A_stm prog3(void) { return A_CompoundStm( A_PrintStm(A_PairExpList( A_EseqExp( A_CompoundStm( A_PrintStm(A_PairExpList( A_EseqExp( A_AssignStm( "a", A_NumExp(1) ), A_IdExp("a") ), A_LastExpList(A_NumExp(3)) )), A_AssignStm( "b", A_NumExp(2) ) ), A_IdExp("a") ), A_LastExpList(A_IdExp("a")) )), A_PrintStm(A_LastExpList(A_IdExp("b"))) ); }
/* print (1,2,3,(print(1,2,3,4), 6)) */ A_stm prog2(void) { return A_PrintStm( A_PairExpList( A_NumExp(1), A_PairExpList( A_NumExp(2), A_PairExpList( A_NumExp(3), A_LastExpList( A_EseqExp( A_PrintStm( A_PairExpList( A_NumExp(1), A_PairExpList( A_NumExp(2), A_PairExpList( A_NumExp(3), A_LastExpList(A_NumExp(4)) ) ) ) ), A_NumExp(6) ) ) ) ) ) ); }
void test_maxargs_exp_op_nested(void** state) { A_stm stm = A_PrintStm(A_LastExpList(A_OpExp( A_OpExp( A_OpExp( A_EseqExp( A_PrintStm(A_PairExpList( A_NumExp(7), A_PairExpList( A_NumExp(8), A_LastExpList(A_NumExp(9)) ) )), A_NumExp(14) ), A_plus, A_NumExp(5) ), A_times, A_NumExp(19) ), A_minus, A_NumExp(42) ))); assert_int_equal(3, maxargs(stm)); }
static void test_maxargs_eseq_nested(void** state) { A_stm stm = A_PrintStm(A_LastExpList( A_EseqExp( A_PrintStm(A_LastExpList(A_NumExp(42))), A_EseqExp( A_PrintStm(A_PairExpList( A_NumExp(8), A_PairExpList( A_NumExp(9), A_LastExpList(A_NumExp(10)) ) )), A_NumExp(7) ) ) )); assert_int_equal(3, maxargs(stm)); }
A_stm prog1(void) { //return A_AssignStm("a", A_OpExp(A_NumExp(5),A_plus, A_NumExp(3))); return A_CompoundStm(A_AssignStm("a", A_OpExp(A_NumExp(5),A_plus, A_NumExp(3))), A_CompoundStm(A_AssignStm("b", A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"), A_LastExpList(A_OpExp(A_IdExp("a"), A_minus, A_NumExp(1))))), A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))), A_PrintStm(A_LastExpList(A_IdExp("b"))))); }
A_stm right_prog(void) { // a = 5 + 3; b = (print(a, a-1), 10*a); print b; // a = 5 + b; b = (print(a, a, a-1), 10*a); print b; // a = (a = a+b, a); A_stm stm1 = prog_prog(); return A_CompoundStm( stm1, A_AssignStm("a", A_EseqExp(A_AssignStm("a", A_OpExp(A_IdExp("a"), A_plus, A_IdExp("b"))), A_IdExp("a")))); }
A_stm prog(void) { // a = 5 + 3; b = (print(a, a-1), 10*a); print b; return A_CompoundStm(A_AssignStm("a", A_OpExp(A_NumExp(5), A_plus, A_NumExp(3))), A_CompoundStm(A_AssignStm("b", A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"), A_LastExpList(A_OpExp(A_IdExp("a"), A_minus, A_NumExp(1))))), A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))), A_PrintStm(A_LastExpList(A_IdExp("b"))))); }
static void test_maxargs_assign(void** state) { // maxargs(stm) works with prints within assignments A_stm stm = A_AssignStm( "a", A_EseqExp( A_PrintStm(A_LastExpList(A_NumExp(7))), A_NumExp(42) ) ); assert_int_equal(1, maxargs(stm)); }
void test_maxargs_exp_op(void** state) { A_stm stm = A_PrintStm(A_LastExpList(A_OpExp( A_EseqExp( A_PrintStm(A_PairExpList( A_NumExp(8), A_LastExpList(A_NumExp(9)) )), A_NumExp(7) ), A_plus, A_NumExp(17) ))); assert_int_equal(2, maxargs(stm)); }
static void test_maxargs_print_nested(void** state) { // maxargs(stm) works with prints within prints A_stm stm = A_PrintStm(A_LastExpList( A_EseqExp( A_PrintStm( A_PairExpList( A_NumExp(7), A_LastExpList(A_NumExp(8)) ) ), A_NumExp(42) ) )); assert_int_equal(2, maxargs(stm)); }
static void test_maxargs_complex(void** state) { // maxargs(stm) works with an arbitrary complex statement A_stm stm = A_CompoundStm( A_AssignStm( "a", A_OpExp(A_NumExp(5), A_plus, A_NumExp(3)) ), A_CompoundStm( A_AssignStm("b", A_EseqExp( A_PrintStm(A_PairExpList( A_IdExp("a"), A_LastExpList( A_OpExp(A_IdExp("a"), A_minus, A_NumExp(1)) ) )), A_OpExp(A_NumExp(10), A_times, A_IdExp("a")) )), A_PrintStm(A_LastExpList(A_IdExp("b"))) ) ); assert_int_equal(2, maxargs(stm)); }