[antlr-interest] parse tree construction

Martijn Reuvers martijn.reuvers at gmail.com
Tue Aug 25 09:50:51 PDT 2009


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)
	;

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<safisce at gmail.com> 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
>
>
> 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