Ok, to answer my own question, this works:
statement returns [ Statement *s ]
: labeled_statement
| [...whatever...]
;
selection_statement returns [If *retval]
: ^(IF expression s1=statement s2=statement)
{
$retval = new If(NULL, $s1.s, $s2.s);
}
| [...]
;
...which matches what's on page 134 of the ANTLR book. So, never mind.
--
Gary R. Van Sickle
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Gary
> R. Van Sickle
> Sent: Saturday, February 28, 2009 3:20 AM
> To: 'antlr-interest'
> Subject: [antlr-interest] More label breakage?
>
> In a tree grammar this time. This should work, right?:
>
> selection_statement returns [If *retval]
> : ^(IF expression s1=statement s2=statement)
> { $retval = new If(NULL, $s1, $s2); }
> | ^(IF { cout << "IF" << endl; }
> expression statement)
> | ^(SWITCH expression statement)
> ;
>
> (C target, "ANTLR Parser Generator Version 3.1.2-2008-10-21")
>
> It results in the following errors from ANTLR:
>
> error(117): ss9_tree_parser.g3t:0:0: missing attribute access
> on rule scope:
> s1
> error(117): ss9_tree_parser.g3t:0:0: missing attribute access
> on rule scope:
> s2
>
> Broken? If I comment out the action, it gets through ANTLR
> and compiles, but of course that's of little use. Apparently
> ANTLR is looking for something along the lines of "new
> If(NULL, $something::s1, $something::s2)", but I have no idea
> what $something is supposed to be, nor can I find any
> documentation to that effect.
>
> --
> Gary R. Van Sickle
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email
> -address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---