#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_CLEAR } 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); ast_node_t *optimize_ast(ast_node_t *ast); void ast_free(ast_node_t *node); void ast_dump(ast_node_t *node, int depth); // codegen str gen_code(ast_node_t *ast);