[antlr-interest] Re: is an id required to access the root text?
kozchris
csnyder at alumni.ncsu.edu
Wed Sep 22 10:58:21 PDT 2004
--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...> wrote:
> On Sep 22, 2004, at 9:36 AM, kozchris wrote:
>
> >
> > Say I have some grammer like this (assume strings for vars):
> >
> > #(pl:PLUS left=expr right=expr) {out= left + pl->getText() + right;}
> > |#(mi:MINUS left=expr right=expr) {out= left + mi->getText() + right;}
> >
> > Is there a way to access the root text so that I can do something like
> > this without having to assign an id to each root:
> >
> > (#(PLUS left=expr right=expr)
> > |#(MINUS left=expr right=expr)) {out= left + CURRENT_ROOT->getText() +
> > right;}
> >
> > Thanks for the help,
> > Chris
> >
> >
>
> ## is a shorthand for the root node of a rule. Another shorthand is
> #ruleName. That should do it.
>
> Monty
I tried the ##->getText() earlier and when I build a c++ output I get
a couple of errors.
error C2065: 'printRoot_AST' : undeclared identifier
error C2065: 'currentAST' : undeclared identifier
error C2228: left of '.root' must have class/struct/union type
error C2227: left of '->getText' must point to class/struct/union
Those errors lead me to believe that using ## was inappropriate for
this problem. What needs to change to be able to use ## for future
reference.
The #[rulename]->getText() works like a champ though.
Thank you,
Chris
Thanks
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list