[antlr-interest] Fwd: Re: Rewrite only if rule returns non-empty result

Christian chwchw at gmx.de
Fri Oct 28 00:55:03 PDT 2011


 Ok, I found my error. I did some sort of the following:

myrule: a=attributes? -> ^(ATTR $a);

The rewritten rule always expects something for a, I think. However, in
the original rule, a is optional. After appending a question mark to a
in the rewrite rule, all works fine.

So, is $a generally replaced by the rule without operators?

Am 27.10.2011 17:00, schrieb Trevor John Thompson:
> You are getting no response because your request makes no sense. You say
>>> I want to rewrite it only if unary_expr returns a non-empty result.
> However, unary_expr can only return a non-empty result, assuming cast_expression, pre_decrement_expression, etc. represent what their names suggest.
>
> The distinction you are drawing between unary_expr and unary_expression appears unmotivated and bizarre. You might start by giving examples of the input you are trying to match, and the corresponding trees you are trying to build.
>
> On 2011 Oct 27, at 05:12, Christian wrote:
>
>> Perhaps, you need more information about unary_expr:
>>
>> unary_expr
>>  : cast_expression
>>  | '+' unary_expression -> ^(POSITIVE unary_expression)
>>  | '-' unary_expression -> ^(NEGATIVE unary_expression)
>>  | '!' unary_expression
>>  | '~' unary_expression
>>  | PRE_INC unary_expression
>>  | pre_decrement_expression
>>  | primary_or_array_creation_expression '++'? '--'?
>>  | pointer_indirection_expression
>>  | addressof_expression
>>  ;
>>
>> Am 26.10.2011 12:29, schrieb Christian:
>>> Hi community,
>>>
>>> I have the following rule:
>>>
>>> unary_expression
>>>  : unary_expr -> ^(UNARY_EXPRESSION unary_expr)
>>>  ;
>>>
>>> I want to rewrite it only if unary_expr returns a non-empty result.
>>> Actually, I want to solve the
>>> org.antlr.runtime.tree.RewriteEmptyStreamException: rule unary_expr. I
>>> think, it is quite easy, but I am too new to ANTLR.
>>>
>>> Regards,
>>> Christian
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> --
> Trevor John Thompson    (425) 246-4023
> tijet at me.com
> Quidquid Latine scriptum sit, altum videtur.
>
>




More information about the antlr-interest mailing list