[antlr-interest] Copying return value of a rule

Christian chwchw at gmx.de
Wed Feb 1 06:00:33 PST 2012


> The first problem: Attributes and modifiers are optional, so I get an
> EmptyStackException if one of the following action is not declared in
> the corresponding upper rule. Can I somehow check whether the attrs and
> members are defined?
I thought the EmptyStackException would have come from the fact that my
attributes and modifiers rules are optional. However the stack is never
popped while being in a subrule (I checked the implementation). Hence,
the stack must never be pushed with an element. And well, I used the scope

		$typed_member_declaration::type

not in a subrule, but outside of the scope. That's why the stack was
empty: nothing was pushed to it.

So, only problem 2 remains.

Am 31.01.2012 21:52, schrieb Christian:
> Hi @all,
>
> as one might know from common programming languages, a field declaration
> looks like the following (here C#)
>
>     [attribute] public String name, text;
>
> My corresponding rule looks as follows:
>
>     variable_declarators
>     : variable_declarator ( COMMA  variable_declarator )*
>       -> ^(VARIABLE_DECLARATOR {$class_member_declaration::attrs}
> {$class_member_declaration::members}
>           {$typed_member_declaration::type} variable_declarator)+
>     ;
>
> The first problem: Attributes and modifiers are optional, so I get an
> EmptyStackException if one of the following action is not declared in
> the corresponding upper rule. Can I somehow check whether the attrs and
> members are defined?
> The second problem: I do not know a good alternative. Passing e.g. type
> through 3 or more rule levels is not maintainable. Furthermore, copying
> the return value of the type rule for each field (here: name and text)
> does not work. Any solution for that?
>
> Regards,
> Christian
>
> 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