From 2db9514a3e21634f63bc5c5a8f75e265ee232298 Mon Sep 17 00:00:00 2001 From: omdxp Date: Sun, 18 Feb 2024 10:30:24 +0100 Subject: [PATCH] dealing with parenthesis buffer --- compiler.h | 2 +- lexer.c | 16 ++++++++++++++-- test.c | 11 +---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/compiler.h b/compiler.h index cbdaddd..cb1335c 100644 --- a/compiler.h +++ b/compiler.h @@ -14,7 +14,7 @@ struct pos const char *filename; }; -#define NUMERCI_CASE \ +#define NUMERIC_CASE \ case '0': \ case '1': \ case '2': \ diff --git a/lexer.c b/lexer.c index 102667a..3e3d906 100644 --- a/lexer.c +++ b/lexer.c @@ -13,6 +13,7 @@ } struct token *read_next_token(); +bool lex_is_in_expression(); static struct lex_process *lex_process; static struct token tmp_token; @@ -25,6 +26,13 @@ static char peekc() static char nextc() { char c = lex_process->function->next_char(lex_process); + + // write paranethesis to an expression buffer (.e.g (20 + 10)) + if (lex_is_in_expression()) + { + buffer_write(lex_process->parenthesis_buffer, c); + } + lex_process->pos.col += 1; if (c == '\n') { @@ -57,6 +65,10 @@ struct token *token_create(struct token *_token) { memcpy(&tmp_token, _token, sizeof(struct token)); tmp_token.pos = lex_file_position(); + if (lex_is_in_expression()) + { + tmp_token.between_brackets = buffer_ptr(lex_process->parenthesis_buffer); + } return &tmp_token; } @@ -259,7 +271,7 @@ static void lex_finish_expression() bool lex_is_in_expression() { - return lex_process->current_expression_count >= 0; + return lex_process->current_expression_count > 0; } bool is_keyword(const char *str) @@ -559,7 +571,7 @@ struct token *read_next_token() switch (c) { - NUMERCI_CASE: + NUMERIC_CASE: token = token_make_number(); break; diff --git a/test.c b/test.c index f74ca95..0b08d9e 100644 --- a/test.c +++ b/test.c @@ -1,10 +1 @@ -50 + 20 - 10 ++(50 + 20)[#] dksdskdk6sd rele_frle pksdk int restrict float continue - - // this is a comment - /* - multile line comment - */ - - 'a' '\n' '\t' - - 0xFE12 0b1110011 +(20 + 10)