[antlr-interest] Semantic predicates

Andreas Meyer andreas.meyer at smartshift.de
Fri Oct 16 14:35:48 PDT 2009


Andreas Meyer schrieb:
> Robert Wentworth schrieb:
>   
>> There appears to be something fundamental that I am not "getting"  
>> [...] 
>>     
>
> I think the generated code is wrong. [...]
>   
btw, when changing the gated semantic predicates:
> > cat     : {input.LT(1).getText().equals("cat")}?=> WORD ;
> >
> > dog     : {input.LT(1).getText().equals("dog")}?=> WORD ;
>   
into plain semantic predicates
> > cat     : {input.LT(1).getText().equals("cat")}? WORD ;
> >
> > dog     : {input.LT(1).getText().equals("dog")}? WORD ;
>   
the generated code looks good and expr can accept cat, cat when dog and 
dog. Now, as the other poster already mentioned, gated semantic 
predicates are there to distinguish between alternatives (that are not 
syntactically ambiguous). Maybe that's where ANTLR (or the user?!) get's 
confused, because cat only has one alternative (which get's effectively 
disabled if the predicate fails), but the context in which it is used 
has more alternatives, which effectively boil down to the same gated 
predicates.

Best,
Andreas Meyer


More information about the antlr-interest mailing list