[antlr-interest] [BUG FIX] Generates bad empty lookahead test expression in C++
ods94538
ods94538 at yahoo.com
Mon Sep 23 09:48:41 PDT 2002
Greetings,
Found the following bug but am unsure how to submit it. Here's the
skinny; if anyone knows a better place for me to send such stuff,
please let me know!
The problem occurs with the following (stripped-down) grammar:
-- begin test.g --
options {
language="Cpp";
}
class TestLexer extends Lexer;
options {
k=2;
charVocabulary='\3'..'\377';
}
COMMENT
: "/*"
( '*' ~'/'
| NEWLINE
| ~('*'|'/'|'\n'|'\r') )*
"*/"
;
NEWLINE: '\r' ('\n')? | '\n' { newline(); };
-- end test.g --
There is a nondeterminism in NEWLINE which generates the following
lookahead tests in the corresponding lexer method, mNEWLINE. The
problem is that the "if (true)" is missing parentheses, so the file
doesn't compile.
-- begin TestLexer.cpp:134-149 --
case static_cast<unsigned char>('\r'):
{
match(static_cast<unsigned char>('\r'));
{
if ((LA(1)==static_cast<unsigned char>('\n')) && (true)) {
match(static_cast<unsigned char>('\n'));
}
else if true { // <-- should be (true)
}
else {
throw ...
}
}
break;
}
-- end TestLexer.cpp --
I propose the following patch:
CppCodeGenerator.java:3584
< return "true";
> return "(true)";
as this seems to generate the correct C++ code.
-- Owen
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list