[antlr-interest] Tree Walking

Andrew Deren andrew at adersoftware.com
Tue Jan 13 08:30:51 PST 2004


I've done a similar program to yours (I think). It's a simple language that
has operations and some statements (if, for, while) and user defined
functions. You can find all the source code at
http://www.adersoftware.com/?page=compilers
It has java and c# implementation (sorry not c++).
But I didn't use antlr generated AST. I just never liked those generics
AST's and prefer writing my own that more closely matches the language. Nice
thing about it is that if you write it once, you can easily reuse it in
other programs.
Andrew

-----Original Message-----
From: zgarber [mailto:zgarber at yahoo.com] 
Sent: Tuesday, January 13, 2004 9:08 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Tree Walking

Hi,

I have been using ANTLR for parsing purposes. And now I also need to 
build some expression language that will have simple operators, basic 
types and conditional statements as well as functions.

Since I'm going to use variables in my language, I want to 
use ANTLR in two steps: 
First parsing input and creating AST Tree at load time.
Second walking this tree later in runtime interpreting
the tree with actual variable data multiple times.

My idea was to evaluate conditional expressions and based on that
calculate statements.

It appeares that Actions defined for Tree Walker are executed
anyway (when matching those nodes in a tree). I can deal with
it by evaluating the result of condition passing it as argument to 
statement. However it seems to me that I'll match all nodes in 
subtree even if its actions shouldn't be executed.
Has anybody have an idea what is the performance overhead of matching
tree nodes without executing the actions?

I've also tried to use transformation and Walk Parser generated tree 
twice: first calculating conditions and generating subtree and 
secondly executing actions for that subtree. However buildAST option 
when defined for Walker causes application crash when creating the 
tree. The same thing happens in cpp\transform example.

Has anybody had a similar problem? I'm using antlr-2.7.2 (libcpp) and 
it worked perfectly when parsing things.

I'll appreciate any approach idea for my problem and specific hints 
how to generate second AST.

Regards,
Z.G.



 

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/ 




 

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