Example from book (3.11)
S -> if E then S else S
S -> begin S L
S -> print E
L -> end
L -> ; S L
E -> num = num
A simple parser class could deal with this by writing methods for S,
L, and E, along with a method that calls for the next
token from the lexer and analyzes it:
class parse
{
Token t;
Lexer lexer;
void eat(Token target) { if t.equals(target) t = lexer.nextToken();
else parseError();}
public parse(Lexer l) { lexer = l; t = lexer.nextToken();}
public void S() { switch(t)
case IF: eat(IF); E(); eat(THEN); S();
eat(ELSE); S(); break;
etc...
}
public void L()
public void E()
}