[antlr-interest] Stuck with parser & tree grammar

Harald Mueller harald_m_mueller at gmx.de
Sat Dec 8 03:08:45 PST 2007


Hi -
Just a guess (without ever having done that myself): Maybe there has to be one (last) condition-less rewrite; so if you drop the {BinaryOp==Divide}?, it might work ... sorry if I'm compeltely off here.
Regards
Harald
-------- Original-Nachricht --------
> Datum: Fri, 7 Dec 2007 13:04:25 +0100
> Von: "G R" <relationalalgebra at gmail.com>
> An: "antlr-interest Interest" <antlr-interest at antlr.org>
> Betreff: [antlr-interest] Stuck with parser & tree grammar

> Hi all!
> I'm still trying to translate relational algebra into SQL.
> I used to some problems with my grammar, so I decide to change it into a
> LL(1) grammar.
> So, a relational algebra query can be describe like this :
> 
> raExpr
> :    raQuery^
> |    RelationName^;
> 
> raQuery
> :    project^
> |    select^
> |    rename^
> |    binaryExpr^;
> 
> binaryExpr
> :    r1=relation (BinaryOp r2=relation
> |     LeftBrack a1=AttributeName RightBrack Join r2=relation LeftBrack
> a2=AttributeName RightBrack)
>     ->{$BinaryOp!=null}?^(BinaryOp $r1 $r2)
>     ->^(Join ^(Left $r1 $a1) ^(Right $r2 $a2));
> 
> relation
> :    LeftParent raQuery RightParent
>     ->^(raQuery)
> |    RelationName
>     ->^(RelationName);
> 
> As you can see, I'm trying to make possible input like :
> relationName1 UNION relationName2
> Or
> relationName1[AttributeName1] JOIN relationName2[AttributeName2]
> 
> Using this grammar, this is ok : my AST looks good. Using previous inputs,
> I
> got the following AST :
> (UNION relationName1 relationName2)
> Or
> (Join (Left relationName1, AttributeName1) (Right relationName2,
> AttributeName2))
> 
> The problem is in the tree grammar. I don't know how to deal with the rule
> binaryExpr.
> I've try this :
> binaryExpr
> :    ^(BinaryOp r1=relation r2=relation)
>         -> {BinaryOp==Union}? Union(left={$r1.st}, right={$r2.st})
>         -> {BinaryOp==Intersect}? Intersect(left={$r1.st}, right={$r2.st})
>         -> {BinaryOp==Difference}? Difference(left={$r1.st},
> right={$r2.st})
>         -> {BinaryOp==Divide}? Divide(left={$r1.st}, right={$r2.st})
> |    ^(Join ^(Left r1=relation a1=AttributeName) ^(Right r2=relation
> a2=AttributeName))
>         -> join(leftRel={$lr.st}, leftAtt={$la.text},
> leftAlias={$lr.alias},
>                         rightRel={$rr.st}, rightAtt={$ra.text},
> rightAlias={$rr.alias});
> 
> But, ANTLR is expecting a REWRITE instead of the optional operator ( | )
> just after the Divide.
> 
> So, my question is : how can I generate my walker using the previous
> parser
> grammar, or What should I do for this to work ?
> 
> Thanks for any help.
> 
> G.R.

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail


More information about the antlr-interest mailing list