[antlr-interest] Tree pattern won't rewrite AST C#

Sam Harwell sharwell at pixelminegames.com
Wed Jul 13 06:43:13 PDT 2011


In your partial class file that accompanies your grammar, you should add the
following function override:

partial class MyTreeParser {
    public override IAstRuleReturnScope Bottomup() { return bottomup(); }
}

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of DJB MASTER
Sent: Tuesday, July 12, 2011 10:38 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Tree pattern won't rewrite AST C#

Hey, I'm trying to apply simple tree patterns that can remove redundancy in
multiplication expressions, such as x*0 -> 0. However I can't get it to
rewrite my AST I feed in.

I'm using again >>>
http://media.pragprog.com/titles/tpdsl/code/IR/Vec/VecMathAST.g 

and I'm using this as my simplifier >>
http://media.pragprog.com/titles/tpdsl/code/walking/patterns/Simplify.g.

I'm getting a correct AST because it's identical to what Terrance gets in
the LP book.

I'm using this code to call my simplifier...

CommonTree AST = (CommonTree)parser.statlist().Tree;        

CommonTreeNodeStream nodes = new CommonTreeNodeStream(AST);
nodes.TokenStream = tokens;

Simplifier simplifier = new Simplifier(nodes); CommonTree AST =
(CommonTree)simplifier.Downup(AST, true);

But it seems to do nothing.

--
View this message in context:
http://antlr.1301665.n2.nabble.com/Tree-pattern-won-t-rewrite-AST-C-tp657761
4p6577614.html
Sent from the ANTLR mailing list archive at Nabble.com.

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



More information about the antlr-interest mailing list