[antlr-interest] a crazy problem cost me almost two days ---how can i get the return value from antlr?

Su Zhang westlifezs at gmail.com
Mon Nov 24 05:59:57 PST 2008


thanks,i see that, yet there is not any value in this String, i checked my
grammar part and did not find any errors or problem? would you take a look
at my grammar and see whether there is a problem in the project?
the grammar is here:

num    returns [String t]
        :n = Num  {$t =
$n.getText();}|b64=Base64Block{$t=$b64.getText();}|ident=Id{$t=$ident.getText();}
        ;
base1   returns[String input]
        :
b64=Base64Block{$input=$b64.getText();}|ident=Id{$input=$ident.getText();}|n
= Num  {$input = $n.getText();}
        ;
id1   returns[String input]
      :ident=Id{$input=$ident.getText();/*System.out.println($input);*/}
|b64=Base64Block{$input=$b64.getText();}|n = Num  {$input = $n.getText();}
      ;

Num   :     ( '0'..'9' ) * ;
Id   :     ( 'a'..'z' | 'A'..'Z' | '_' ) ( 'a'..'z' | 'A'..'Z' | '_' |'-'|
'0'..'9' ) *;
Base64Block  :('a'..'z'| 'A'..'Z'|'0'..'9'|'/'|'+'|'=')*;
//Base64Block      : ('a'..'z' | 'A'..'Z' | 'O'..'9' | '/' | '+' | '=')*;
ChallengeBlock   : ( 'a'..'z' | 'A'..'Z' | 'O'..'9'| ':')* ;
//fragment
WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;



thanks

2008/11/24 Jared Bunting <jared.bunting at peachjean.com>

> Look at the definition of that return class.  It should have a field "t"
> that is a String.  That is your return value.
>
>   On Sun, Nov 23, 2008 at 11:49 PM, Su Zhang <westlifezs at gmail.com> wrote:
>
>>  yes, i have, it has a prog_return class in the code, but it isnot the
>> String type,do you know how can I take the value as a string out of the
>> code?
>>
>> 2008/11/23 Terence Parr <parrt at cs.usfca.edu>
>>
>>>
>>> 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
>>>
>>>
>>
>>
>> --
>> Su Zhang
>> PHD Candidate
>>  Computer Information and Science
>> Kansas State University
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>>
>


-- 
Su Zhang
PHD Candidate
Computer Information and Science
Kansas State University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081124/b1c84092/attachment.html 


More information about the antlr-interest mailing list