[antlr-interest] Deciphering the TreeWalker error message ...

Gary Miller gary at sumwise.com
Wed Jul 20 22:53:18 PDT 2011


Hey Vasan,

Without seeing the reset of the tree walker grammar and the toStringTree of
the AST I'm really just guessing.

The rule looks a bit odd to me.
All my tree walker rules look more like

compoundExpression
:
     ^(SOMETOKEN  conversion_clause)
    | sclarSubExpression
;

I guess you can have rules as the first element of a tree, its just not
something that turns up in my tree grammars.

Regards
Gary

On Thu, Jul 21, 2011 at 3:29 PM, srinivasan karthikeyan pitchai <
srinivasan.karthikeyan.pitchai at oracle.com> wrote:

> Hi Folks,
> I forgot to mention.  The compoundExpression rule has options{backtrack
> = true;}  set that is it reads like
>
> compoundExpression
> options {backtrack = true;}
> :
>      ^(sclarSubExpression  conversion_clause)
>     | sclarSubExpression
> ;
>
> Thanks,
> Vasan
>
>
>
> On 7/21/2011 10:56 AM, srinivasan karthikeyan pitchai wrote:
> > Jim, Gray, Loring,
> > Thanks for pitching in to give me some direction to focus on.
> >
> > ANTLR Gurus,
> >
> > I've solved the issue.  Still I am unable to reason out my fix.
> >
> > I am providing the offending grammar snippet below and would appreciate
> > your rationale to get an insight into the problem and how the fix works!!
> >
> > The below rule fails with the "
> >
> > no viable alt; token=[@-1,0:0='DOWN'" error message
> >
> > compoundExpression:
> >       ^(sclarSubExpression  conversion_clause)
> >      | sclarSubExpression
> > ;
> >
> > However when I change the rule like the following, i.e make the
> > conversion_clause optional  and then remove the second alternative every
> > thing works fine!!  In my mind both the rules are semantically identical.
> >
> > compoundExpression:
> >       ^(sclarSubExpression  conversion_clause?)
> > ;
> >
> > Thanks a ton.
> >
> > -Vasan
> >
> > On 7/21/2011 4:16 AM, Jim Idle wrote:
> >> Or use the dot description producing methods and create a nice graphic
> >> with graphviz. Much easier to see that way.
> >>
> >> Jim
> >>
> >>> -----Original Message-----
> >>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >>> bounces at antlr.org] On Behalf Of Gary Miller
> >>> Sent: Wednesday, July 20, 2011 3:44 PM
> >>> To: antlr-interest at antlr.org
> >>> Subject: Re: [antlr-interest] Deciphering the TreeWalker error message
> >>> ...
> >>>
> >>> I often find it usefully to print out the AST (toStringTree in Java)
> >>> and walk through the tree grammar manually.
> >>>
> >>> Regards
> >>> Gary
> >>>
> >>> On Thu, Jul 21, 2011 at 3:15 AM, Loring Craymer<lgcraymer at yahoo.com>
> >>> wrote:
> >>>
> >>>> "UP" and "DOWN" tokens (start/end of child list for tree) do not have
> >>>> location information attached so no line/column error reporting.
> >>>> Mostly the error says that you started a subtree that your grammar
> >>>> does not match, probably an LPAREN or RPAREN rooted subtree from your
> >>>> report of cases where you do or do not get the error.
> >>>>
> >>>> --Loring
> >>>>
> >>>>
> >>>>
> >>>>> ________________________________
> >>>>> From: srinivasan karthikeyan pitchai<
> >>>> srinivasan.karthikeyan.pitchai at oracle.com>
> >>>>> To: antlr-interest at antlr.org
> >>>>> Cc: Terence Parr<parrt at cs.usfca.edu>
> >>>>> Sent: Wednesday, July 20, 2011 9:46 AM
> >>>>> Subject: [antlr-interest] Deciphering  the TreeWalker error message
> >>> ...
> >>>>> Hi Folks,
> >>>>> What does the ANTLR walker error message like the following mean?
> >>>>>
> >>>>> no viable alt; token=[@-1,0:0='DOWN'
> >>>>>
> >>>>>
> >>>>> Would appreciate any general guidance/suggestions to zero in on the
> >>>>> errors of this nature.
> >>>>>
> >>>>> Thanks,
> >>>>> Vasan
> >>>>>
> >>>>>
> >>>>> Input sql:
> >>>>> -----------
> >>>>>
> >>>>> select (1) from table1
> >>>>> where 2 between 3 and 4;
> >>>>>
> >>>>>
> >>>>> Error Message:
> >>>>> --------------------
> >>>>>
> >>>>> TDWalker1.g: node from after line 2:8 [start1, startStatement, dml,
> >>>>> query_term, query_expression, query, query_unit, where_clause,
> >>>>> condition_list, condition_subexpression, condition] Walker1: no
> >>>>> viable alt; token=[@-1,0:0='DOWN',<2>,0:-1] (decision=127 state 0)
> >>>>> decision=<<590:1: condition options {backtrack=true; } : ( ^(
> >>>>> comparison_operator ( condition_quantifier )? c1= condition c2=
> >>>>> condition ) | ^( BETWEEN expression ^( and_or_operator c1= condition
> >>>>> c2= condition ) ) | ^( condition_operator expression c1= condition
> >>> ^(
> >>>>> ESCAPE escape_character ) ) | ^( condition_operator expression c1=
> >>>>> condition )
> >>>>> | ^( condition_operator expression_list c1= condition ) | ^( NOT c1=
> >>>>> condition ) | ^( EXISTS expression ) | ^( IS_NOT_NULL expression ) |
> >>>>> ^( IS_NULL expression ) | ^( IS_NOT expression UNTIL_CHANGED ) | ^(
> >>>>> IS expression UNTIL_CHANGED ) | ^( IS_NOT expression UNTIL_CLOSED )
> >>> |
> >>>>> ^( IS expression UNTIL_CLOSED ) | expression | condition_list );>>
> >>>> context=......
> >>>>> However the following SQL, that just doesn't have the parenthesis
> >>>>> around 1,  works fine!!!
> >>>>>
> >>>>> select (1) from table1
> >>>>> where 2 between 3 and 4;
> >>>>>
> >>>>>
> >>>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >>>>> Unsubscribe:
> >>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-
> >>> address
> >>>>>
> >>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >>>> Unsubscribe:
> >>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-
> >>> address
> >>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> >>> email-address
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list