-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.c
35 lines (28 loc) · 1006 Bytes
/
tree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "defs.h"
#include "data.h"
#include "decl.h"
struct ASTnode *mkastnode(int op, int type,
struct ASTnode *left, struct ASTnode *mid, struct ASTnode *right,
struct symtable *sym, int intvalue) {
struct ASTnode *node;
node = (struct ASTnode *)malloc(sizeof(struct ASTnode));
if (node == NULL)
fatal("unable to malloc a ASTnode in mkastnode()");
node->op = op;
node->type = type;
node->rvalue = 0;
node->left = left;
node->mid = mid;
node->right = right;
node->sym = sym;
node->intvalue = intvalue;
return (node);
}
struct ASTnode *mkastleaf(int op, int type,
struct symtable *sym, int intvalue) {
return (mkastnode(op, type, NULL, NULL, NULL, sym, intvalue));
}
struct ASTnode *mkastunary(int op, int type, struct ASTnode *left,
struct symtable *sym, int intvalue) {
return (mkastnode(op, type, left, NULL, NULL, sym, intvalue));
}