summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c39
1 files changed, 39 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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;
+}