// Stms --> Stm { ";" Stm } public Tree[] stms() { Tree[] trees = new Tree[1]; trees[0] = stm(); while (symbol == SEMICOLON) { next(); trees = appendToTrees(trees, stm()); } return trees; } |
// Stm --> ( Assign | Loop | While | Cond | Block ) // fonctionne parce que toutes les options commencent par des // mots cle differents; sinon plus de "look-ahead" serait // necessaire public Tree stm() { if (symbol == ID) return assign(); else if (symbol == LOOP) return loop(); else if (symbol == WHILE) return whil(); else if (symbol == IF) return cond(); else if (symbol == LBRACE) return block(); else if (symbol == ACTION) return action(); else throw new Error("statement expected in line " + pos); } |
// Assign --> id ":=" Exp public Tree assign() { if (symbol == ID) { String id = chars; next(); if (symbol == ASSIGN) { next(); Tree right = exp(); return make.Assign(pos, id, right); } else throw new Error("assignment expected in line " + pos); } else throw new Error("identifier expected in line " + pos); } |