summaryrefslogtreecommitdiff
path: root/include/A.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/A.h')
-rw-r--r--include/A.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/include/A.h b/include/A.h
new file mode 100644
index 0000000..9c2db23
--- /dev/null
+++ b/include/A.h
@@ -0,0 +1,55 @@
1/* types, of pointers to corresponding structs */
2typedef struct A_stm_ *A_stm;
3typedef struct A_exp_ *A_exp;
4typedef struct A_expList_ *A_expList;
5
6/* binary operation */
7typedef enum { A_plus, A_minus, A_times, A_div } A_binop;
8
9/* statement */
10struct A_stm_ {
11 /* types: compound, assign, print */
12 enum { A_compoundStm, A_assignStm, A_printStm } type;
13 union {
14 struct { A_stm stm1, stm2; } compound;
15 struct { char *id; A_exp exp; } assign;
16 struct { A_expList exps; } print;
17 } u;
18};
19
20/* statement constrctor functions */
21A_stm A_CompoundStm ( A_stm stm1, A_stm stm2 );
22A_stm A_AssignStm ( char *id, A_exp exp );
23A_stm A_PrintStm ( A_expList exps );
24
25/* expression */
26struct A_exp_ {
27 /* types: id, number, operation, sequence */
28 enum { A_idExp, A_numExp, A_opExp, A_eseqExp } type;
29 union {
30 char *id;
31 int num;
32 struct { A_exp exp1; A_binop op; A_exp exp2; } op;
33 struct { A_stm stm; A_exp exp; } eseq;
34 } u;
35};
36
37/* expression constructor functions */
38A_exp A_IdExp ( char *id );
39A_exp A_NumExp ( int num );
40A_exp A_OpExp ( A_exp exp1, A_binop op, A_exp exp2 );
41A_exp A_EseqExp ( A_stm stm, A_exp exp );
42
43/* expression list */
44struct A_expList_ {
45 /* types: pair, last */
46 enum { A_pairExpList, A_lastExpList } type;
47 union {
48 struct { A_exp head; A_expList tail; } pair;
49 A_exp last;
50 } u;
51};
52
53/* expression list constructor functions */
54A_expList A_PairExpList (A_exp head, A_expList tail);
55A_expList A_LastExplist (A_exp last);