[antlr-interest] Bug in ANTLR C runtime - Incorrect getCharPositionInLine on first line
Ales Teska
ales.teska at gmail.com
Thu Oct 8 14:33:10 PDT 2009
Hi,
I'm using ANTLR3 in one of my project and it seems that I found small
bug in ANTLR C (version 3.2, 3.1.3 is also corrupted).
I do not know if this is correct way of reporting bugs but ...
ANTLR3 C runtime returns incorrect values of CharPositionInLine for
tokens on first line of input. This is eventually propagated to tokens.
I wrote small program to demonstrate this behavior - it is available
here: http://devel-www.cyber.cz/files/tmp/antlrc3-bug-pack.zip
Bug causes token stream post-processing a little bit more complicated
than it can ideally be ...
Here is expected output (produced by Python target).
First character is from input.txt, second is result of
getCharPositionInLine():
--- cut --- cut --- cut ---
1 0
2 2
3 4
\n 5
1 0
2 2
3 4
\n 5
--- cut --- cut --- cut ---
and here is actual output from C target:
--- cut --- cut --- cut ---
1 4294967295
2 1
3 3
\n 4
1 0
2 2
3 4
\n 5
--- cut --- cut --- cut ---
Please notice that first token has undefined value in
getCharPositionInLine() and rest till end of line is shifted by -1.
Workaround is to set ctx->pLexer->input->charPositionInLine to zero
after constructing lexer and before actual lexing/parsing.
Regards,
Ales Teska
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2371 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091008/2e224983/attachment.bin
More information about the antlr-interest
mailing list