Safiye Celik wrote:
Hi,
I have a grammar such below:

a: b A
b: C^ B

What I want is to set "A" token in rule "a" as the last branch of rule "b" 's parse tree without changing the grammar, rules, tokens etc. (because the rules and tokens are used somewhere else, the grammar is not such simple of course)

That's, I want a tree like: ^(C B A). But I only know how to set "A" as the root of  rule "a" with this grammar(that is done by a: b A^), and it causes a tree like ^(A C B) which I do not want.

Is there a way to construct the tree I want with above grammar??
Take a step back here - you probably don't need to do this. The point of an AST isn't to make it readable to you per se (though it helps ;-), but to make sure it is unambiguous to the tree parser. If this is your exact grammar then the tree rule is just:

a: b A;

b : ^(C B);

And if you need to process A in some actions in rule b, then just pass it to rule B (but you might be better initiating the action in rule a and having the b tree available.


If you cannot change the rules then there isn't much you can do ;-) However perhaps you could inherit the originating grammar in an import within a new grammar, then just override rule a:

import existing.g

a : C^ B A ;

You could also use actions to build the AST yourself, but then that is a modification to the rules of course. You could also add action code in the tree parser to traverse the tree of b. Finally you could have an interim tree grammar that rewrites the tree to your purposes.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com
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