1
0
Fork 0

Improve lexer

This commit is contained in:
Alex Kotov 2023-05-05 15:55:42 +04:00
parent 250a91bc52
commit 6337d202d6
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 4 additions and 3 deletions

View File

@ -71,7 +71,8 @@ State_to_token_type(const enum State state, enum TokenType *const token_type)
void buffer_add(char chr)
{
assert(buffer_index < 1000);
buffer[buffer_index++] = chr;
buffer[buffer_index] = chr;
++buffer_index;
buffer[buffer_index] = 0;
}
@ -176,12 +177,12 @@ void Lexer_lex(const Lexer self, const char chr)
token_add(self->tokens, state, buffer);
buffer_clean();
state = STATE_IDENT;
buffer[buffer_index++] = chr;
buffer_add(chr);
} else if (is_number(chr)) {
token_add(self->tokens, state, buffer);
buffer_clean();
state = STATE_NUM;
buffer[buffer_index++] = chr;
buffer_add(chr);
} else {
abort();
}