summaryrefslogtreecommitdiff
path: root/lex
diff options
context:
space:
mode:
author0x221e <x221e@0xinfinity.dev>2026-06-22 13:18:43 +0300
committer0x221e <x221e@0xinfinity.dev>2026-06-22 13:22:10 +0300
commitad5d641ad41f415cca3cc01c88bc063319aba937 (patch)
treef03b2c0116bb41535e2fe7aa11294948b66e99c8 /lex
parent45f4a6afd2a5683fa53f9d6787e3c5b0f70229fd (diff)
downloadmetalc-master.tar.gz
parser: add unary, and binary operationsHEADmaster
lex: add bang passes: add initial debug pass
Diffstat (limited to 'lex')
-rw-r--r--lex/lex.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lex/lex.c b/lex/lex.c
index ea0978e..f787619 100644
--- a/lex/lex.c
+++ b/lex/lex.c
@@ -4,7 +4,6 @@
#include <string.h>
#include <platform/osal.h>
-
#include <stdio.h>
static struct token keywords[] = {
@@ -46,6 +45,7 @@ const char *lex_get_token_name(int id)
__GET_TKN_NAME(TOKEN_MINUS);
__GET_TKN_NAME(TOKEN_STAR);
__GET_TKN_NAME(TOKEN_SLASH);
+ __GET_TKN_NAME(TOKEN_BANG);
default:
print("lex_get_token_name: token not found: %d!", id);
exitc(1);
@@ -266,13 +266,12 @@ struct token lex_keyword(struct lex *l) //APPROPRIATE INC
}
if (strncmp(&l->buffer[start], keywords[i].lexeme, keywords[i].length) == 0) {
- tt = keywords[i].type;
+ tt = keywords[i].type;
break;
}
}
return (struct token) {.type = tt, .length=len, .lexeme = &l->buffer[start]};
-
}
struct token lex_next(struct lex *l)
@@ -329,11 +328,14 @@ struct token lex_next(struct lex *l)
case '/':
lex_advance(l, 1);
return TOKEN(TOKEN_SLASH, "/");
+ case '!':
+ lex_advance(l, 1);
+ return TOKEN(TOKEN_BANG, "!");
default:
char curr = lex_seek(l, 0);
- if (lex_is_char(curr) || (curr == '_')) {
+ if (lex_is_char(curr) || (curr == '_'))
return lex_keyword(l);
- }
+
return TOKEN(TOKEN_INVALID, "INVALID");
}
}