Skip to content

Commit

Permalink
dealing with parenthesis buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Feb 18, 2024
1 parent 7e328df commit 2db9514
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct pos
const char *filename;
};

#define NUMERCI_CASE \
#define NUMERIC_CASE \
case '0': \
case '1': \
case '2': \
Expand Down
16 changes: 14 additions & 2 deletions lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -259,7 +271,7 @@ static void lex_finish_expression()

bool lex_is_in_expression()
{
return lex_process->current_expression_count >= 0;

This comment has been minimized.

Copy link
@omdxp

omdxp Feb 18, 2024

Author Owner

yeah, this was a bug 🥲

return lex_process->current_expression_count > 0;
}

bool is_keyword(const char *str)
Expand Down Expand Up @@ -559,7 +571,7 @@ struct token *read_next_token()

switch (c)
{
NUMERCI_CASE:
NUMERIC_CASE:
token = token_make_number();
break;

Expand Down
11 changes: 1 addition & 10 deletions test.c
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2db9514

Please sign in to comment.