On Mon, 2008-11-24 at 05:59 -0800, Su Zhang wrote:
> 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();}


This has already been pointed out once, but don't use getText(). You
want to use:

$n.text $b64.text $ident.text


>         ;
> base1   returns[String input] 


input is already in use as an object name within ANTLR, you need to use
a different name.

Then if your grammar is called myGrammar, you invoke it as:


myGrammar parser = new myGrammar(tokens);  // Set up your parser

// Next, your num rule will either return String (as you only have one return 
element) or the type num_return:
//

// Either...
//
num_return psrReturn = parser.num();
System.out.println("Return was " + psrReturn.t);

// Or if it just returns string:
//
String psrReturn = parser.num();
System.out.println("Return was " + psrReturn);

If you are not getting back a string value, then there is an error in
your grammar actions. 

I suggest that you buy a copy of the book or at least scan all the
available example grammars and contributed grammars.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to