🐛 usub error with negative numbers.

main
bog 2024-04-02 00:01:33 +02:00
parent 22cf99faa9
commit 441acdeea2
4 changed files with 6 additions and 19 deletions

View File

@ -5,4 +5,5 @@ assert 6 * 7 eq 42
assert 1 + 2 * 3 eq 7
assert (1 + 2) * 3 eq 9
assert -2^3 eq -8
assert -2^4 eq -16
assert 32 % 7 eq 4

View File

@ -200,13 +200,6 @@ struct token* lexer_try_scan_int(struct lexer* self)
struct str value;
str_init(&value);
if (cursor < self->len
&& self->source[cursor] == '-')
{
str_push(&value, self->source[cursor]);
cursor++;
}
while (cursor < self->len
&& isdigit(self->source[cursor]))
{
@ -237,13 +230,6 @@ struct token* lexer_try_scan_float(struct lexer* self)
struct str value;
str_init(&value);
if (cursor < self->len
&& self->source[cursor] == '-')
{
str_push(&value, self->source[cursor]);
cursor++;
}
while (cursor < self->len
&& isdigit(self->source[cursor]))
{

View File

@ -42,9 +42,9 @@ static void test_lexer(char const* source, int count, ...)
static void test_lexer_int()
{
test_lexer(" 4 -23 720 ", 3,
test_lexer(" 4 23 720 ", 3,
"INT[4]",
"INT[-23]",
"INT[23]",
"INT[720]"
);
@ -77,11 +77,11 @@ static void test_lexer_bool()
static void test_lexer_float()
{
test_lexer(".4 7. 2.3 -6.12", 4,
test_lexer(".4 7. 2.3 6.12", 4,
"FLOAT[.4]",
"FLOAT[7.]",
"FLOAT[2.3]",
"FLOAT[-6.12]"
"FLOAT[6.12]"
);
}

View File

@ -31,7 +31,7 @@ static void test_parser_int()
{
test_parser("ROOT(INT[32])", " 32 ");
test_parser("ROOT(INT[32],INT[-2],INT[24])", " 32 -2 24");
test_parser("ROOT(INT[32],INT[2],INT[24])", " 32 2 24");
test_parser("ROOT(ADD(INT[1],MUL(INT[2],INT[3])))",
" 1 + 2 * 3 ");