[antlr-interest] Changing the root of a tree in a tree parser

John B. Brodie jbb at acm.org
Mon Nov 28 10:40:55 PST 2011


On 11/28/2011 05:32 AM, franck102 wrote:
> I am trying to do something that seems pretty simple, which is adjusting the
> root token of a tree in my tree parser.
> Basically my parser always sees a=b as a comparison and generates ^( EQUAL a
> b) as an AST, and in the tree parser I want to adjust that to ^( ASSIGN a b)
> if I am at the statement level:
> 
> statement
>     : ifStatement
>     | ...
>     | expressionStatement { if ($expressionStatement.tree.getType() ==
> EQUALS) { <set tree type to ASSIGN> }
> 
> If I try to introduce an assignmentStatement (just in the tree parser) I get
> mutually recursive rule, so that isn't an option...
> 
> Any suggestion?
> 
> 
> --
> View this message in context: http://antlr.1301665.n2.nabble.com/Changing-the-root-of-a-tree-in-a-tree-parser-tp7038239p7038239.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

pass a flag as a parameter to expressionStatement that tells it whether
or not to rewrite itself as an assignment.



More information about the antlr-interest mailing list