[antlr-interest] Antlr3: Help - line 0:-1 mismatched input '<EOF>' ?

David Holroyd dave at badgers-in-foil.co.uk
Mon Jan 8 00:33:29 PST 2007


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/


More information about the antlr-interest mailing list