diff --git a/src/lexer.cpp b/src/lexer.cpp index 1487033d..596d0f71 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -260,7 +260,7 @@ static bool is_unicode_Lo_char(uint32_t c) { } void Lexer::eat_number() { - PK_LOCAL_STATIC const std::regex pattern("^(0[xo])?[0-9a-fA-F]+(\\.[0-9]+)?(L)?"); + PK_LOCAL_STATIC const std::regex pattern("^(0[xob])?[0-9a-fA-F]+(\\.[0-9]+)?(L)?"); std::smatch m; const char* i = token_start; @@ -278,14 +278,15 @@ static bool is_unicode_Lo_char(uint32_t c) { } if(m[1].matched && m[2].matched){ - SyntaxError("hex/octal literal should not contain a dot"); + SyntaxError("binary/hex/octal literal should not contain a dot"); } try{ int base = 10; size_t size; if (m[1].matched) { - if (m[1].str() == "0o") base=8; + if (m[1].str() == "0b") base = 2; + else if (m[1].str() == "0o") base = 8; else base = 16; } if (m[2].matched) { diff --git a/tests/01_int.py b/tests/01_int.py index f95264a4..3a27aeb4 100644 --- a/tests/01_int.py +++ b/tests/01_int.py @@ -9,6 +9,10 @@ assert 2**60-1 + 546 - 0xfffffffffffff == 1148417904979477026 assert 0o1234 == 668 assert 0o17777777777 == 2147483647 +# test binary literals +assert 0b10010 == 18 +assert 0b11111111111111111111111111111111 == 4294967295 + # test == != >= <= < > assert -1 == -1 assert -1 != 1