[antlr-interest] Return values for fragment lexer rules

Christian chwchw at gmx.de
Sat Jan 14 09:21:56 PST 2012


Ok, I solved it by myself.
Although lexer rules cannot return values, they do can have parameters.
Thus, I create a wrapper object that holds the return value and pass it
to the lexer rule. This kind of parameter passing is used in Pascal
(var) or C++ (out), for example.

Regards,
Christian

Am 14.01.2012 14:23, schrieb Christian:
> I now use an extended version of CommonToken that additionally contains
> a member result. In this way, I can save the result of a Token. However,
> I have to set it somehow. How can I access the current token within
> action code? I would like to have something like the following:
>
> fragment Pp_expression
>   : WHITESPACE? expr=Pp_or_expression WHITESPACE?
>     {$this.result = $expr.result;}
>   ;
>
> Regards,
> Christian
>
> Am 13.01.2012 12:38, schrieb Christian:
>> Hello community,
>>
>> is it right that even fragment lexer rules cannot return any value? The
>> CommonToken does not provide any access to such a value.
>>
>> 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
>



More information about the antlr-interest mailing list