diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-06 15:40:35 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-06 20:07:56 -0400 |
commit | 0f38c9398c21e756a834140fbe6f023de51ef527 (patch) | |
tree | 3b2df11afe275557ba6aadba66b17c61ddf67088 | |
parent | 4589135bdde2dfbf899ab22f5d82e5d6abf020f0 (diff) |
Add gen_code src files, with gen_label func implemented
-rw-r--r-- | gen_code.c | 45 | ||||
-rw-r--r-- | gen_code.h | 10 |
2 files changed, 55 insertions, 0 deletions
diff --git a/gen_code.c b/gen_code.c new file mode 100644 index 0000000..7471e8f --- /dev/null +++ b/gen_code.c @@ -0,0 +1,45 @@ +#include "gen_code.h" +#include "pc.h" + +int gen_label(t) +ptree *t; +{ + int tmp; + + if (!(t->l && t->r)) + return 0; + + if (t->l) { + tmp = gen_label(t->l); + t->l->label = (!tmp ? 1 : tmp); + } else + yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n"); + + + if (t->r) + t->r->label = gen_label(t->r); + else + t->r->label = 0; + + + + + if (t->r->label == t->l->label) { + return 1 + t->l->label; + } else { + return t->r->label > t->l->label ? t->r->label : t->l->label; + } + +} + + +void gen_code(t) +ptree *t; +{ + /*Test gen_label*/ + if (t->type == ASSIGNOP){ + gen_label(t->r); + print_tree(t->r); + } +} + diff --git a/gen_code.h b/gen_code.h new file mode 100644 index 0000000..8c9ad00 --- /dev/null +++ b/gen_code.h @@ -0,0 +1,10 @@ +#ifndef GEN_CODEH +#define GEN_CODEH + +#include "tree.h" +void gen_code(ptree*); + +void gen_expr(ptree*); +void gen_statement(ptree*); + +#endif |