[antlr-interest] Help to make an iteration (somehing go wrong
with previous)
Bryan Ewbank
ewbank at gmail.com
Thu Oct 27 02:26:58 PDT 2005
Let me try again with more explanation...
[01] eval:
[02] ... ... ... | while_stmt | ... ... ...
[03] ;
[04]
[05] while_stmt
[06] :
[07] #( WHILE e:expr s:stmt )
[08] {
[09] while (eval(#e) == true)
[10] {
[11] eval(#s);
[12] }
[13] }
[14] ;
Line [07] matches the assumed tree for a while node. When this matches, the
action (lines [08-13]) is executed. The while-statement at [09] is executed in
the native language, which means that the "eval(#s)" at [11] will be executed
each time that the condition in the while at [09] evaluates to "true"
Note that [07] could probably be rewritten as follows, because it's likely
wasteful to traverse those trees to recognize them:
[07] #( WHILE e:. s:. )
So, yes, stmt is another tree. ANTLR allows you to walk (and capture) the expr
and stmt trees once; after that, you must walk (and evaluate) each tree
multiple times.
Hope this is a bit more clear in what I was saying,
- Bryan
On 10/26/05, gil_loureiro at iol.pt <gil_loureiro at iol.pt> wrote:
> But the problem is stmt is another tree ... how can I walk this tree
> (with eval(#s)) to run the contained set of statements multiple times?
More information about the antlr-interest
mailing list