Beispiel #1
0
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")))
    );
}
Beispiel #2
0
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")))));

}
Beispiel #3
0
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")))));
}
Beispiel #4
0
static void test_maxargs_deep_nested(void** state) {
    // maxargs(stm) can work with deeply nested statements
    A_stm stm = A_CompoundStm(
        A_AssignStm("a", A_NumExp(0)),
        A_CompoundStm(
            A_PrintStm(A_PairExpList(
                A_NumExp(7),
                A_LastExpList(A_NumExp(42))
            )),
            A_AssignStm("a", A_NumExp(5))
        )
    );
    assert_int_equal(2, maxargs(stm));
}
Beispiel #5
0
static void test_maxargs_nested(void** state) {
    // maxargs(stm) can work with nested statements
    A_stm stm = A_CompoundStm(
        A_PrintStm(A_LastExpList(A_NumExp(7))),
        A_AssignStm("a", A_NumExp(7))
    );
    assert_int_equal(1, maxargs(stm));
}
Beispiel #6
0
A_stm error_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 = c;
     A_stm stm1 = prog_prog();
     return 
	 	A_CompoundStm( stm1, A_AssignStm("a", A_IdExp("c")));
 
}
Beispiel #7
0
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"))));
 
}
Beispiel #8
0
static void test_maxargs_multiple(void** state) {
    // maxargs(stm) works with multiple 'A_printStm's
    A_stm stm = A_CompoundStm(
        A_PrintStm(A_PairExpList(
            A_NumExp(7),
            A_LastExpList(A_NumExp(9))
        )),
        A_PrintStm(A_LastExpList(A_NumExp(8)))
    );

    assert_int_equal(2, maxargs(stm));
}
Beispiel #9
0
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));
}