[antlr-interest] Quick rewrite question

Jim Idle jimi at temporal-wave.com
Mon Apr 23 10:48:26 PDT 2012


x: subrule -> ^(ParamDecToken subrule) ;

subrule : declaration_specifiers (declarator|abstract_declarator)* ;


Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Leah Perlmutter
> Sent: Monday, April 23, 2012 10:39 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Quick rewrite question
>
> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list