diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2024-09-16 12:06:09 +0100 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2024-09-16 12:06:09 +0100 |
commit | 9eafce19945f858649eaac8eabfee9ec1857c1cd (patch) | |
tree | b06cac968dc4319bbd4e5dd5a99e1b049af67e87 /comp/lucas-standen-NEA/code2/comp.c | |
parent | f35cd6c1d15ce31cd5f1d1d578a7a2a4880c2179 (diff) |
finished the compiler, moving on to advaced command line tool
Diffstat (limited to 'comp/lucas-standen-NEA/code2/comp.c')
-rw-r--r-- | comp/lucas-standen-NEA/code2/comp.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/comp/lucas-standen-NEA/code2/comp.c b/comp/lucas-standen-NEA/code2/comp.c index bdca47f..6d96994 100644 --- a/comp/lucas-standen-NEA/code2/comp.c +++ b/comp/lucas-standen-NEA/code2/comp.c @@ -4,6 +4,7 @@ #include <stdbool.h> #include "tokenizer.h" +#include "util.h" #include "appendsnprintf.h" #define MAXOUTLEN 512 @@ -99,6 +100,13 @@ char *getVarName(char *exp){ return out; } +char *getVarType(char *exp){ + char *out = malloc(strlen(exp)); + char *pos = strchr(exp, ':')+1; + memcpy(out, pos, strlen(pos) + 1); + return out; +} + char *reversepolishToC(astNode *exp, char *out){ out = appendsnprintf(out, MAXOUTLEN, "%s ", exp->args[0]); if (exp->func[0] == '=') out = appendsnprintf(out, MAXOUTLEN, "=="); @@ -125,7 +133,7 @@ char *compile(astNode *node){ out = appendsnprintf(out, MAXOUTLEN, "%s %s(", node->args[1], node->args[0]); int i = 2; while (node->args[i] != NULL){ - if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ",", node->args[i]); + if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ","); out = vartypeToC(node->args[i], out); i++; } @@ -213,6 +221,17 @@ char *compile(astNode *node){ else if (strcmp(names[27], node->func) == 0){ out = appendsnprintf(out, MAXOUTLEN, "sizeof(%s)", node->args[0]); } + else if (strcmp(names[28], node->func) == 0){ + out = appendsnprintf(out, MAXOUTLEN, "%s (*%s)", node->args[1], node->args[0]); + int i = 2; + while (node->args[i] != NULL){ + if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ","); + else out = appendsnprintf(out, MAXOUTLEN, "("); + out = appendsnprintf(out, MAXOUTLEN, "%s", getVarType(node->args[i])); + i++; + } + out = appendsnprintf(out, MAXOUTLEN, ")"); + } else { // arithmetic operators and comparitors |