summaryrefslogtreecommitdiff
path: root/src/A.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/A.c')
-rw-r--r--src/A.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/A.c b/src/A.c
new file mode 100644
index 0000000..751de8c
--- /dev/null
+++ b/src/A.c
@@ -0,0 +1,88 @@
1# include <stdlib.h>
2# include "A.h"
3
4/*
5 * node constructor functions
6 */
7
8/* A_CompoundStm - returns a compound statement of stm1, stm2 */
9A_stm A_CompoundStm (A_stm stm1, A_stm stm2) {
10 A_stm s = malloc(sizeof(*s));
11 s->type = A_compoundStm;
12 s->u.compound.stm1 = stm1;
13 s->u.compound.stm2 = stm2;
14 return s;
15}
16
17/* A_AssignStm - returns a assign statement of id, exp */
18A_stm A_AssignStm (char *id, A_exp exp) {
19 A_stm s = malloc(sizeof(*s));
20 s->type = A_assignStm;
21 s->u.assign.id = id;
22 s->u.assign.exp = exp;
23 return s;
24}
25
26/* A_PrintStm - returns a print statement of exps */
27A_stm A_PrintStm (A_expList exps) {
28 A_stm s = malloc(sizeof(*s));
29 s->type = A_printStm;
30 s->u.print.exps = exps;
31 return s;
32}
33
34/* A_IdExp - returns an id expression of id */
35A_exp A_IdExp (char *id) {
36 A_exp e = malloc(sizeof(*e));
37 e->type = A_idExp;
38 e->u.id = id;
39 return e;
40}
41
42/* A_NumExp - returns a number expression of num */
43A_exp A_NumExp (int num) {
44 A_exp e = malloc(sizeof(*e));
45 e->type = A_numExp;
46 e->u.num = num;
47 return e;
48}
49
50/* A_OpExp - returns an operation expression of exp1, op, exp2 */
51A_exp A_OpExp (A_exp exp1, A_binop op, A_exp exp2) {
52 A_exp e = malloc(sizeof(*e));
53 e->type = A_opExp;
54 e->u.op.exp1 = exp1;
55 e->u.op.op = op;
56 e->u.op.exp2 = exp2;
57 return e;
58}
59
60/* A_EseqExp - returns a seqeunce expression of stm, exp */
61A_exp A_EseqExp (A_stm stm, A_exp exp) {
62 A_exp e = malloc(sizeof(*e));
63 e->type = A_eseqExp;
64 e->u.eseq.stm = stm;
65 e->u.eseq.exp = exp;
66 return e;
67}
68
69/* A_PairExpList - returns a list expression pair of head, tail */
70A_expList A_PairExpList (A_exp head, A_expList tail) {
71 A_expList l = malloc(sizeof(*l));
72 l->type = A_pairExpList;
73 l->u.pair.head = head;
74 l->u.pair.tail = tail;
75 return l;
76}
77
78/* A_LastExpList - returns a expression list end of last */
79A_expList A_LastExpList (A_exp last) {
80 A_expList l = malloc(sizeof(*l));
81 l->type = A_lastExpList;
82 l->u.last = last;
83 return l;
84}
85
86int main (int argc, char** argv) {
87 return 0;
88}