[antlr-interest] a crazy problem cost me almost two days ---how can i get the return value from antlr?
Jared Bunting
jared.bunting at peachjean.com
Mon Nov 24 07:10:52 PST 2008
In addition to compiling, after renaming "input" your grammar seems to
work just fine. Using output=AST, t had a value for every input that I
through at it.
-Jared
Ivar Refsdal wrote:
> Hi,
>
> I noticed one thing:
>
> You are using the name "input" as the return value.
> It looks like this variable is reserved.
> The .g to .java compiler should complain about this in my opinion.
>
> Here the .g compiles to .java, but the .java does not compile.
> If you rename the return variable name, the .java compiles also.
>
>
> If you look at the code:
>
> public final String base1() throws RecognitionException {
> String input = null;
> ...
> switch ( input.LA(1) ) {
> ...
> So that's probably it...
>
> This compiles fine:
> base1 returns[String input2]
> :
> b64=Base64Block{$input2=$b64.getText();}|ident=Id{$input2=$ident.getText();}|n
> = Num {$input2 = $n.getText();}
> ;
> id1 returns[String input2]
> :ident=Id{$input2=$ident.getText();}
> |b64=Base64Block{$input2=$b64.getText();}|n = Num {$input2 = $n.getText();}
> ;
>
>
> Good luck,
> Ivar
>
>
>
> Terence Parr wrote:
>
>> On Nov 23, 2008, at 7:47 PM, Su Zhang wrote:
>>
>>
>>
>>> Hi all,
>>>
>>> I wrote a returns [String s] in my rules in order to get a return
>>> value, but when I call the function generated by the exact rule in
>>> the main function, there is not any return value, and the type of
>>> return value is not a String, and the value includes a tree
>>> structure,etc, but I define it as a string in the antlrworks, does
>>> anybody know what's the problem in my project? how can i get the
>>> return String I defined? I am almost crazy about this annoying
>>> problem,
>>> here is a part of my grammar:
>>>
>>>
>>>
>> hi. have you looked at the generated code? It should have a t in the
>> object returned from that rule.
>>
>> Ter
>>
>>
>> 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