[antlr-interest] Syntactic predicate for single alternatives

Gokhan Caglar gcaglar at gmail.com
Wed Jan 11 23:42:55 PST 2006


On 1/11/06, Prashant Deva <prashant.deva at gmail.com> wrote:
>
>
> At the program rule I think statement2 is an alternative to statement1 in
> > the following construct:  (statement1)* statement2
> >
> No, statement2 is not an alternative in this case. It just follows
> statement1. Which is why you get the syntactic predicate ignored warning,
> cause there is no need for it.
>

No it is an alternative, if it hadn't been an alternative, there would be no
ambiguity in the first place.  The parser has two alts to choose, one token
is not enough to decide.  When the k is set to 2 the ambiguity goes away.  I
am asking if there is a way to do this with a syntactic predicate and
specially handle this case?


To make statement2 an alternative, write  the rule like this -
>
>
>
>
> program
>     :
>         (DO THIS)=>  (statement1)*
>
>         | (statement2)?
>     ;
>
> Notice the '|' operator which separates 2 alternatives.
>
> --
> Prashant Deva
> Creator, ANTLR Studio
> Founder, Placid Systems, www.placidsystems.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060111/dd8192d9/attachment-0001.html


More information about the antlr-interest mailing list