From 7ccae1c362a45b28f4fbf96da4f479730e4b382b Mon Sep 17 00:00:00 2001 From: Elis Eriksson Date: Sat, 13 Jun 2026 17:40:25 +0200 Subject: Initial Commit, probably needs heavy code cleanup --- src/all.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/all.h (limited to 'src/all.h') 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 +#include + +// 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 *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); -- cgit v1.3-7-ge9ab