Simply using a tree grammar won't alter the input tree. If you want
customizable actions, use something like this:

 

tokenSpec

        :       TOKEN_REF {TrackToken($TOKEN_REF);}

        ;

 

Then in your helper file (which you can create since the tree grammar
class is declared partial in code), create a virtual stub method that
"handles" things:

 

protected virtual void TrackToken(CommonTree tokenRef)

{

}

 

Then you can derive classes from the tree parser and override methods as
needed to provide the required functionality. In the C# port of the
ANTLR tool, this exact method is used to implement the functionality for
the AssignTokenTypesWalker tree parser (the lines above are actually
taken from it).

 

Sam

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Rob Dougan
Sent: Thursday, July 30, 2009 1:48 PM
To: ANTLR Interest
Subject: [antlr-interest] Approach to Multiple Passes using Tree
Grammars without Filters (C#)?

 

Antlr 3.1.3 does not have tree filters.
 
Pass 1: lex/parse produces AST,
 
I would like to do multi-pass processing on AST produced in first pass.
 
Pass 2: Tree grammar A (AST): variable defs, build symbol table etc
Pass 3: Tree grammar B (AST): static type checking etc.
Pass 4: Tree grammar C (AST): execute
 
If i do not have tree filters, do I have copy the tree grammar three
times and modify the actions to accomplish the task?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to