Do you have any idea about my problem below??

---------- Forwarded message ----------
From: Safiye Celik <[email protected]>
Date: 2009/8/14
Subject: Re: [antlr-interest] parse tree construction
To: Jim Idle <[email protected]>


So I think I cannot do anything about that problem :(
It would be good if there was some syntax like "^token" which makes a token
the root, but that makes it a branch of other tree :) My aim is not to make
the tree more readable. If A is the root, I can access the tokens in the
order A, C and B. But I wanna access them in the order C, B, A. I do not
wanna go over A to access C. That is the problem.

I wanna ask one more question to you about parse tree construction..
I have such a rule:

x: A B (C D A B)* and I have to create such a tree for it:

                                                  B
                                            /      |     \
                                       A        C        B
                                                  |       /  |  \
                                                 D    A  C   B
                                                             |
                                                            D
............and continues like that.

How can I create such a tree for that rule? the "*" confuses everything :(

2009/8/13 Jim Idle <[email protected]>

>  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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>


-- 
-safiye



-- 
-safiye

--~--~---------~--~----~------------~-------~--~----~
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