[antlr-interest] More label breakage?

Gary R. Van Sickle g.r.vansickle at att.net
Sat Feb 28 01:52:20 PST 2009


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: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] 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



More information about the antlr-interest mailing list