[antlr-interest] Small input and grammar causes out of memory error (Java)

Jim Idle jimi at temporal-wave.com
Tue Dec 16 15:31:52 PST 2008


On Tue, 16 Dec 2008 13:50:26 -0800, <jason.terhune at thomsonreuters.com>  
wrote:

> Hi all,
>
> I was playing with the TDD example on the wiki, and I was surprised to
> see an out of memory error with my trivial grammar and input using
> v3.1.1.  After I fixed my grammar by adding a space to the NONBREAKING
> definition, the problem went away:
> NONBREAKING : ('a'..'z' | 'A'..'Z' | ' ');
>

That is a by prodcut of your reall error, which is that you have a lexer  
rule that can match nothing and so will (depending on your other rules),  
continue to match nohting forever:

> TERM : NONBREAKING*;


That should be a + not a *

Also, you cannot have two lexer rules matching the same thing, which  
NONBREAKING and TERM are doing as you have them. Perhaps you want  
NONBREAKING to be a fragment rule? Then it won't try to generate its own  
token match, fragment just means that you will use it in other rules.

Jim


More information about the antlr-interest mailing list