[antlr-interest] Infinite lexer exception allocation loop in C target C parser, antlr3.0

Hardy, Stephen Stephen_Hardy at rabbit.com
Mon Jul 2 13:30:36 PDT 2007


Hi all,
I'm tasked with some C-to-C translation, and have been using the ANSI C
grammar with the C target as a starting point, with antlr3.0.

The grammar inadvertently omits the possibility of using \x (hex)
escapes in a literal string, and this causes an infinite memory
allocation loop when the parser is run against tokens such as
"\x00\x00".  The offending sequence of code is in mSTRING_LITERAL(),
which calls mEscapeSequence(), which in turn allocates an exception
struct (CONSTRUCTEX()) when it fails to understand the \x.
Unfortunately, the calling code is a for(;;) loop which does not advance
the token stream, hence the lexer will allocate forever.  

Sorry I'm really new to this, so it may be my fault, but it looks like
it may be a C target problem.  Didn't see any similar problem mentioned
in the most recent archive.

Regards,
SJH


More information about the antlr-interest mailing list