[antlr-interest] [C target] bug in hidden syntactic predicates

Maximilien Colange macolange at gmail.com
Tue Aug 30 09:51:56 PDT 2011


Hi,

I've been using antlr for a few months in order to parse logical 
formulae, with the C target.

I have a rule in a parser such as
subformula:
       atom
     | term (x='and' term)+  -> ^($x term+)
     | term ('or' term)+    -> ^('or' term+)
     | term
     ;

As far as i have understood, antlr generates a syntactic predicate in 
order to distinguish between the 'and' and 'or' alternatives.
In the case as presented above, the code of such a predicate is 
incorrect, as it begins with :
     pANTLR3_COMMON_TOKEN    ;
            = NULL ;
It looks like the name x is omitted in this declaration, though it 
appears later in the code.

I don't actually need to name the token 'and', and deleting x fixes the 
problem.
Expliciting the syntactic predicate seems to fix it as well.
I also noted that the bug does not appear without the +.

Hope this may help improving this great tool:-)

-- 
Max


More information about the antlr-interest mailing list