[antlr-interest] Re: Own AST : initializing extra private members

Kristoff Tempelaere kristoff_tempelaere at yahoo.com.au
Fri Aug 20 01:56:31 PDT 2004


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 yahoo.com> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20040820/e35b01c5/attachment.html


More information about the antlr-interest mailing list