[antlr-interest] Parse-tree Reference to father rule

Jim Idle jimi at temporal-wave.com
Tue Aug 24 11:27:46 PDT 2010


This tends to indicate that you have copied the language definition verbatim
from some written form that was written with  LALR parser in mind (if it had
any in mind). You have to restructure this in to an LL tree and then you
will find that ambiguities go away and that the AST build comes naturally
out of the parsing structure.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Nieves.Salor.Moral at esa.int
> Sent: Tuesday, August 24, 2010 2:38 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Parse-tree Reference to father rule
> 
> Hi guys!!
> 
> Sorry to bother you again!!
> 
> I have already managed to get the syntax-highlighting and error
> management done :D ( I am still fighting with the code-folding in
netbeans),
> and now I am building the tree grammar before creating the string
> templates.
> 
> And I have come across a question, that maybe is stupid, but I don't find
any
> reference in the books or internet.
> 
> My problem is, that I have rules like these:
> 
> relational_expression
>   : term comparative_expression?
>   ;
> comparative_expression
>   : RELATIONAL_OPERATOR term
>   | 'between' a=term POSITIVE_LOG_OPERATOR b=term -> ^('between' $a
> $b)
>   | 'within'constant MOD_SIGN? OF_LINK term -> ^('within' constant
> MOD_SIGN? term) //(engineering_units| '%')?
>   | IN_TAG OPEN_PARENTHESIS term (COMMA term)+ CLOSE_PARENTHESIS
> -> ^( IN_TAG term+)
>   ;
> 
> where RELATIONAL_OPERATOR can be '!='|'<='|'>='.
> 
> so when I create the tree grammar, I would like to have a tree similar so
> ^(RELATIONAL_OPERATOR term1 term2), for example.
> 
> This opens the following possibilities:
> 1)I access the child tree in relational_expression rule and later one I
changed
> it depending on the tree that I get (so I would have to add as many checks
as
> possibilities has the child rule) 2)I access the father first element tree
in
> comparative_expression and, later in the father I assign the father tree
as
> the child tree, but If I have another rule that also calls this child
rule, I cannot
> do this.
> 
> I think neither option is really good, any inputs?
> 
> Thanks in advance
> 
> Nieves
> 
> 
> 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