Micheal Bedward asked:
> In my parser grammar:
>
> expr_list : (expr (',' expr)* )? -> ^(EXPR_LIST expr*) ;
>
> In my tree grammar:
>
> expr_list returns [List<Double> values] : ^(EXPR_LIST expr*)
> { $values = new ArrayList<Double>();
> int n = $EXPR_LIST.getChildCount();
> for (int i = 0; i < n; i++) {
> $values.add($expr.value);
> }
> }
> ;
>
> Yuck !! I can see I'm doing ANTLR's work here insstead of letting it
> work for me - but I haven't been able to see how to collect the values
> of 0 or more expressions. I understand that I can't use list label
> syntax here because I don't have output=AST for the tree grammar. I
> can see by looking at the generated walker code that there is a loop
> iterating through the expr values, after which my ugly code does the
> same thing !
have you tried placing your action inside antlr's loop?
something like (untested):
expr_list returns [ List<Double> values ] :
{ $values = new ArrayList<Double>(); }
^(EXPR_LIST ( e=expr {$values.add($e.value);} )*)
;
hope this helps
---
-jbb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address