diff options
Diffstat (limited to 'src/A.c')
-rw-r--r-- | src/A.c | 88 |
1 files changed, 88 insertions, 0 deletions
@@ -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 */ | ||
9 | A_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 */ | ||
18 | A_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 */ | ||
27 | A_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 */ | ||
35 | A_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 */ | ||
43 | A_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 */ | ||
51 | A_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 */ | ||
61 | A_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 */ | ||
70 | A_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 */ | ||
79 | A_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 | |||
86 | int main (int argc, char** argv) { | ||
87 | return 0; | ||
88 | } | ||