[antlr-interest] whats wrong in this very very simple grammar ?

Borat Borat nukethenuke at yahoo.com
Sat Mar 3 14:26:09 PST 2012


Hi,

I have very simple grammar, and I'm using antlr 3.3:

rule: stat EOF ;
stat: ID;
fragment LETTER : ('a'..'z' | 'A'..'Z') ;
ID: LETTER* ;
WS: (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;} ;

And test rig is :
ANTLRInputStream input = new ANTLRInputStream(System.in);
TestLexer lexer = new TestLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TestParser parser = new TestParser(tokens);
parser.rule();


Now, the problem, when I input, for example, abc and hit Ctrl + Z, I get error:
line 1:0 mismatched input '<EOF>' expecting ID

However, if I type abc for input and then hit enter and then press
Ctrl + Z everything executes as expected.

I was wondering if someone could explain me what is exactly happening here,
I fail to see why first scenario fails ? 

Thanks



More information about the antlr-interest mailing list