[antlr-interest] Tree grammars & optional AST nodes
Terence Parr
parrt at cs.usfca.edu
Sat Oct 21 09:35:53 PDT 2006
On Oct 20, 2006, at 11:24 PM, Nicolas Rouquette wrote:
> Terence Parr <parrt at ...> writes:
>
>> On Oct 19, 2006, at 5:09 PM, Nicolas Rouquette wrote:
>>
>>> <at> init { boolean flag=false; }
>>> : e1=conditionalExpression (op=assignmentOperator e2=expression
>>> {flag=true;})?
>>> -> {flag} ? ^($op $e1 $e2)
>>> -> $e1
>>> ;
>>
>> or use {$op!=null}? without the flag mumbojumbo.
>
> Thanks for this suggestion; however, there's one small glitch...
> If I write:
>
> expression
> : e1=conditionalExpression (op=assignmentOperator e2=expression)?
> -> {$op!=null} ? ^($op $e1 $e2)
> -> $e1
> ;
>
> 3.0b4 produces this kind of code:
>
> if ($op!=null) {
> // the code for ^($op $e1 $e2)
> } else {
> // the code for $e1
> }
>
> ... and a telltale error message:
>
> missing attribute access on rule scope: op
Oh. It wants $op.tree or something. Which which is the problem? ^
($op i guess. Try {$op.tree} for now.
Ter
More information about the antlr-interest
mailing list