[antlr-interest] Re: Own AST : initializing extra private members
Eric Mahurin
eric_mahurin at yahoo.com
Fri Aug 20 08:11:04 PDT 2004
You should give a more concrete example that shows exactly what you
are doing - especially where xvalue is coming from. At least a
complete rule, if not a mini-grammar (parser).
--- In antlr-interest at yahoogroups.com, Kristoff Tempelaere
<kristoff_tempelaere at y...> wrote:
> Where does xvalue come from? Is it constant or does it rarely change?
> ---- It changes a lot :( I'll make it a bit more concrete : I'm
working on an SQL-grammar, and I need to store some extra information
in the AST. For example, to group all keywords...
>
> Because sometimes I just need to all keywords in the query. I could
do this by searching the AST for every keyword, based on the _ttype.
But thanx to the x-value I can do this in just one traversal, which
saves ofcourse a lot of time... If there are 100 keywords, then this
would sava 99 traversals...
>
> I saw a similar example, with a private member "line". The
difference is, the information for this member is in the token, so
overwriting create(token) {.... line = token->getLine(); ... } did the
trick there. But in my case, the x-value can't be derived based on
the token, it must be passed in the grammar. A bunch of semantic
actions { setx(value);} does the job, but it looks awfull... and
messes up the grammar a bit... so I was wondering if there was a
better way, like "ID<AST=MyAST(xvalue)>" or something... So, somehow
to force the parser call MyFactory.create(token, xvalue) and passing
the xvalue in the grammar...
>
> More general : setting private members of an ASTnode, which can NOT
be derived from the token... is there another way than using semantic
actions?
>
> Thx for your proposal anyway! But it won't work in my case :(
>
> Kristoff
>
>
> Eric Mahurin <eric_mahurin at y...> wrote:
> --- In antlr-interest at yahoogroups.com, Kristoff Tempelaere
> wrote:
>
> > Can this be done in a better way? Instead of using
> myfactory.create(token), i would like the parser calls
> MyFactory.create(token,xvalue)
>
> Where does xvalue come from? Is it constant or does it rarely change?
> If so, you could make your own factory class that has a static xvalue
> variable that you would assign whenever needed and then your new
> create method would use this static value.
>
> Eric
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
> ---------------------------------
> Find local movie times and trailers on Yahoo! Movies.
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