mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
Added binary literal support
This commit is contained in:
parent
4d2b3e59a1
commit
badc8d44d1
@ -260,7 +260,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Lexer::eat_number() {
|
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;
|
std::smatch m;
|
||||||
|
|
||||||
const char* i = token_start;
|
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){
|
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{
|
try{
|
||||||
int base = 10;
|
int base = 10;
|
||||||
size_t size;
|
size_t size;
|
||||||
if (m[1].matched) {
|
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;
|
else base = 16;
|
||||||
}
|
}
|
||||||
if (m[2].matched) {
|
if (m[2].matched) {
|
||||||
|
@ -9,6 +9,10 @@ assert 2**60-1 + 546 - 0xfffffffffffff == 1148417904979477026
|
|||||||
assert 0o1234 == 668
|
assert 0o1234 == 668
|
||||||
assert 0o17777777777 == 2147483647
|
assert 0o17777777777 == 2147483647
|
||||||
|
|
||||||
|
# test binary literals
|
||||||
|
assert 0b10010 == 18
|
||||||
|
assert 0b11111111111111111111111111111111 == 4294967295
|
||||||
|
|
||||||
# test == != >= <= < >
|
# test == != >= <= < >
|
||||||
assert -1 == -1
|
assert -1 == -1
|
||||||
assert -1 != 1
|
assert -1 != 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user