[antlr-interest] Problem with AST

Marcin Rzeźnicki marcin-rzeznicki at wp.pl
Tue Oct 19 14:54:11 PDT 2004


Hello
I am trying to write parser for logical expressions with some
extensions. I started with standard logical expressions grammar which I
will not present here for it is obvious. Next I eliminated left
recursion and performed left factorization in order to squirt it into
LL(1) class, which resulted in following grammar:
logexp          :   andexp logexp_part;
logexp_part     :   OR andexp logexp_part       |
                 ;
andexp          :   notexp andexp_part;
andexp_part     :   AND notexp andexp_part      |
                 ;
notexp          :   NOT relexp                  |
                     relexp;
relexp          :   primitive relexp_factor;
relexp_factor   :   REL_OP relexp               |
                 ;
primitive       :   VAR_ID                      |
                     PROB LPAREN NUMBER RPAREN   |
                     LPAREN logexp RPAREN        |
                     GET LPAREN NUMBER VAR_ID (COMMA VAR_ID)* RPAREN;

(VAR_ID are variable identifiers, PROB and GET are some special
functions which need not be delved into here, LPAREn and RPAREN are left
and right parentheses, REL_OP is < or <= and so on, others are standard
logical operators)

So far so good. Nex I would like to build AST expressing parsed logical
expression, and here lies my problem. 'Primitive' production is fairly
easy to tranform into AST, yet 'complex' productions are little obscure
to me. Take relexp and relexp_factor: what I would like to achieve is to
make AST that: if relexp_factor is not epsilon-production(null-string
production) then subtree resulting from that expression part should be:
#(REL_OP primitive "part of relexp_factor tree without operator node"),
otherwise I would like it to be just #primitive. Considering for example
'andexp' production: if andexp_aprt is not epsilon-production then
resutling tree should be #(AND notexp "andexp_part without AND node"),
otherwise just #notexp. And so on. How this coulbe be achieved? Thank
you in advance
--
Greetings
Marcin Rzeźnicki







 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list