Skip to content

Commit

Permalink
Start working on *= and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jun 13, 2024
1 parent 90a37cf commit 0f05b64
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions Sources/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion Sources/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0f05b64

Please sign in to comment.