mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

commit c02ee739581c03a36017807ca8e797e881bd1f34
parent bb58229d059a69fec4f6c26f8514b3406028840c
Author: citbl <citbl@citbl.org>
Date:   Thu, 21 May 2026 21:57:54 +1000

refac

Diffstat:
Mmtcc/src/lexer.c | 4++--
Mmtcc/src/lexer.h | 10+---------
Mmtcc/src/main.c | 41+++++++++++------------------------------
Amtcc/src/parser.c | 5+++++
Amtcc/src/parser.h | 5+++++
Amtcc/src/types.h | 42++++++++++++++++++++++++++++++++++++++++++
6 files changed, 66 insertions(+), 41 deletions(-)

diff --git a/mtcc/src/lexer.c b/mtcc/src/lexer.c @@ -1,8 +1,8 @@ #include <stdbool.h> -#include "lexer.h" -#include "string.h" #include "array.h" +#include "string.h" +#include "lexer.h" static bool is__(const char c); static bool is_alpha(const char c); diff --git a/mtcc/src/lexer.h b/mtcc/src/lexer.h @@ -1,13 +1,5 @@ #pragma once -#include "token.h" -struct lexer { - const char *file; - const char *src; - size_t src_len; - struct token *tokens; - size_t tok_len; - size_t tok_cap; -}; +#include "types.h" void lexer_lex(struct lexer *); diff --git a/mtcc/src/main.c b/mtcc/src/main.c @@ -1,42 +1,16 @@ #include <stdio.h> #include <stdbool.h> #include "utils.h" +#include "types.h" #include "lexer.h" - -struct scope { - void *tbd; -}; - -enum node_type { - NODE_PROGRAM = 100, - NODE_FUNC_DECL, -}; - -struct node { - enum node_type type; - struct token token; - struct scope *scope; - union { - /* clang-format off */ - struct { struct node **declarations; size_t len, cap; } program; - struct { struct node* return_type; struct node** params; size_t p_len, p_cap; struct node* body; bool is_public; } func_decl; - struct { struct node* type; } func_decl_param; - /* clang-format on */ - }; -}; - -struct parser { - struct lexer *lexer; - struct node **nodes; - size_t nodes_len; - size_t nodes_cap; -}; +#include "parser.h" int main(int argc, char **argv) { const char *filename; file_t file; struct lexer lexer; + struct parser parser; if (argc < 2) { const char *cmp = argv[0]; @@ -46,6 +20,9 @@ main(int argc, char **argv) { filename = argv[1]; file = read_file(filename); + + printf("%s\n", file.contents); + lexer = (struct lexer){ .file = filename, .src = file.contents, @@ -54,5 +31,9 @@ main(int argc, char **argv) { lexer_lex(&lexer); - printf("%s\n", file.contents); + parser = (struct parser){ + .lexer = &lexer, + }; + + parser_parse(&parser); } diff --git a/mtcc/src/parser.c b/mtcc/src/parser.c @@ -0,0 +1,5 @@ +#include "parser.h" + +void +parser_parse(struct parser *parser) { +} diff --git a/mtcc/src/parser.h b/mtcc/src/parser.h @@ -0,0 +1,5 @@ +#pragma once + +#include "types.h" + +void parser_parse(struct parser *parser); diff --git a/mtcc/src/types.h b/mtcc/src/types.h @@ -0,0 +1,42 @@ +#pragma once + +#include <stddef.h> +#include "token.h" + +struct lexer { + const char *file; + const char *src; + size_t src_len; + struct token *tokens; + size_t tok_len; + size_t tok_cap; +}; + +struct scope { + void *tbd; +}; + +enum node_type { + NODE_PROGRAM = 100, + NODE_FUNC_DECL, +}; + +struct node { + enum node_type type; + struct token token; + struct scope *scope; + union { + /* clang-format off */ + struct { struct node **declarations; size_t len, cap; } program; + struct { struct node* return_type; struct node** params; size_t p_len, p_cap; struct node* body; bool is_public; } func_decl; + struct { struct node* type; } func_decl_param; + /* clang-format on */ + }; +}; + +struct parser { + struct lexer *lexer; + struct node **nodes; + size_t nodes_len; + size_t nodes_cap; +};