Handling while loop construct from AST
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, September 15, 2002 11:13 PM

Hello everyone, After generating an AST from Antlr how can I selectively avoid the evaluation of sub elements in a Tree during pattern matching in Antlr Tree Parser Section. For example in the following code: #("while" e:expression s:statements) { while( expr(#e) != 0 ) stmts(#s); } both e:expression and s:statemnts are evaluated by Antlr (rule procedures expr and stmts are called by Antlr as well) for matching this tree pattern but can't the matching of expression be done on just by comparing the root elements of expression and statements elements. Alternately Is there an easier   More>>

Hello everyone,



After generating an AST from Antlr how can I selectively avoid the evaluation of sub elements in a Tree during
pattern matching in Antlr Tree Parser Section.


For example in the following code:



#("while" e:expression s:statements) {

while( expr(#e) != 0 )

stmts(#s);

}




both e:expression and s:statemnts are evaluated by Antlr
(rule procedures expr and stmts are called by Antlr as well)
for matching this tree pattern but can't the matching of
expression be done on just by comparing the root elements
of expression and statements elements. Alternately Is there
an easier way to execute this while loop construct easily
with out generating intermediate assembly like code (that can be interpreted later) or hand coding the tree walker.



Thanks

Ranjith

   <<Less

Re: Handling while loop construct from AST

Posted By:   Terence_Parr  
Posted On:   Tuesday, September 24, 2002 11:10 AM

Use ""dot"" wildcard operator to match a whole subtree. It prevents antlr from doing anything but check to see that one is there.



Terence
About | Sitemap | Contact