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
|
/* types, of pointers to corresponding structs */
typedef struct A_stm_ *A_stm;
typedef struct A_exp_ *A_exp;
typedef struct A_expList_ *A_expList;
/* binary operation */
typedef enum { A_plus, A_minus, A_times, A_div } A_binop;
/* statement */
struct A_stm_ {
/* types: compound, assign, print */
enum { A_compoundStm, A_assignStm, A_printStm } type;
union {
struct { A_stm stm1, stm2; } compound;
struct { char *id; A_exp exp; } assign;
struct { A_expList exps; } print;
} u;
};
/* statement constrctor functions */
A_stm A_CompoundStm ( A_stm stm1, A_stm stm2 );
A_stm A_AssignStm ( char *id, A_exp exp );
A_stm A_PrintStm ( A_expList exps );
/* expression */
struct A_exp_ {
/* types: id, number, operation, sequence */
enum { A_idExp, A_numExp, A_opExp, A_eseqExp } type;
union {
char *id;
int num;
struct { A_exp exp1; A_binop op; A_exp exp2; } op;
struct { A_stm stm; A_exp exp; } eseq;
} u;
};
/* expression constructor functions */
A_exp A_IdExp ( char *id );
A_exp A_NumExp ( int num );
A_exp A_OpExp ( A_exp exp1, A_binop op, A_exp exp2 );
A_exp A_EseqExp ( A_stm stm, A_exp exp );
/* expression list */
struct A_expList_ {
/* types: pair, last */
enum { A_pairExpList, A_lastExpList } type;
union {
struct { A_exp head; A_expList tail; } pair;
A_exp last;
} u;
};
/* expression list constructor functions */
A_expList A_PairExpList (A_exp head, A_expList tail);
A_expList A_LastExplist (A_exp last);
|