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

Jim Idle jimi at temporal-wave.com
Sat Mar 3 14:28:38 PST 2012


Your ID matches an empty string so it will match forever and consume
nothing. You need + and not *

This is an FAQ, and please use the antlr.markmail.org search engine. You
can also trace your parser with the Java debugger.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Borat Borat
> Sent: Saturday, March 03, 2012 2:26 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] whats wrong in this very very simple grammar
> ?
>
> 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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list