From 64aea8de7d042117cfe807c1eaa58f7a5d35a2ed Mon Sep 17 00:00:00 2001 From: hankluo6 Date: Fri, 1 Mar 2024 16:04:56 -0600 Subject: [PATCH 1/2] Prevent leading zeros in integer literals --- src/lpython/parser/tokenizer.re | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lpython/parser/tokenizer.re b/src/lpython/parser/tokenizer.re index 64b0488b76..7cdb4416b8 100644 --- a/src/lpython/parser/tokenizer.re +++ b/src/lpython/parser/tokenizer.re @@ -96,6 +96,10 @@ void lex_int(Allocator &al, const unsigned char *s, u.from_smallint(n); } else { lex_dec_int_large(al, s, e, u); + if (s[0] == '0' && u.n != 0) { + throw parser_local::TokenizerError( + "Leading zeros in decimal integer are not allowed", {loc}); + } } return; } From a97952d86b059c890604ecd0f6b52253a723c6da Mon Sep 17 00:00:00 2001 From: hankluo6 Date: Sat, 2 Mar 2024 19:35:16 -0600 Subject: [PATCH 2/2] Remove parentheses for consistency --- src/lpython/parser/tokenizer.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/parser/tokenizer.re b/src/lpython/parser/tokenizer.re index 7cdb4416b8..e5e9f524f0 100644 --- a/src/lpython/parser/tokenizer.re +++ b/src/lpython/parser/tokenizer.re @@ -89,7 +89,7 @@ void lex_int(Allocator &al, const unsigned char *s, s = s + 2; uint64_t n = get_value((char*)s, 2, loc); u.from_smallint(n); - } else if ((std::tolower(s[1]) == 'o')) { + } else if (std::tolower(s[1]) == 'o') { // Oct s = s + 2; uint64_t n = get_value((char*)s, 8, loc);