Grammar -> Parser question
4 Jun 1998 23:40:01 -0400

          From comp.compilers

Related articles
Grammar -> Parser question (1998-06-04)
Re: Grammar -> Parser question (Torbjorn Drevin) (1998-06-09)
Re: Grammar -> Parser question (Torben Mogensen) (1998-06-09)
Re: Grammar -> Parser question (1998-06-09)
Re: Grammar -> Parser question (Quinn Tyler Jackson) (1998-06-09)
Re: Grammar -> Parser question (Quinn Tyler Jackson) (1998-06-18)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 4 Jun 1998 23:40:01 -0400
Organization: Deja News - The Leader in Internet Discussion
Keywords: parse, question

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.



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.