hughperman / pure-lang

Automatically exported from code.google.com/p/pure-lang
0 stars 0 forks source link

Integer numbers starting with a leading 0 #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. enter a integer literal starting with a 0 digit
2. follow by a non-octal digit
3. result is 0

What is the expected output? What do you see instead?
I'd expect either an error message or the correct integer value.

What version of the product are you using? On what operating system?
0.42, 0.43

Please provide any additional information below.
The problem is in pure/lexer.ll: the definition of int should not have
[0-9]+ but instead should read [1-9][0-9]*

Original issue reported on code.google.com by ieeege...@gmail.com on 20 Feb 2010 at 6:08

GoogleCodeExporter commented 8 years ago
Mind that my solution excludes 0 by itself being an integer;
better fix this by allowing octal numbers as 0[0-7]*

Original comment by ieeege...@gmail.com on 20 Feb 2010 at 7:36

GoogleCodeExporter commented 8 years ago
Geert, I think that, in order to catch most typos, the best fix to is to just 
allow
0[0-9A-Za-z]* for all integers in the lexical syntax and have the lexer print an
error message if any of the digits are wrong for the indicated base. This is 
also
similar to what gcc does. It will exclude previously legal syntax such as 0x12g
(which would have been parsed as 0x12 g), but in most cases such inputs will be 
typos
anyway.

Fixed in r3087, thanks for reporting.

Original comment by aggraef@gmail.com on 20 Feb 2010 at 10:48