[antlr-interest] Problems with syntactic predicates(?)
Christian Gudrian
gn at fluidon.dyndns.info
Sat Jan 26 12:23:36 PST 2008
Hello!
I want to write a grammar that matches equations like:
a=1
2=b
f_a(3)=4
5=f_b(6,7)
f_c(8,9)
This is my approach so far:
// -------------------------- 8< --------------------------
grammar test;
INT : ( '0'..'9' )+ ;
IDENT : ( 'a'..'z' )+ ;
equation
: ( expression '=' ) => expression '=' expression
| function_call
;
expression
: ( IDENT '(' ) => function_call
| INT
| IDENT
;
function_call
: IDENT '(' args? ')' ;
args : expression ( ',' expression )* ;
// ------------------------- >8 --------------------------
The ANTLRWorks debugger shows me, that the equation rule matches input
of the form "a=1". Everything involving function calls doesn't match,
however; I get a NoViableAltException(0!=[null]) error in these
cases. I suspect it's my use of syntactic predicates which causes
this behaviour, isn't it? What's wrong?
Christian
More information about the antlr-interest
mailing list