[antlr-interest] Grammer question
Sriram Durbha
cintyram at yahoo.com
Thu Nov 7 09:08:23 PST 2002
i had asked a similar question earlier .. and learnt that the last
terminal in a rule that has a caret on it becomes teh root;
i dont know how to achieve the tree structure you have shown in one
rule; but it can be acheived in more than one rule;
also your picture shows that alias has two children, in antlr trees i
think only one child can be there, the other one becomes a siblilng;
so your tree might be like
A
|
C3 --->[dummy]
|
|
C1-->C2
you can have C1
|
V
C2 also;
by writing two rules you can have the grammar like this
rule2 : rule1 alias^ C3 ;
rule1 : ( LPAREN! )? C1^ PLUS! C2 (RPAREN! )? ;
this will make alias as root and C3 and and rule1 as its siblings; [ or
is it children?]
but rule 1 is a tree in itself in which C1 is root and C2 its sibling[
child ?]
hope this helps..
/e
cheers
ram
--- "Ney, Richard" <richard.ney at aspect.com> wrote:
> I have a question on formatting a grammer rule to construct the AST
> tree a
> certain way. Say we have a grammer that allows these constructs
>
> Construct 1) column1 + column2 alias1, column3
> Construct 2) (column1 + column2) alias1, column3
>
> Column1, column2 and alias as basic identifiers and the desired tree
> looks
> like
>
> alias1----
> | |
> | +----------
> | |
> | column1
> | column2
> column3
>
> I figure I can do something with the ^ to make various item root.
> Also the
> parens are option and I don't want them in the tree constuct. Is it
> possible
> to combine ! and ?
>
> -Richard
>
>
----------------------------------------------------------------------------
> ------------------------
> Richard Ney Aspect Communications
> Principal Software Engineer
> http://www.aspect.com <http://www.aspect.com>
> Main: 408.325.2200
> mailto:richard.ney at aspect.com <mailto:richard.ney at aspect.com>
> SJ Office: 408.325.2464
> Home Office: 916.797.9602
>
----------------------------------------------------------------------------
> ------------------------
>
> The Three Laws of Infernal Dynamics:
> 1. An object in motion will always be headed in the wrong direction.
> 2. An object at rest will always be in the wrong place.
> 3. The energy required to change either of these states will always
> be more
> than you wish to expend, but never so much as to make the task appear
> prospectively impossible.
>
>
>
__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list