Greetings!

Martijn's suggestions are close but need a couple of tweaks, see
below...

On Tue, 2009-08-25 at 18:50 +0200, Martijn Reuvers wrote:
> Hi Safiye,
> 
> As Sam said, recursion might be what you need.
> 
> Something like this gives your tree I believe:
> 
> grammar test;
> 
> options {
>       output=AST;
>       
> }
> 
> x
>       : A B y    -> ^(B A y)
>       ;

this will REQUIRE at least 1 instance of the C A B clause. whereas the
original rule had it being 0 or more. to fix make the y be y?, e.g:

x : A B y? -> ^(B A y?) ;

> y :   C A B y* -> ^(B A C y*)
>       ;

this is a recursive application of the y rule inside a loop! i suspect
it will work but seems very dangerous to me. i would suggest using the ?
operator rather than the * operator, 0 or 1 vs 0 or many; e.g:

y : C A B y? -> ^(B A C y?) ;

> 
> A :   'A';
> 
> B :   'B';
> 
> C :   'C';
> 
> 
> Martijn
> 
> On Tue, Aug 25, 2009 at 4:57 PM, Safiye Celik<[email protected]> wrote:
> > Hi
> > I wanna ask one more question about parse tree construction..
> > I have such a rule:
> >
> > x: A B (C A B)* and I have to create such a tree for it:
> >
> >
> >                                            B
> >                                      /      |     \
> >                                 A        C        B
> >                                                   /  |  \
> >                                                A  C    B
> >                                                         /  |  \
> >                                                       A..C. B......and
> > continues like that. (The leftmost a B is in the rule, the closest it is to
> > the root of the tree.This is true also for other tokens)
> >
> > How can I create such a tree for that rule? the "*" confuses everything :(
> >
> >
> > --
> > -safiye

Hope this helps...
   -jbb



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

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

Reply via email to