[antlr-interest] Approach to Multiple Passes using Tree Grammars without Filters (C#)?

Sam Harwell sharwell at pixelminegames.com
Thu Jul 30 13:37:57 PDT 2009


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: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] 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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090730/68eb301b/attachment.html 


More information about the antlr-interest mailing list