Posted By:
Adam_McClure
Posted On:
Thursday, August 29, 2002 04:01 PM
I seem to have a hard time getting some rules to bottom out. For example, I have a rule defined as an identifier which is checked at the end of an expression. The generated code parses the token as part of the expression, but fails and claims it doesn't recognize the next token. I'm using nested expressions to represent a functional language. expr: comp ('>' comp)* ; comp: unary ('+' unary)* ; unary: ID ; Now feed in the following expression: a + b > c The generated code will recognize a+b but throw an exception when trying to recognize '>'. I've tried playing around with the look
More>>
I seem to have a hard time getting some rules to bottom out. For example, I have a rule defined as an identifier which is checked at the end of an expression. The generated code parses the token as part of the expression, but fails and claims it doesn't recognize the next token. I'm using nested expressions to represent a functional language.
expr: comp ('>' comp)* ;
comp: unary ('+' unary)* ;
unary: ID ;
Now feed in the following expression:
a + b > c
The generated code will recognize
a+b
but throw an exception when trying to recognize '>'.
I've tried playing around with the lookahead depth thinking that will change things but it only seems to shift the errors around. I've done some debugging and narrowed the problem to the tokenSet.member(LA(#)) tests following successful evaluation of the ID rule.
I think the question then comes back to, how are the DFA's generated and is there a way to clarify my error? What impact does the lookahead depth have on the DFA?
<<Less