[antlr-interest] newbie question

Loring Craymer lgcraymer at yahoo.com
Fri Nov 3 17:02:07 PST 2006


Rajesh--

Trees are very good for converting infix notation to
prefix notation as you are looking to do; there is a
treewalker example of this sort in the ANTLR 2
distribution.

Yes on your second question, although you will want an
XML parser to convert the XML tree into an AST and
then output "child root child" sequences in a tree
walker.

--Loring

--- Rajesh Menon <prm225 at gmail.com> wrote:

> Hi.
> I'd like a suggestion on a rather simple exercise
> I'm trying.
> I have a sample language of the form:
> 
> a = 4;
> b = 3;
> e = a;
> c = b + e;
> e = b WHEN a > 4 OR b < 5 AND c > 6 OR e != 3;
> 
> The user input above would go through 3 stages:
> 1. get transformed into something similar to:
> (num (a 4))
> (num (b 3))
> (expr (e a))
> (expr (c (+ b e)))
> (expr (b (...)))
> 
> 2. This output would be stored as XML on disk (for
> which I'll look at 
> XMLTreeParser).
> 3. This stored XML could be read back in to produce
> the user input.
> 
> 
> The CFG I've written produces the AST:
> ( = a 4 )
> ( = b 3 )
> ( = e a )
> ( = c ( + b e ) )
> ( = e b ( OR ( > a 4 ) ( AND ( < b 5 ) ( OR ( > c 6
> ) ( != e 3 ) ) ) ) )
> 
> which is good.
> 
> My doubt is: to perform the conversion for stage 1,
> is it better to use 
> a TreeParser and walk through each node, or actually
> write the code in 
> for each production in the Parser? I'd personally
> like to do the former, 
> but just want to make sure from someone with more
> experience. (I might 
> not even be making much sense asking this question
> either ...)
> 
> Also, is it possible to reverse the process of
> creating the AST to get 
> back the user input (stage 3 above.)
> 
> Thanks so much for your time and input.
> 
> 
> 



 
____________________________________________________________________________________
We have the perfect Group for you. Check out the handy changes to Yahoo! Groups 
(http://groups.yahoo.com)



More information about the antlr-interest mailing list