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

Nieves.Salor.Moral at esa.int Nieves.Salor.Moral at esa.int
Tue Aug 24 02:37:43 PDT 2010


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



More information about the antlr-interest mailing list