[antlr-interest] Re: SQL grammar tree construction problem

Gustav Boström i93gusbo at hotmail.com
Fri Nov 7 09:12:36 PST 2003


Hi!

Thanks for the help!

I think I'm trying the same thing as you, but also without luck.
I try to do:
sql_stmt : 
	  sql_data_stmt  { #sql_stmt = #([SQL_STMT,"sql_stmt"], 
#sql_stmt); }

, but I never find this node in the tree. The code seems to be 
generated, but has no effect. Could it be that no root node is ever 
created?

I also tried this:
sql_script : 
	 (sql_stmt)? { #sql_script = #
([Token.MIN_USER_TYPE,"sql_script"], #sql_script); } ( SEMICOLON 
(sql_stmt)? )*

"sql_script" is the first rule and now a node is in fact created, but 
it has no children. I thought that all the subsequent nodes would be 
added as children automatically.

Qoute from doc:
"Setting the return tree is very useful in combination with normal 
tree construction because you can have ANTLR do all the work of 
building a tree and then add an imaginary root node such as: 
  
decl : ( TYPE ID )+
       { #decl = #([DECL,"decl"], #decl); }
     ;
ANTLR allows you to assign to #rule anywhere within an alternative of 
the rule. ANTLR ensures that references of and assignments to #rule 
within an action force the parser's internal AST construction 
variables into a stable state. After you assign to #rule, the state 
of the parser's automatic AST construction variables will be set as 
if ANTLR had generated the tree rooted at #rule. For example, any 
children nodes added after the action will be added to the children 
of #rule." 
 
This is exactly what I want, but I must be doing something wrong.



/Gustav



--- In antlr-interest at yahoogroups.com, "Joshua Davis" 
<joshua.davis at k...> wrote:
> ANTLR newbie question:
> 
> I've been having a similar problem I think.  I made a very simple 
> grammar based on L. V.'s grammar.   It seems to be always producing 
> only one root node, with no children.  What steps should I take to 
> debug this?  I have tried adding actions to the rules, and it looks 
> like the rules are being triggered correctly, but no AST is 
produced.
> 
> --- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:
> > Gustav--
> > 
> > You cannot make a rule a root--that's what ANTLR is complaining 
> about. 
> >  Rules may represent subtrees, so only nodes with token ids (TEXT 
> or 
> > STRING, for example) can be followed with ^.
> > 
> > --Loring
> > 
> > 
> > --- In antlr-interest at yahoogroups.com, Gustav Boström 
> <i93gusbo at h...> 
> > wrote:
> > > Hello!
> > > 
> > > I'm trying to use Lubos Vnuk's (Thanks for doing all the work!) 
> SQL-
> > > grammar in order to do some 
> > > processing on SQL-statments. I would for example like to find 
out 
> > > which columns are affected by a DML-statement and which 
> parameters 
> > > correspond to which columns.
> > > 
> > > I'm doing this is in Java , so I've changed the grammar 
slightly.
> > > I've removed the C++ actions or replaced them with Java 
versions.
> > > 
> > > My thought was to add AST-construction and then navigate the 
tree 
> to 
> > > find out the stuff I need. This is where I run into problems.
> > > I tried to annotate the rules with ^ to construct my tree, but 
it 
> > > keeps giving me "unexpected token:^" when I try to dothis for 
> > example:
> > > sql_stmt : 
> > > 	  sql_data_stmt^ 
> > > ;
> > > 
> > > I've set the options to buildAST=true;
> > > I'm using version 2.7.2.
> > > 
> > > Any ideas on what can be wrong?
> > > 
> > > Cheers,
> > > 
> > > Gustav Boström


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list