Ordering AST Nodes ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lingot_norbert
Posted On:   Wednesday, February 20, 2002 05:05 AM

Hi

I would like to generate AST Nodes in a prepefined order.

For example in the following grammar:

rule1 : rule2 | rule3;

rule : "start" ( rule1 )* "end";

I would like rule3 nodes to appear before any rule2 node into the generated tree. Tree walking will then compute all rule3 nodes before computing the first rule2 node.

Is it possible ? If it is, how can I do that?

Thank you.

Re: Ordering AST Nodes ?

Posted By:   Monty_Zukowski  
Posted On:   Friday, February 22, 2002 07:19 AM

You could build the tree yourself:

rule1!
{Vector rule2s=newVector;
Vector rule3s=newVector;}
:
( (r2:rule2 {rule2s.append(#r2);}
|(r3:rule3 {rule3s.append(#r3);}
) { /*now build the tree here */ }
;

This example is pretty generic though, are you trying to achieve precedence or just make sure initializations happen before use, or what? You have more flexibility if you build the tree in a pretty normal way first and then use different tree parsers to do different things.
About | Sitemap | Contact