Hi Webstorm-
You're definitely going to be my hero today :)
(2) I rearranged the rules for expr as I did the the original post FROM how you have it above. This is necessary because of the
expr op expr
rule causing an infinite recursion error. How to work around that is unclear since i get an error with expr op expr but nondeterminism when arranging the rules as I did in my original post.
What you've suggested does in fact remove all nondeterminism if I remove the error temporarily by removing the initial expr call in that rule mentioned above, and I do understand the logic behind what you've done, so thanks very much for that!!
-D4
Main Topics
Browse All Topics





by: WebstormPosted on 2006-02-18 at 08:54:47ID: 15989122
Hi D4Ly,
(2) Generally, you don't have to put * in a grammar, but use the recusivity of rules.
(1) When many non-terminals can start with the same pattern/token, you may have to split / regroup the expressions like this :
type1: ("int" | "bool" | "void" )(ARRAY)?
;
type: type1
| ID(ARRAY)?
;
expr: uop expr
| INTEGER
| LPAREN expr RPAREN
| lvalue
| "new" alloc
| expr op expr
;
alloc: ID ( LPAREN (actuals)? RPAREN
| (ARRAY)? LBRACKET expr DOTS expr RBRACKET
)
| type1 LBRACKET expr DOTS expr RBRACKET
;