diff --git a/compiler.h b/compiler.h index be9973f..cbdaddd 100644 --- a/compiler.h +++ b/compiler.h @@ -45,6 +45,16 @@ struct pos case '.': \ case '?' +#define SYMBOL_CASE \ + case '{': \ + case '}': \ + case ':': \ + case ';': \ + case '#': \ + case '\\': \ + case ')': \ + case ']' + enum { LEXICAL_ANALYSIS_ALL_OK, diff --git a/lexer.c b/lexer.c index 8ff7c3a..3937c19 100644 --- a/lexer.c +++ b/lexer.c @@ -193,8 +193,7 @@ void read_op_flush_back_keep_first(struct buffer *buffer) } } -const char * -read_op() +const char *read_op() { bool single_operator = true; char op = nextc(); @@ -240,6 +239,15 @@ static void lex_new_expression() } } +static void lex_finish_expression() +{ + lex_process->current_expression_count--; + if (lex_process->current_expression_count < 0) + { + compiler_error(lex_process->compiler, "Closed expression that was never opened\n"); + } +} + bool lex_is_in_expression() { return lex_process->current_expression_count >= 0; @@ -265,6 +273,18 @@ static struct token *token_make_operator_or_string() return token; } +static struct token *token_make_symbol() +{ + char c = nextc(); + if (c == ')') + { + lex_finish_expression(); + } + + struct token *token = token_create(&(struct token){.type = TOKEN_TYPE_SYMBOL, .cval = c}); + return token; +} + struct token * read_next_token() { @@ -280,6 +300,10 @@ read_next_token() token = token_make_operator_or_string(); break; + SYMBOL_CASE: + token = token_make_symbol(); + break; + case '"': token = token_make_string('"', '"'); break; diff --git a/test.c b/test.c index 1a1ed95..75956cb 100644 --- a/test.c +++ b/test.c @@ -1 +1 @@ -50 + 20 - 10 ++ +50 + 20 - 10 ++(50 + 20)[#]