summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/lexer.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/lexer.c b/core/lexer.c
index 51e4d40..1d1e900 100644
--- a/core/lexer.c
+++ b/core/lexer.c
@@ -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;
}
}