Tree grammar attribute $text not working

13 views
Skip to first unread message

liuku...@gmail.com

unread,
Feb 27, 2013, 6:29:09 AM2/27/13
to antlr-di...@googlegroups.com

anltr 3.4
parser grammar:
additiveExpression 
    :   multiplicativeExpression
        (   
            (   '+'^
            |   '-'^
            )
            multiplicativeExpression
        )* 
    ;

tree grammar:
expression
@init 
{
    $start.setOriginalText($text);//try to record source code
}
    :   ^('+' e1=expression e2=expression)
        {
            //do something
        }
    |   ^('-' e1=expression e2=expression)
        {
            //do something
        }
    ;

Example:

1+1+1+1;

AST:
   +             $text=1+1+1+1    correct
  + 1            $text=+          wrong
 + 1             $text=+          wrong
1 1 

I only get correct text for root tree,but not any for subtree.

 What should I do? 

Thank you very much!

Reply all
Reply to author
Forward
0 new messages