[antlr-interest] Stuck with parser & tree grammar[Scanned]

Roidl Moritz moro at flw.mb.uni-dortmund.de
Fri Dec 7 05:56:44 PST 2007


Hi,

 

this is a snippet from ANTLRv3Tree.g that describes the structure of
rewrites:

 

rewrite

      :     (^('->' SEMPRED rewrite_alternative))* ^('->'
rewrite_alternative)

      |

      ;

 

You always need a default rewrite rule which takes all the cases that
are not covered by the conditional rewrites. So, you could try something
like 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})

        -> UndefinedBinaryOp(left={$r1.st}, right={$r2.st})

 

Since you know that only the conditional cases can occur the default
rule will never be evaluated. I hope this works, I haven't tested it.

 

Moritz

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071207/8e8368fa/attachment.html 


More information about the antlr-interest mailing list