[antlr-interest] A parser nondeterminism error I just can't get my
head around...
James Matthews
james.x.matthews at imperial.ac.uk
Sun Feb 26 17:09:15 PST 2006
Hi,
I apologies in advance if I'm missing something fundamental here, but
I've been puzzling over this for a while and I'm stuck, so I thought I'd
ask you guys.
To save you reading through all my grammar, I have broken the problem
down to the simplest form I can find.
Can anyone please explain why:
a : IDENT LPAREN (b)? RPAREN
| LPAREN a RPAREN;
b: a
| IDENT;
works fine with k=2, but
a : IDENT LPAREN (b)? RPAREN
| LPAREN a RPAREN
| INT;
b: a
| IDENT;
gives me the error on k=2:
model.g:118:5: warning:nondeterminism between alts 1 and 2 of block upon
model.g:118:5: k==1:IDENT
model.g:118:5: k==2:RPAREN
(and will not work for any k)
I do not understand why adding in the INT option makes any difference?
Many thanks if anyone can help,
James
P.S. If anyone feels it is easier for me to try and explain what I'm
trying to achieve, here you go:
In the modeling language I am creating, I have an expression which as
well as having the standard int, string, variable and boolean atoms, I
would also like function calls which I would like to look like:
"functionName(arg1, arg2 ... argN)".
The functions are passed a list of arguments, which can be of two types,
another expression or an IDENT (representing a resource in my model).
There is no sole IDENT in the expression and every function call must
start IDENT LPAREN, so I was hoping k=2 should uniquely distinguish the
two.
With the grammar below, I get the same error as above. However, I have
discovered that if I remove all the "STRING_LITERAL | INT | VARIABLE |
"FALSE" | "TRUE"" base options from my expression, it works (but is not
much use!)
expression : or_expr ( IMPLIES ^ or_expr )*;
or_expr : and_expr ( OR ^ and_expr )* ;
and_expr : not_expr ( AND ^ not_expr ) * ;
not_expr : NOT ^ not_expr | expr ( ( NOT_EQUALS ^ | LTE ^ |
LT ^ |
GTE ^ | GT ^ | EQUALS ^) expr )? ;
expr : MINUS ^ term
| term (( PLUS ^ | MINUS ^ ) term )* ;
term : factor ( (TIMES ^ | DIV ^) factor)* ;
factor : STRING_LITERAL | INT | VARIABLE |"FALSE" | "TRUE" | function |
LPAREN ! expression RPAREN !;
function: IDENT^ LPAREN! (arguements)? RPAREN!;
arguements: (expression | IDENT) (COMMA! (expression | IDENT))* ;
More information about the antlr-interest
mailing list