From 9911f9a73c7dc46069199e52f2bc54082d10366c Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 3 Jan 2018 23:10:59 +0100 Subject: Initial --- node.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 node.h (limited to 'node.h') diff --git a/node.h b/node.h new file mode 100644 index 0000000..81d0b26 --- /dev/null +++ b/node.h @@ -0,0 +1,56 @@ +#pragma once + +#include "type.h" + + +enum node_type { + N_LIST, // [head] [tail] + N_LIST_END, // -- + N_BLOCK, // [body] + N_VAR_DECL_INIT, // rtype name [value] + N_VAR_DECL, // rtype name + N_FUNC_DECL, // rtype name [params] [body] + N_IF, // [cond] [body] [else-body] + N_WHILE, // [cond] [body] + N_RETURN, // [value] + N_NUM, // value + N_VAR, // name + N_BINOP, // [left] oper [right] + N_UNOP, // oper [arg] + N_CALL, // name [args] +}; + +enum operator { + // binary + OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, + OP_EQ, OP_NEQ, OP_LT, OP_GT, OP_LEQ, OP_GEQ, + OP_AND, OP_OR, + OP_ASSIGN, + // unary + OP_NEG, OP_NOT, OP_DEREF, OP_ADDROF, +}; + +struct node { + enum node_type type; + struct node *child1, *child2, *child3; + struct type *rtype; + char *name; + int value; + enum operator oper; +}; + + +struct node* node_make_0(enum node_type type); +struct node* node_make_1(enum node_type type, struct node *c1); +struct node* node_make_2(enum node_type type, struct node *c1, struct node *c2); +struct node* node_make_3(enum node_type type, struct node *c1, struct node *c2, struct node *c3); + +__attribute__((sentinel)) +struct node* node_make_list_(struct node *first, ...); +#define node_make_list(...) node_make_list_(__VA_ARGS__, NULL) + +int node_list_length(struct node *node); + +void node_delete_recursive(struct node *node); + +void node_print(const struct node *node, FILE *f, int indent); -- cgit v1.2.3-54-g00ecf