[antlr-interest] Strange behavior with backtracking

G R relationalalgebra at gmail.com
Thu Dec 6 00:09:46 PST 2007


Hi!
While I was debugging my application, I found some strange error. Here is a
part of my grammar :

grammar RAGrammar;
options    {output=AST;
    backtrack=true;
    memoize=true;}

raExpr    :    raQuery     ->^(raQuery)
    |    RelationName    ->^(RelationName);

raQuery    :    project^
    |    select^
    |    rename^
    |    product^
    |    join^
    |    union^
    |    intersect^
    |    difference^
    |    divide^;
        catch [RecognitionException re] {
            throw re;
        }

relation:    LeftParent raQuery RightParent    ->^(raQuery)
    |    RelationName            ->^(RelationName);

union
:    r1=relation Union r2=relation
        ->^(Union $r1 $r2);
intersect
:    r1=relation Intersect r2=relation
        ->^(Intersect $r1 $r2);
difference
:    r1=relation Difference r2=relation
        ->^(Difference $r1 $r2);
divide
:    r1=relation Divide r2=relation
        ->^(Divide $r1 $r2);

So there are a few parser rule that ask for a relation then, a relational
algebra operator (Union, Intersect, Difference, and the last one in my
grammar : Divide).
When I try parsing the follow input, everything  works fine :

(PROJECT [nomClub] Clubcheap)
 UNION (PROJECT [nomClub] Clubexpensive)

But when I make an error in this input like this :

(PROJECT [nomClub] Clubcheap)
 UNION (PROJECT [nomClub. Clubexpensive)

I expect that ANTLR raise an error like "mismatched input '.' expecting ']'
in project.
But the error I get is : "mismatched input 'UNION' expecting DIVIDE in
divide"
So I think the error comes from the backtracking (correct me if I'm wrong,
I'm here to learn), where ANTLR believe he is in the last rule (no syntactic
predicate for the last rule) ans then raise a wrong error message.

How can i correct this ?
I would really appreciate any help for this.

Thanks.

G. R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071206/1104c854/attachment.html 


More information about the antlr-interest mailing list