core: lexer: Add keyword tokens

Signed-off-by: Chloe M. <chloe@mirocom.org>
This commit is contained in:
2026-05-23 07:59:47 -04:00
parent 596e63e468
commit 9bc47590c3
+45
View File
@@ -7,6 +7,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "cescal/lexer.h"
#include "cescal/log.h"
#include "cescal/ptrbox.h"
@@ -135,6 +136,49 @@ lexer_scan_ident(struct cescal_state *state, char lc, struct token *res)
return 0;
}
/*
* Checks if an identifier token is actually a keyword
*
* @state: Compiler state
* @res: Token result
*/
static void
lexer_check_kw(struct cescal_state *state, struct token *res)
{
if (state == NULL || res == NULL) {
return;
}
switch (*res->s) {
case 'p':
if (strcmp(res->s, "pub") == 0) {
res->type = TT_PUB;
return;
}
if (strcmp(res->s, "proc") == 0) {
res->type = TT_PROC;
return;
}
break;
case 'b':
if (strcmp(res->s, "begin") == 0) {
res->type = TT_BEGIN;
return;
}
break;
case 'e':
if (strcmp(res->s, "end") == 0) {
res->type = TT_END;
return;
}
break;
}
}
int
lexer_nom(struct cescal_state *state, struct token *res)
{
@@ -164,6 +208,7 @@ lexer_nom(struct cescal_state *state, struct token *res)
return 0;
default:
if (lexer_scan_ident(state, c, res) == 0) {
lexer_check_kw(state, res);
return 0;
}
}