[antlr-interest] Change type of current AST

Terence Parr parrt at cs.usfca.edu
Fri Jun 6 13:23:37 PDT 2008


Try $tree = or $additiveExpression.tree =  I believe.No doubt you are  
getting an error from antlr below?
Ter
On Jun 6, 2008, at 1:17 PM, Dimitrios Kolovos wrote:

> Hi Ter,
>
> Unfortunately, that doesn't seem to work either.
>
> additiveExpression
>   :    multiplicativeExpression (('+'|'-')^ multiplicativeExpression  
> {$additiveExpression.setType(Operator);})*
>   ;
>
> in the parser grammar produces
>
> if ( state.backtracking==0 ) {
>   $additiveExpression.setType(Operator);
> }
>
> in the parser class.
>
> (I'm using 3.1b in case this makes a difference.)
>
> Cheers,
> Dimitrios
>
> Terence Parr wrote:
>> Use $ not #
>> On Jun 6, 2008, at 6:27 AM, Dimitrios Kolovos wrote:
>>
>>> Hi,
>>>
>>> In ANTLR2 I was able to change the type of the current AST like  
>>> this:
>>>
>>> additiveExpression
>>>  :    multiplicativeExpression ((PLUS^|MINUS^)  
>>> multiplicativeExpression {#additiveExpression.setType(OPERATOR);})*
>>>  ;
>>>
>>> but I haven't been able to find how to do the same in v3. Any hints?
>>>
>>> Cheers,
>>> Dimitrios
>>
>>



More information about the antlr-interest mailing list