[antlr-interest] Tree Rewrite doubt | errors on parser generation

Miguel Ping mblp at mega.ist.utl.pt
Sat Feb 24 13:33:48 PST 2007


Err, I'm having problems filling the return tree with the tree built
by antlr. If I use the $sql_statement syntax, the corresponding
subtree of the node SQL_STATEMENT comes empty, but if I reference the
right side of the production, it comes ok. What is the proper way of
referencing the LEFT side of the production so antlr can do the tree
building and I can put the result on an imaginary token?

In more complex examples, I have no simple way of solving this without
antlr building the tree for me, it would require me to rewrite all the
rule just to fill the tree.

Thanks in advance,
Miguel Ping

On 2/24/07, Miguel Ping <mblp at mega.ist.utl.pt> wrote:
> I figure out how to port those rules to antl3, it is quite simple:
>
> sql_statement: sql_command (SEMI)? -> ^(SQL_STATEMENT $sql_statement);
>
> You use the $rulename syntax. Hope it helped other than myself :)
>
> On 2/22/07, Miguel Ping <mblp at mega.ist.utl.pt> wrote:
> > Hi all!
> >
> > I am currently trying to port PL/SQL 7 antlr v2 grammar downloadable
> > from antlr site to antlr v3 b6. The grammar has some tree rewrite
> > rules that are useful to group statements under a tree like:
> >
> > sql_statement: sql_command (SEMI)?
> >         { #sql_statement = #([SQL_STATEMENT, "sql_statement"],
> > #sql_statement); }
> >
> > If I understant the tree rewrite rules correctly, this grammar rule
> > states that the (sub) tree that will be assigned to sql_statement is
> > to be assigned to a child under the SQL_STATEMENT imaginary token with
> > the name "sql_statement". For me to port those definitions to antlr
> > v3, should I do it this way:
> >
> > sql_statement: sql_command (SEMI)? -> ^(SQL_STATEMENT sql_statement);
> >
> > Because if I do it that way, antlr tool tells me that the
> > 'sql_statement' does not exist on the left side of  the '->' symbol:
> > error(136): reference to rewrite element sqlStatement without
> > reference on left of ->
> > How should I work this out?
> >
> >
> > There are 2 other errors happening in the generated parser code:
> >
> > 1. The symbol LA27_1 in the following method does not exist:
> >
> >  public int specialStateTransition(int s) throws NoViableAltException {
> >                 int _s = s;
> >             switch ( s ) {
> >                     case 0 :
> >                         input.rewind();
> >                         s = -1;
> >                         if ( (LA27_1==OPEN_PAREN||LA27_1==DOT) ) {s =
> > 14;} //error here
> >                         else if ( (synpred7()) ) {s = 9;}
> >                          (...)
> >
> > Since this method overrides the one in the DFA, I guess that this must
> > be a problem with the generator, but I can be wrong...
> >
> > 2. In the rule
> >
> > variable : ( ( columnSpec ( OPEN_PAREN PLUS CLOSE_PAREN ) )=>
> > columnSpec ( OPEN_PAREN PLUS CLOSE_PAREN ) | columnSpec );
> >
> > The parser code for the return tree I guess is in this method, which
> > has alot of if's and cases:
> >
> >     public variable_return variable() throws RecognitionException {
> >      (...)
> >      int LA29_5 = input.LA(7);
> >      (...)
> > The problem is that the variable 'int LA29_5' is being duplicated in
> > alot of places on this method. Is this because of my rule, or can it
> > be a antlr bug?
> >
> > Thanks In advance!
> >
>


More information about the antlr-interest mailing list