http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_test.cpp File tests/preprocessor_tests/number_test.cpp (right): http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_test.cpp#newcode40 tests/preprocessor_tests/number_test.cpp:40: testing::Range('0', '7'))); I do not think that would be ...
13 years, 12 months ago
(2012-04-13 21:45:56 UTC)
#3
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
File tests/preprocessor_tests/number_test.cpp (right):
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
tests/preprocessor_tests/number_test.cpp:40: testing::Range('0', '7')));
I do not think that would be a bug as far as lexer is concerned. It will just
tokenize a "08" as two integers - 0 and 8, which will later be rejected by the
compiler due to syntax error.
I feel that if we try to capture these kind of errors at the lexer stage, the
grammar will become too complicated. Do you have suggestion on handling these
cases in a more general way. I do not want to special case for 08 and 09. It
should also handle "0x", where x is any character.
On 2012/04/13 21:18:31, kbr1 wrote:
> How about negative tests, for example octal numbers attempting to include 8 or
> 9?
13 years, 12 months ago
(2012-04-13 22:14:06 UTC)
#4
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
File tests/preprocessor_tests/number_test.cpp (right):
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
tests/preprocessor_tests/number_test.cpp:40: testing::Range('0', '7')));
On 2012/04/13 21:45:56, Alok Priyadarshi wrote:
> I do not think that would be a bug as far as lexer is concerned. It will just
> tokenize a "08" as two integers - 0 and 8, which will later be rejected by the
> compiler due to syntax error.
>
> I feel that if we try to capture these kind of errors at the lexer stage, the
> grammar will become too complicated. Do you have suggestion on handling these
> cases in a more general way. I do not want to special case for 08 and 09. It
> should also handle "0x", where x is any character.
I don't know flex/bison well enough to know how to catch errors like this, but
it seems to me that if the lexer doesn't catch it then it will be difficult to
produce good error messages in the compiler, since it won't know that there
wasn't whitespace between the valid prefix and invalid suffix. For example, for
this program:
int main()
{
int 1a = 2;
return 0;
}
gcc produces 'error: invalid suffix "a" on integer constant'. For:
int main()
{
int a = 08;
return 0;
}
gcc produces 'error: invalid digit "8" in octal constant'. This is a different
error than if there were a space between the 0 and the 8.
You are right about the quality of error messages. In fact VC++ also produce error ...
13 years, 12 months ago
(2012-04-13 22:21:51 UTC)
#5
You are right about the quality of error messages. In fact VC++ also produce
error messages similar to GCC. I think it will be possible to catch these kind
of errors in flex with a catch-all rule for each type. I will try to figure it
out. Thanks for the examples.
On 2012/04/13 22:14:06, kbr1 wrote:
>
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
> File tests/preprocessor_tests/number_test.cpp (right):
>
>
http://codereview.appspot.com/6022045/diff/1/tests/preprocessor_tests/number_...
> tests/preprocessor_tests/number_test.cpp:40: testing::Range('0', '7')));
> On 2012/04/13 21:45:56, Alok Priyadarshi wrote:
> > I do not think that would be a bug as far as lexer is concerned. It will
just
> > tokenize a "08" as two integers - 0 and 8, which will later be rejected by
the
> > compiler due to syntax error.
> >
> > I feel that if we try to capture these kind of errors at the lexer stage,
the
> > grammar will become too complicated. Do you have suggestion on handling
these
> > cases in a more general way. I do not want to special case for 08 and 09. It
> > should also handle "0x", where x is any character.
>
> I don't know flex/bison well enough to know how to catch errors like this, but
> it seems to me that if the lexer doesn't catch it then it will be difficult to
> produce good error messages in the compiler, since it won't know that there
> wasn't whitespace between the valid prefix and invalid suffix. For example,
for
> this program:
>
> int main()
> {
> int 1a = 2;
> return 0;
> }
>
> gcc produces 'error: invalid suffix "a" on integer constant'. For:
>
>
> int main()
> {
> int a = 08;
> return 0;
> }
>
> gcc produces 'error: invalid digit "8" in octal constant'. This is a different
> error than if there were a space between the 0 and the 8.
Issue 6022045: Added tests for number types.
(Closed)
Created 14 years ago by Alok Priyadarshi
Modified 13 years, 12 months ago
Reviewers: kbr1
Base URL: http://angleproject.googlecode.com/svn/trunk/
Comments: 3