/* 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);