diff options
Diffstat (limited to 'include/A.h')
| -rw-r--r-- | include/A.h | 55 |
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 */ | ||
| 2 | typedef struct A_stm_ *A_stm; | ||
| 3 | typedef struct A_exp_ *A_exp; | ||
| 4 | typedef struct A_expList_ *A_expList; | ||
| 5 | |||
| 6 | /* binary operation */ | ||
| 7 | typedef enum { A_plus, A_minus, A_times, A_div } A_binop; | ||
| 8 | |||
| 9 | /* statement */ | ||
| 10 | struct 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 */ | ||
| 21 | A_stm A_CompoundStm ( A_stm stm1, A_stm stm2 ); | ||
| 22 | A_stm A_AssignStm ( char *id, A_exp exp ); | ||
| 23 | A_stm A_PrintStm ( A_expList exps ); | ||
| 24 | |||
| 25 | /* expression */ | ||
| 26 | struct 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 */ | ||
| 38 | A_exp A_IdExp ( char *id ); | ||
| 39 | A_exp A_NumExp ( int num ); | ||
| 40 | A_exp A_OpExp ( A_exp exp1, A_binop op, A_exp exp2 ); | ||
| 41 | A_exp A_EseqExp ( A_stm stm, A_exp exp ); | ||
| 42 | |||
| 43 | /* expression list */ | ||
| 44 | struct 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 */ | ||
| 54 | A_expList A_PairExpList (A_exp head, A_expList tail); | ||
| 55 | A_expList A_LastExplist (A_exp last); | ||
