summaryrefslogtreecommitdiff
path: root/src/A.c
blob: 751de8cb1cfde4495195a9a6b3a16f306ec15230 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# include <stdlib.h>
# include "A.h"

/*
 *	node constructor functions
 */

/* A_CompoundStm - returns a compound statement of stm1, stm2 */
A_stm A_CompoundStm (A_stm stm1, A_stm stm2) {
	A_stm s				= malloc(sizeof(*s));
	s->type				= A_compoundStm;
	s->u.compound.stm1	= stm1;
	s->u.compound.stm2	= stm2;
	return s;
}

/* A_AssignStm - returns a assign statement of id, exp */
A_stm A_AssignStm (char *id, A_exp exp) {
	A_stm s			= malloc(sizeof(*s));
	s->type			= A_assignStm;
	s->u.assign.id	= id;
	s->u.assign.exp	= exp;
	return s;
}

/* A_PrintStm - returns a print statement of exps */
A_stm A_PrintStm (A_expList exps) {
	A_stm s			= malloc(sizeof(*s));
	s->type			= A_printStm;
	s->u.print.exps	= exps;
	return s;
}

/* A_IdExp - returns an id expression of id */
A_exp A_IdExp (char *id) {
	A_exp e = malloc(sizeof(*e));
	e->type = A_idExp;
	e->u.id = id;
	return e;
}

/* A_NumExp - returns a number expression of num */
A_exp A_NumExp (int num) {
	A_exp e		= malloc(sizeof(*e));
	e->type		= A_numExp;
	e->u.num	= num;
	return e;
}

/* A_OpExp - returns an operation expression of exp1, op, exp2 */
A_exp A_OpExp (A_exp exp1, A_binop op, A_exp exp2) {
	A_exp e			= malloc(sizeof(*e));
	e->type			= A_opExp;
	e->u.op.exp1	= exp1;
	e->u.op.op		= op;
	e->u.op.exp2	= exp2;
	return e;
}

/* A_EseqExp - returns a seqeunce expression of stm, exp */
A_exp A_EseqExp (A_stm stm, A_exp exp) {
	A_exp e			= malloc(sizeof(*e));
	e->type			= A_eseqExp;
	e->u.eseq.stm	= stm;
	e->u.eseq.exp	= exp;
	return e;
}

/* A_PairExpList - returns a list expression pair of head, tail */
A_expList A_PairExpList (A_exp head, A_expList tail) {
	A_expList l		= malloc(sizeof(*l));
	l->type			= A_pairExpList;
	l->u.pair.head	= head;
	l->u.pair.tail	= tail;
	return l;
}

/* A_LastExpList - returns a expression list end of last */
A_expList A_LastExpList (A_exp last) {
	A_expList l	= malloc(sizeof(*l));
	l->type		= A_lastExpList;
	l->u.last	= last;
	return l;
}

int main (int argc, char** argv) {
	return 0;
}