[antlr-interest] Problem with recursive rules

Mark mark at antelope.nildram.co.uk
Sun Dec 16 14:03:53 PST 2007


Hi,

I've just discovered ANTLR and it looks like a fantastic tool, but I'd be
grateful if anyone here could offer me any help with the following..

If I try to parse an IF statement in a language with a rule like this:

statement =
'{' statement '}'
|  ....
|  'if' expression 'then' statement 'else' statement

Then I get a conflict warning.  Looking at it in Antlrworks shows that the
problem is: if it finds a statement like "if (a) then if (b) then
doSomething; else doSomethingElse", it doesn't know which 'if' the 'else'
applies to.  It should always apply to the inner one (ie, the "if b" in this
example), but how do I tell ANTLR that?

Thanks,
Mark.


________________________________________________
Message sent using UebiMiau 2.7.2



More information about the antlr-interest mailing list