[antlr-interest] Syntactic and semantic predicates don't work in ANTLRWork's "interpreter"?

Johannes Luber jaluber at gmx.de
Sat Nov 17 09:18:27 PST 2007


Steve Bennett wrote:
> Hi all,
>   (First post!) I'm enjoying playing with ANTLRWorks but seem to have
> just hit a gotcha. I spent hours trying to work out how to use syntactic
> and semantic predicates, and finally it seems that the problem is just
> that the Interpreter doesn't support them. Is that true? Perhaps it
> could just say so rather than make the user tear their hair out...
> 
> Here's my grammar, just in case I'm missing something:
> ---
> grammar magicword;
> 
> f : t ('|' option)*;
> option : (magicword '|') => magicword
> | t;
> 
> t : LETTER;
> 
> magicword
> : 'magicword';
> 
> LETTER : ('a'..'z' | 'A'..'Z')+;
> ---
> 
> I honestly thought I just hadn't understand syntactic predicates for
> ages, then on a whim tried the debugger...and it actually worked.

The interpreter ignores predicates. That may or may not change, but
should be documented somewhere.

> Anyway, hi, everyone! Looking forward to learning ANTLR a lot better and
> making sure I get my head around all these constructs. Apart from the
> book and the wiki, are there any other good resources that would help
> answer questions like "I need to parse X, what's the best way to do it?"

The posted grammars may be useful, too, if they happen to include the
required case. Otherwise just ask - usually people will know tips or
links or books about the subject at hand.

Johannes



More information about the antlr-interest mailing list