[antlr-interest] Quick rewrite question

Leah Perlmutter lrperlmu at colby.edu
Mon Apr 23 10:38:42 PDT 2012


I have the following rule in a C grammar:

parameter_declaration
    : declaration_specifiers (declarator|abstract_declarator)*
    ;

I want the rule to get its own token, so I tried the following rewrite:

parameter_declaration
    : declaration_specifiers (declarator|abstract_declarator)*
        -> ^( ParamDecToken<ParamDec> declaration_specifiers (declarator |
abstract_declarator)* )
    ;

but that doesn't compile (antlr syntax error). The attempt below compiles
but is semantically wrong because it doesn't account for when the
declarators and abstract_declarators are interspersed.

parameter_declaration
    : declaration_specifiers (declarator|abstract_declarator)*
        -> ^( ParamDecToken<ParamDec> declaration_specifiers declarator*
abstract_declarator*)  // semantically wrong
    ;

Is there a way to add my token and preserve proper semantics?


Thanks!
-Leah


More information about the antlr-interest mailing list