Su Zhang schreef:
> Hi all,
>  
> My program needs a string from Parser, but there is not any function
> provided in the public class parser, how can I get the string outside? I
> mean I want to get the string generated from the rules of
> antlr(functions in parser), and I have written  "returns[String s]" to
> indicate that I need the value, but how can i get the String? does
> anybody familiar with this kind of problem?

Use the specific parser that ANTLR generated from your grammar instead
of the generic Parser class.  It will have a public method for each rule
with the return type you specified or with some internally specified one
if you didn’t give one.

E.g. this is how I use my parser:

// Use ANTLR to parse the query string
final CharStream antlrInput = new ANTLRStringStream(queryString);
final Lexer lexer = new fsqLexer(antlrInput);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final fsqParser parser = new fsqParser(tokens);
final Formula queryFormula = parser.formula();

HTH, H.
-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Attachment: signature.asc
Description: OpenPGP digital signature

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