aboutsummaryrefslogtreecommitdiff
path: root/src/all.h
diff options
context:
space:
mode:
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);