From af780dc32cbc9d9a40bec1e2ea538e71001c36aa Mon Sep 17 00:00:00 2001 From: thing1 Date: Fri, 14 Mar 2025 17:37:27 +0000 Subject: init commit --- parse.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 parse.c (limited to 'parse.c') diff --git a/parse.c b/parse.c new file mode 100644 index 0000000..94623a5 --- /dev/null +++ b/parse.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#include "types.h" + +parsetypes prevtype = NILPARSETYPE; + +ast *genast(lexobj lexes[4096], int *lexcount) { + static ast a; + switch (prevtype) { + case NILPARSETYPE: + case FUNCEND: + a.function = lexes[*lexcount + 1].data; // function name + a.litteralchildren[0] = lexes[*lexcount].data; // function ret type + *lexcount += 2; + a.childcount++; + while (lexes[*lexcount].t != CLOSEBRACE) { + a.litteralchildren[a.childcount] = lexes[*lexcount].data; + *lexcount += 1; + a.childcount++; + } + *lexcount += 1; // move the lexptr to the start of the functions code + prevtype = FUNCTIONDEF; + return &a; + case FUNCTIONDEF: + a.function = lexes[*lexcount].data; + *lexcount += 1; + if (lexes[*lexcount].t == INTLIT) { + a.litteralchildren[0] = lexes[*lexcount].data; + *lexcount += 1; + return &a; + } + else { + a.children[0] = genast(lexes, lexcount); + } + } + return &a; +} -- cgit v1.2.3