commit 613e94fd674226346973b98cac8cde97e5b9bff2
parent d5d9ba503bddab9fd6da4d1b06ebbdad85d09ea2
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Thu, 9 Oct 2025 12:12:25 +0100
progressed the lexer slightly further
Diffstat:
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/lex.c b/lex.c
@@ -35,7 +35,7 @@ peekc(FILE *in) {
}
lex_val *
-lex_char(char c, lex_type t) {
+lex_char(char c, enum lex_type t) {
if (getchr(input) != c) return &lex_error;
lv.type = t;
lv.data = NULL;
@@ -93,15 +93,17 @@ lex_sym() {
case '=': getchr(input); lv.type = LTE; break;
default: lv.type = LT; break;
}
- return lv;
+ return &lv;
case '>':
switch (peekc(input)) {
case '=': getchr(input); lv.type = GTE; break;
default: lv.type = GT; break;
}
- return lv;
+ return &lv;
case '!':
- lv.type = LT; break;
+ if (!check_bytes("=")) return &lex_error;
+ lv.type = NEQ;
+ break;
case '+': lv.type = LT; break;
case '-': lv.type = LT; break;
case '/': lv.type = LT; break;
@@ -122,6 +124,7 @@ lex_name(void) {
memcpy(strnul(name), &c, 1);
if ((len++ + 1) == 32) return &lex_error;
} while(isalnum((c = getc(input))));
+ ungetc(c, input);
lv.data = name;
lv.type = NAME;
diff --git a/lex.h b/lex.h
@@ -28,7 +28,7 @@ enum lex_type {
SHORT,
LONG,
OCBRACE,
- CCBRACE,
+ CCBRACE
};
typedef struct lex_val {
diff --git a/main.c b/main.c
@@ -4,10 +4,10 @@
int
main() {
+ lex_val *val;
FILE *f = fopen("test.hlc", "r");
init_lexer(f);
- lex_val *val;
while (val = get_next())
continue;
diff --git a/test.hlc b/test.hlc
@@ -1 +1 @@
-byte *name
+byte *name;