[antlr-interest] Tree Grammar from parser grammar

Shmuel Siegel ssiegel at finjan.com
Tue Sep 25 06:52:59 PDT 2007


I don't know how you want your tree to look but one possibility is:

 

conditionTerm
    :    l+=logicalTerm (Or^ l+=logicalTerm)*

      ->($Or $l*)

; 

 

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of G R
Sent: Tuesday, September 25, 2007 3:26 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Tree Grammar from parser grammar

 

Hi all

I'm actually trying to move from my parser grammar to a tree grammar
using AST rewriting rules as much as I can.
The problem is that I've got 2 rule that I don't know how to deal with
using rewriting rules. 
Here is a part of my grammar :


select    :    Select LeftBrack condition RightBrack (LeftParent raQuery
RightParent | Name)
        -> ^(Select condition raQuery? Name?);
condition
    :    conditionTerm 
        ->^(Condition conditionTerm); 
conditionTerm
    :    logicalTerm (Or^ logicalTerm)*; 
logicalTerm
    :    logicalFactor (And^ logicalFactor)*;
logicalFactor
    :    Not? o1=operand CompareOperator o2=operand
        -> ^(CompareOperator Not? $o1 $o2)
        |LeftParent conditionTerm RightParent
        -> ^(conditionTerm); 
operand    :    Name
        |Numeric;


The rules for conditionTerm and logicalTerm are the ones that I've try
to change using rewriting rule, but i can't any solution...
Could anyone giving me a hand ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070925/207d77bb/attachment-0001.html 


More information about the antlr-interest mailing list