#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; }