[antlr-interest] disambiguating semantic predicates

Tom Smith yotommy at gmail.com
Fri Sep 19 14:25:14 PDT 2008


(Apologies for the earlier incomplete message --- an errant Enter key).

I am trying to use disambiguating semantic predicates, as I have a
case where "a property of a token must dictate how the parser
interprets it" (to quote The Definitive ANTLR Reference, p. 287).  A
snippet of the grammar is shown below.

However when I execute the parser, I get FailedPredicateExceptions.
This doesn't make sense to me, because for proper disambiguation,
some predicates must evaluate to false.

Can someone offer a clue?

Thanks,
Tom Smith.

event
   :
   ^(EVENT T1 varName (h=hostcode)?)
   |
   ^(EVENT T2 TIMEOUT (h=hostcode)?)
   |
   ^(EVENT T3 varName (h=hostcode)?)
   ;

T1
   :
   { isTypeT1(((Tree) input.LT(1)).getText()) }?
   varName
   ;

T2
   :
   { isTypeT2(((Tree) input.LT(1)).getText()) }?
   varName
   ;

T3
   :
   { isTypeT3(((Tree) input.LT(1)).getText()) }?
   varName
   ;

varName
   :
   ID
   ;


More information about the antlr-interest mailing list