From 0f05b641549244a04b923a9afb76530ffe85b013 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Thu, 13 Jun 2024 18:39:09 +0200 Subject: [PATCH] Start working on *= and friends --- Sources/parser.c | 2 +- Sources/tokenizer.c | 20 ++++++++++++++++++++ Sources/tokenizer.h | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sources/parser.c b/Sources/parser.c index 3873900..8793cb0 100644 --- a/Sources/parser.c +++ b/Sources/parser.c @@ -379,7 +379,7 @@ static expression *parse_assign(state_t *state) { while (!done) { if (current(state).kind == TOKEN_OPERATOR) { operatorr op = current(state).op; - if (op == OPERATOR_ASSIGN) { + if (op == OPERATOR_ASSIGN || op == OPERATOR_MINUS_ASSIGN || op == OPERATOR_PLUS_ASSIGN || op == OPERATOR_DIVIDE_ASSIGN || op == OPERATOR_MULTIPLY_ASSIGN) { advance_state(state); expression *right = parse_logical(state); expression *expression = expression_allocate(); diff --git a/Sources/tokenizer.c b/Sources/tokenizer.c index f36be77..4abbe96 100644 --- a/Sources/tokenizer.c +++ b/Sources/tokenizer.c @@ -453,6 +453,26 @@ tokens tokenize(const char *filename, const char *source) { token.op = OPERATOR_MOD; tokens_add(&tokens, token); } + else if (tokenizer_buffer_equals(&buffer, "-=")) { + token token = token_create(TOKEN_OPERATOR, &state); + token.op = OPERATOR_MINUS_ASSIGN; + tokens_add(&tokens, token); + } + else if (tokenizer_buffer_equals(&buffer, "+=")) { + token token = token_create(TOKEN_OPERATOR, &state); + token.op = OPERATOR_PLUS_ASSIGN; + tokens_add(&tokens, token); + } + else if (tokenizer_buffer_equals(&buffer, "/=")) { + token token = token_create(TOKEN_OPERATOR, &state); + token.op = OPERATOR_DIVIDE_ASSIGN; + tokens_add(&tokens, token); + } + else if (tokenizer_buffer_equals(&buffer, "*=")) { + token token = token_create(TOKEN_OPERATOR, &state); + token.op = OPERATOR_MULTIPLY_ASSIGN; + tokens_add(&tokens, token); + } else if (tokenizer_buffer_equals(&buffer, "=")) { token token = token_create(TOKEN_OPERATOR, &state); token.op = OPERATOR_ASSIGN; diff --git a/Sources/tokenizer.h b/Sources/tokenizer.h index 5bb1ee3..c2e4db2 100644 --- a/Sources/tokenizer.h +++ b/Sources/tokenizer.h @@ -20,7 +20,11 @@ typedef enum operatorr { OPERATOR_OR, OPERATOR_AND, OPERATOR_MOD, - OPERATOR_ASSIGN + OPERATOR_ASSIGN, + OPERATOR_MINUS_ASSIGN, + OPERATOR_PLUS_ASSIGN, + OPERATOR_DIVIDE_ASSIGN, + OPERATOR_MULTIPLY_ASSIGN } operatorr; typedef struct token {