[antlr-interest] Strings as Synthetic Attributes in ANTLR 3.1.2 and ANTLRWorks 1.2.3.
Foolish Ewe
foolishewe at hotmail.com
Tue Mar 10 06:51:02 PDT 2009
Thank you Gavin! This is indeed exactly the problem. After I ran into this I caved in and bought the Definitive ANTLR Reference manual, which does have a treatment of this also.
Thanks again:
Bill M.
> Date: Tue, 10 Mar 2009 21:00:21 +1300
> To: foolishewe at hotmail.com; antlr-interest at antlr.org
> From: antlr at mirality.co.nz
> Subject: Re: [antlr-interest] Strings as Synthetic Attributes in ANTLR 3.1.2 and ANTLRWorks 1.2.3.
>
> At 09:45 10/03/2009, Foolish Ewe wrote:
> >When I run it I get the output:
> >op=<+> (Hardwired!), lhs=<2>, rhs=<3>, result_attr=<+23>
> >e.text = <2 + 3>
> >
> >Note that e.text shows the infix order from the inputs, so I'm
> >guessing the synthetic attribute isn't being successfully
> >transmitted to stat from expr, have I goofed or is this a bug in
> >ANTLR?
> [...]
> >// Here we should see the prefix version of the synthetic
> >attribute of expr
> >stat: e=expr NEWLINE {System.out.println("e.text = <" + $e.text
> >+ ">");};
> >
> >// Creates a synthetic string attribute (bottom up).
> >// given an infix order sum operation the attribute string
> >reflects a prefix order expression
> >expr returns [String result_attr]: lhs=NUM '+' rhs=NUM
> > { $result_attr = '+' + $lhs.text + $rhs.text;
> > System.out.println("op=<+> (Hardwired!), lhs=<" +
> > $lhs.text +
> > ">, rhs=<" + $rhs.text + ">, result_attr=<" +
> > $result_attr + ">");
> > }
> > ;
>
> You are assigning your custom text to a return value called
> "result_attr". This will, naturally enough, appear in the parent
> rule as $e.result_attr, not as $e.text.
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
_________________________________________________________________
Windows Live™: Life without walls.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1a_explore_032009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090310/c0e81058/attachment.html
More information about the antlr-interest
mailing list