[antlr-interest] PEG-style "and" predicates

Wincent Colaiuta win at wincent.com
Mon Jul 2 17:04:30 PDT 2007


El 3/7/2007, a las 1:37, David Piepgrass escribió:

>> My understanding of predicates (notes at <http://wincent.com/
>> knowledge-base/ANTLR_predicates>) leads me to believe that this is
>> failing because in ANTLR, syntactic predicates are used to order a
>> rule's alternatives. They are not like gated semantic predicates
>> which can be used to turn an entire rule off depending on context. It
>
> Hmm, I realize I am very puzzled about something. If these predicates
> aren't used for prediction, then what are they good for? A means to
> reorder alternatives is not really needed--if the user wants to
> reorder alternatives, he can simply do so.

Nope, I don't think so. They are needed because, with a few  
exceptions, the order in which you specify alternatives *doesn't*  
actually have any impact on their precedence. One of the key uses of  
syntactic predicates (*the* key use?) is to resolve ambiguities by  
specifying which alternative should succeed. If you want the physical  
order in which alternatives appear in the grammar to be used to  
resolve ambiguities then you must set the "backtrack" to "true",  
either for that rule or for the whole grammar.

Once again, a more expert ANLTR user might be able to explain this a  
bit better than me...

Cheers,
Wincent



More information about the antlr-interest mailing list