------------------------------- -- CISC 672 -- -- programming assignment 1 -- -- author: Timo Koetzing -- ------------------------------- -- The program: the full table of the precedence constraints given in the manual -- at 11.1 (page 14) is tested. Every test has to return "true" in order for the -- precedence to be correctly implemented - or, as in most cases, be compiled at all -- The following is the setup for the precedence . to @: -- if it compiles, the precedence is correct class A { foo() : Bool { true }; }; class B inherits A { foo() : Bool { false }; bar() : B { new B }; test() : Bool { self.bar()@A.foo() }; }; ----------------------------------- -- The following tests ~ against @ and . (has to compile) -- both are checked, as transitivity doesn't apply on not-compiling class C { foo() : Int { 5 }; }; class D inherits C { foo() : Int { 4 }; test1() : Bool { ~self@C.foo() = ~5 }; test2() : Bool { ~(new D).foo() = ~4 }; }; ------------------------------------ -- The following tests isvoid against ~ (has to compile - well, it's a little strange with two unaries) class E { test() : Bool { not isvoid ~ 2 }; }; ------------------------------------ -- The following tests * and / against ~ (against isvoid makes no sense) class F { test1() : Bool { ~ 5 * 2 = (~5) * 2 }; test2() : Bool { ~ 5 / 2 = (~5) / 2 }; }; ------------------------------------ -- The following tests * and / against + and - class G { test1() : Bool { 5 * 2 + 7 = 17 }; test2() : Bool { 10 / 2 - 1 = 4 }; }; ------------------------------------ -- The following tests the comparatives against + and - (well, it basically has to compile, as types would mismatch otherwise) class H { test1() : Bool { 5 - 4 <= 1 }; test2() : Bool { 2 < 1 + 3 }; test3() : Bool { 4 - 2 = 1 + 1 }; }; ------------------------------------ -- The following tests "not" against <=, <, = (has to compile) class I { test1() : Bool { not 3 < 3 }; test2() : Bool { not 3 <= 2 }; test3() : Bool { not 1 = 3 }; }; ------------------------------------ -- The following tests <- against "not" (has to compile) class J { b : Bool; test() : Bool { { b <- not false; b; } }; }; ------------------------------------ -- The main class executes all tests class Main { myIO : IO <- new IO; main() : Int { { if (new B).test() then myIO.out_string(" 1: True.\n") else myIO.out_string(" 1: False.\n") fi; if (new D).test1() then myIO.out_string(" 2: True.\n") else myIO.out_string(" 2: False.\n") fi; if (new D).test2() then myIO.out_string(" 3: True.\n") else myIO.out_string(" 3: False.\n") fi; if (new E).test() then myIO.out_string(" 4: True.\n") else myIO.out_string(" 4: False.\n") fi; if (new F).test1() then myIO.out_string(" 5: True.\n") else myIO.out_string(" 5: False.\n") fi; if (new F).test2() then myIO.out_string(" 6: True.\n") else myIO.out_string(" 6: False.\n") fi; if (new G).test1() then myIO.out_string(" 7: True.\n") else myIO.out_string(" 7: False.\n") fi; if (new G).test2() then myIO.out_string(" 8: True.\n") else myIO.out_string(" 8: False.\n") fi; if (new H).test1() then myIO.out_string(" 9: True.\n") else myIO.out_string(" 9: False.\n") fi; if (new H).test2() then myIO.out_string("10: True.\n") else myIO.out_string("10: False.\n") fi; if (new H).test3() then myIO.out_string("11: True.\n") else myIO.out_string("11: False.\n") fi; if (new I).test1() then myIO.out_string("12: True.\n") else myIO.out_string("12: False.\n") fi; if (new I).test2() then myIO.out_string("13: True.\n") else myIO.out_string("13: False.\n") fi; if (new I).test3() then myIO.out_string("14: True.\n") else myIO.out_string("14: False.\n") fi; if (new J).test() then myIO.out_string("15: True.\n") else myIO.out_string("15: False.\n") fi; 1; } }; };