[antlr-interest] Antlr3: Help - line 0:-1 mismatched input '<EOF>' ?
Mark Mandel
mark.mandel at gmail.com
Mon Jan 8 01:41:36 PST 2007
Omg... I didn't think of that.
I'll give it a shot.
>slaps forehead<
Mark
On 1/8/07, David Holroyd <dave at badgers-in-foil.co.uk> wrote:
> Hi,
>
> On Mon, Jan 08, 2007 at 04:32:29PM +1100, Mark Mandel wrote:
> > I get the error:
> > line 0:-1 mismatched input '<EOF>' expecting SELECT
> >
> > Whenever I run my parser over my tokens, and I have no idea why. Is
> > line:0:-1 at the beginning or the end of the string?
>
> > My grammar and test bed is the following:
> >
> > [Test.java]
> >
> > public static void main(String[] args)
> > {
> > try
> > {
> > String tql = "select emails.Email.emailName, emails.Email.emailFrom from emails.Email where emails.Email.emailName = :name";
> > System.out.println(tql);
> > CharStream input = new ANTLRStringStream(tql);
> > TqlLexerLexer lexer = new TqlLexerLexer(input);
> > Token token;
> > while ((token = lexer.nextToken())!=Token.EOF_TOKEN) {
> > System.out.println("Token["+ token.getType() +"]:
> > "+token.getText());
> > }
>
> Does it work without the above while-loop in there? If you've already
> read all the tokens up to EOF from the lexer, that sounds like a good
> reason for the parser to complain about EOF being the first thing it
> sees.
>
> > CommonTokenStream tokens = new CommonTokenStream(lexer);
> > TqlParserParser parser = new TqlParserParser(tokens);
> > TqlParserParser.selectStatement_return root =
> > parser.selectStatement();
> > System.out.println("tree="+((Tree)root.tree).toStringTree());
>
> [Didn't run the code to confirm that, sorry.]
>
>
> ta,
> dave
>
> --
> http://david.holroyd.me.uk/
>
--
E: mark.mandel at gmail.com
W: www.compoundtheory.com
More information about the antlr-interest
mailing list