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

Miguel Ping mblp at mega.ist.utl.pt
Sat Feb 24 09:20:10 PST 2007


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