-
Notifications
You must be signed in to change notification settings - Fork 1
/
slp.c
60 lines (47 loc) · 1.36 KB
/
slp.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "util.h"
#include "slp.h"
A_stm A_CompoundStm(A_stm stm1, A_stm stm2) {
A_stm s = checked_malloc(sizeof *s);
s->kind=A_compoundStm; s->u.compound.stm1=stm1; s->u.compound.stm2=stm2;
return s;
}
A_stm A_AssignStm(string id, A_exp exp) {
A_stm s = checked_malloc(sizeof *s);
s->kind=A_assignStm; s->u.assign.id=id; s->u.assign.exp=exp;
return s;
}
A_stm A_PrintStm(A_expList exps) {
A_stm s = checked_malloc(sizeof *s);
s->kind=A_printStm; s->u.print.exps=exps;
return s;
}
A_exp A_IdExp(string id) {
A_exp e = checked_malloc(sizeof *e);
e->kind=A_idExp; e->u.id=id;
return e;
}
A_exp A_NumExp(int num) {
A_exp e = checked_malloc(sizeof *e);
e->kind=A_numExp; e->u.num=num;
return e;
}
A_exp A_OpExp(A_exp left, A_binop oper, A_exp right) {
A_exp e = checked_malloc(sizeof *e);
e->kind=A_opExp; e->u.op.left=left; e->u.op.oper=oper; e->u.op.right=right;
return e;
}
A_exp A_EseqExp(A_stm stm, A_exp exp) {
A_exp e = checked_malloc(sizeof *e);
e->kind=A_eseqExp; e->u.eseq.stm=stm; e->u.eseq.exp=exp;
return e;
}
A_expList A_PairExpList(A_exp head, A_expList tail) {
A_expList e = checked_malloc(sizeof *e);
e->kind=A_pairExpList; e->u.pair.head=head; e->u.pair.tail=tail;
return e;
}
A_expList A_LastExpList(A_exp last) {
A_expList e = checked_malloc(sizeof *e);
e->kind=A_lastExpList; e->u.last=last;
return e;
}