summaryrefslogtreecommitdiff
path: root/core/parser.c
diff options
context:
space:
mode:
authorIan Moffett <ian@mirocom.org>2026-05-23 02:21:09 -0400
committerIan Moffett <ian@mirocom.org>2026-05-23 02:21:09 -0400
commit74e2e8c772d0f88da6684918f782b37156f10fb3 (patch)
treefa5d9431e7e3f8df98f1d7f8e5dc9f8c02d09002 /core/parser.c
parent659dd389326f73e6bcbce5311088c182d7cb580e (diff)
core: Add lexer + parser groundwork
Signed-off-by: Ian Moffett <ian@mirocom.org>
Diffstat (limited to 'core/parser.c')
-rw-r--r--core/parser.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/core/parser.c b/core/parser.c
new file mode 100644
index 0000000..a584a56
--- /dev/null
+++ b/core/parser.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include "cescal/log.h"
+#include "cescal/parser.h"
+#include "cescal/state.h"
+#include "cescal/lexer.h"
+
+/* Symbolic token */
+#define symtok(tok) \
+ "[" tok "]"
+
+/* Quoted token */
+#define qtok(tok) \
+ "'" tok "'"
+
+/* Convert token to string */
+#define tokstr1(tt) \
+ toktab[(tt)]
+
+/* Convert token to string */
+#define tokstr(tok) \
+ toktab[(tok)->type]
+
+/*
+ * Converts numeric tokens into human readable strings
+ */
+static const char *toktab[] = {
+ [TT_NONE] = symtok("none"),
+ [TT_IDENT] = symtok("ident"),
+ [TT_INTLIT] = symtok("number"),
+ [TT_LPAREN] = qtok("("),
+ [TT_RPAREN] = qtok(")"),
+ [TT_COMMA] = qtok(","),
+ [TT_RETURN] = qtok("return"),
+ [TT_PUB] = qtok("pub"),
+ [TT_PROC] = qtok("proc"),
+ [TT_BEGIN] = qtok("begin"),
+ [TT_END] = qtok("end")
+};
+
+int
+parser_parse(struct cescal_state *state)
+{
+ struct token tok;
+
+ if (state == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ while (lexer_nom(state, &tok) == 0) {
+ cc_trace("got token %s\n", tokstr(&tok));
+ }
+
+ return 0;
+}