aboutsummaryrefslogtreecommitdiff
path: root/src/all.h
diff options
context:
space:
mode:
authorElis Eriksson <spelis@spelis.li>2026-06-13 17:40:25 +0200
committerElis Eriksson <spelis@spelis.li>2026-06-13 17:40:25 +0200
commit7ccae1c362a45b28f4fbf96da4f479730e4b382b (patch)
treef59ba4d76221590901784464a03a6a871d774305 /src/all.h
downloadbfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar.gz
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar.bz2
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar.lz
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar.xz
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.tar.zst
bfc-7ccae1c362a45b28f4fbf96da4f479730e4b382b.zip
Initial Commit, probably needs heavy code cleanup
Diffstat (limited to 'src/all.h')
-rw-r--r--src/all.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/all.h b/src/all.h
new file mode 100644
index 0000000..c5a983c
--- /dev/null
+++ b/src/all.h
@@ -0,0 +1,65 @@
+#pragma once
+#include "ivec.h"
+#include "node_vec.h"
+#include "str.h"
+#include <stdbool.h>
+#include <stddef.h>
+
+// Lexer
+
+typedef enum {
+ LEX_PINC,
+ LEX_PDEC,
+ LEX_VINC,
+ LEX_VDEC,
+ LEX_OUT,
+ LEX_IN,
+ LEX_LB,
+ LEX_RB,
+ LEX_EOF
+} lex_tok_e;
+
+typedef struct {
+ str *src;
+ size_t pos;
+ ivec tokens;
+} lexer_t;
+
+lexer_t lex_init(str *src);
+void lex_run(lexer_t *lx);
+void lex_free(lexer_t *lx);
+
+// Parser/AST
+
+typedef struct ast_node ast_node_t;
+
+typedef enum {
+ AST_INC,
+ AST_DEC,
+ AST_PTR_INC,
+ AST_PTR_DEC,
+ AST_OUT,
+ AST_IN,
+ AST_LOOP
+} ast_type_e;
+
+struct ast_node {
+ ast_type_e type;
+ int val;
+
+ node_vec children; // vec<ast_node_t*>
+ ast_node_t *next;
+};
+
+typedef struct {
+ lexer_t *lx;
+ size_t pos;
+} parser_t;
+
+parser_t parser_init(lexer_t *lx);
+ast_node_t *parse_program(parser_t *p);
+void ast_free(ast_node_t *node);
+
+// codegen
+
+str gen_code(ast_node_t *ast);