[antlr-interest] newbie question

Rajesh Menon prm225 at gmail.com
Fri Nov 3 16:26:00 PST 2006


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.




More information about the antlr-interest mailing list