[antlr-interest] Fwd: "Exotic" grammar rule

Kevin Cummings cummings at kjchome.homeip.net
Tue Apr 24 11:02:19 PDT 2012


Yes, the code in the {}? Is a gated semantic predicate.  If the expression inside evaluates to true, then the alternative is attempted to be matched.  If the expression is false, then the alternative is never tried.

So, for the code you are looking at, if the 2nd look ahead character is *not* a STAR, then it is OK to match an optional STAR character as the next input character.  This guarantees that if you *do* match a STAR, there is only one to match (and not two of them).

--
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232
(http://www.linuxcounter.net/)


On Apr 24, 2012, at 4:53, Christian Lerch <christian.lerch at km-works.eu> wrote:

> 
> On some other website I found the following interesting ANTRL grammar rule:
> 
> onestar
>     :    ( { input.LA(2) != STAR }?  ( STAR )?)
>     |
>     ;
> 
> Can anybody explain its precise meaning to me?
> 
> Cheers,
> Chris
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list