[antlr-interest] BUG? - Antlr hoists unhoistable predicates

Austin Hastings Austin_Hastings at Yahoo.com
Mon Oct 8 01:12:32 PDT 2007


I was trying to slim down my grammar a bit by combining some rules into 
a single parameterized rule.

decl_specifiers[Boolean permitStorageClass, Boolean permitFunctionSpec]
    : ( accs+=decl_access_qualifier
      | type+=decl_type_spec
      | stcl+=decl_storage_class
      | {$permitFunctionSpec}? func+=decl_function_spec
          )+
    /* blah blah blah */

This would have eliminated several nearly-identical variants.

Unfortunately, Antlr3 hoisted the predicate out of the rule. This 
doesn't work, obviously, because the $permitFunctionSpec is a parameter 
to the rule (which the predicate was hoisted out of...).

In cases like this, Antlr needs to catch the impossibility (detecting 
the use of a rule- or token- field seems a good start) and either not 
hoist, or construct a synthetic predicate with the correct values.

=Austin




More information about the antlr-interest mailing list