|Grammar -> Parser question email@example.com (1998-06-04)|
|Re: Grammar -> Parser question firstname.lastname@example.org (Torbjorn Drevin) (1998-06-09)|
|Re: Grammar -> Parser question email@example.com (Torben Mogensen) (1998-06-09)|
|Re: Grammar -> Parser question firstname.lastname@example.org (1998-06-09)|
|Re: Grammar -> Parser question email@example.com (Quinn Tyler Jackson) (1998-06-09)|
|Re: Grammar -> Parser question firstname.lastname@example.org (Quinn Tyler Jackson) (1998-06-18)|
|Date:||4 Jun 1998 23:40:01 -0400|
|Organization:||Deja News - The Leader in Internet Discussion|
Suppose I have the following Grammar:
condition -> expr PLUS expr |
LPAREN condition RPAREN
expr -> ID |
LPAREN expr RPAREN
I want to hand-code a top down recursive descent parser for this grammar
using ideas from the Dragon Book (nonterminals become functions, terminals
become calls to match()). I can't use lex or yacc.
However, the LPAREN symbol is causing a problem: When I see it, I don't
know if I'm dealing with a nested condition or a nested expression.
How does one typically deal with this situation if one has to hand-code
the parser? It looks like I need some sort of lookahead and/or backtracking
mechanism so I can figure out which case I am dealing with.
sample source code demonstrating concepts appreciated. The actual grammar
is somewhat more complicated, but this is the critical area I need to address.
Return to the
Search the comp.compilers archives again.