### Abstract Tree ###################### import jex.Test; Test.method(); Test.method(Test.arg1(), Test.arg2(), Test.arg3()); Test.header("Literals"); Test.literalFalse(false); Test.literalTrue(true); Test.literal42(42); Test.literalHello("Hello"); Test.header("Field access"); Test.test("Field access (get)", 37, Test.field); Test.field = 29; Test.test("Field access (set)", 29, Test.field); Test.header("Arithmetic operators"); Test.test("11 + 31", 42, (11+31)); Test.test("59 - 17", 42, (59-17)); Test.test("6 * 7 ", 42, (6*7)); Test.test("84 / 2 ", 42, (84/2)); Test.header("Comparison operators"); Test.test("13 < 17", true, (13<17)); Test.test("17 < 17", false, (17<17)); Test.test("13 > 17", false, (13>17)); Test.test("13 > 13", false, (13>13)); Test.test("13 <= 13", true, (13<=13)); Test.test("13 <= 17", true, (13<=17)); Test.test("17 >= 17", true, (17>=17)); Test.test("13 >= 17", false, (13>=17)); Test.header("Equality operators"); Test.test("true == false", false, (true==false)); Test.test("true != false", true, (true!=false)); Test.println(); Test.test("13 == 17", false, (13==17)); Test.test("13 != 17", true, (13!=17)); Test.println(); Test.test(Test.HELLO_EQ_BYE, false, ("Hello"=="Bye")); Test.test(Test.HELLO_NE_BYE, true, ("Hello"!="Bye")); Test.println(); Test.header("Operator precedence"); Test.test("17 + 5 * 5 ", 42, (17+(5*5))); Test.test("17 + 5 * 5 == 42", true, ((17+(5*5))==42)); Test.test(" 5 * 5 + 17", 42, ((5*5)+17)); Test.test("42 == 5 * 5 + 17", true, (42==((5*5)+17))); Test.header("Constructor call"); new Test(Test.ARG1, Test.ARG2, Test.ARG3); Test.test("new Test().toString()", "a Test instance", new Test().toString()); Test.header("Variable access"); int i; i = 7; Test.test("int i; i = 7; => i", 7, i); Test.header("Block"); i = 0; { i = (i+1); i = (i+2); i = (i+5); } Test.test("i = 0; {i = i + 1; i = i + 2; i = i + 5;} => i", 8, i); Test.header("While"); i = 0; while ((i<3)) i = (i+1); Test.test("i = 0; while (i < 3) i = i + 1; => i", 3, i); Test.header("If"); i = 0; if (true) i = 1; else i = 2; Test.test("i = 0; if (true ) i = 1; else i = 2; => i", 1, i); i = 0; if (false) i = 1; else i = 2; Test.test("i = 0; if (false) i = 1; else i = 2; => i", 2, i); i = 0; if (true) i = 1; Test.test("i = 0; if (true ) i = 1; => i", 1, i); i = 0; if (false) i = 1; Test.test("i = 0; if (false) i = 1; => i", 0, i); i = 0; if (true) if (false) i = 1; else i = 2; Test.test("i = 0; if (true ) if (false) i = 1; else i = 2; => i", 2, i); Test.header("Return"); i = 0; return 1; i = 2; Test.test("i = 0; return 1; i = 2; => i", 2, i); i = 0; { i = 1; return 2; i = 3; } Test.test("i = 0; {i = 1; return 2; i = 3} => i", 1, i); i = 0; while ((i<3)) { i = (i+1); return 5; } Test.test("i = 0; while (i < 3) {i = i + 1; return 5;} => i", 1, i); Test.header("Function call"); Test.println("int f(int arg1, int arg2, int arg3) return arg1 + arg2 + arg3;"); Test.println("int result; result = f(2,3,4);"); int f(int arg1, int arg2, int arg3) { Test.test("Function call: arg1 ", 2, arg1); Test.test("Function call: arg2 ", 3, arg2); Test.test("Function call: arg3 ", 4, arg3); return ((arg1+arg2)+arg3); } int result; result = f(2, 3, 4); Test.test("Function call: result", 9, result); Test.println(); i = 0; int f1() { i = 1; return 2; } f1(); Test.test("i = 0; int f1() {i = 1; return 2;} f1(); => i", 1, i); i = 0; int f2() { i = 1; return 2; } i = 3; f2(); Test.test("i = 0; int f2() {i = 1; return 2;} i = 3; f2(); => i", 1, i); i = 0; int f3(int i) { i = 1; return 2; } f3(3); Test.test("i = 0; int f3(int i) {i = 1; return 2;} f3(3); => i", 0, i); i = 0; int f4(int j) { i = j; return 2; } f4(3); Test.test("i = 0; int f4(int j) {i = j; return 2;} f4(3); => i", 3, i); Test.println(); ### Analyzer messages ################## ### Interpretation output ############## **************************************** * Method call Method call without parameter -> ok Method call with parameters -> ok **************************************** * Literals literal false = false -> ok literal true = true -> ok literal 42 = 42 -> ok literal "Hello" = "Hello" -> ok **************************************** * Field access Field access (get) = 37 -> ok Field access (set) = 29 -> ok **************************************** * Arithmetic operators 11 + 31 = 42 -> ok 59 - 17 = 42 -> ok 6 * 7 = 42 -> ok 84 / 2 = 42 -> ok **************************************** * Comparison operators 13 < 17 = true -> ok 17 < 17 = false -> ok 13 > 17 = false -> ok 13 > 13 = false -> ok 13 <= 13 = true -> ok 13 <= 17 = true -> ok 17 >= 17 = true -> ok 13 >= 17 = false -> ok **************************************** * Equality operators true == false = false -> ok true != false = true -> ok 13 == 17 = false -> ok 13 != 17 = true -> ok "Hello" == "Bye" = false -> ok "Hello" != "Bye" = true -> ok **************************************** * Operator precedence 17 + 5 * 5 = 42 -> ok 17 + 5 * 5 == 42 = true -> ok 5 * 5 + 17 = 42 -> ok 42 == 5 * 5 + 17 = true -> ok **************************************** * Constructor call Constructor call -> ok new Test().toString() = "a Test instance" -> ok **************************************** * Variable access int i; i = 7; => i = 7 -> ok **************************************** * Block i = 0; {i = i + 1; i = i + 2; i = i + 5;} => i = 8 -> ok **************************************** * While i = 0; while (i < 3) i = i + 1; => i = 3 -> ok **************************************** * If i = 0; if (true ) i = 1; else i = 2; => i = 1 -> ok i = 0; if (false) i = 1; else i = 2; => i = 2 -> ok i = 0; if (true ) i = 1; => i = 1 -> ok i = 0; if (false) i = 1; => i = 0 -> ok i = 0; if (true ) if (false) i = 1; else i = 2; => i = 2 -> ok **************************************** * Return i = 0; return 1; i = 2; => i = 2 -> ok i = 0; {i = 1; return 2; i = 3} => i = 1 -> ok i = 0; while (i < 3) {i = i + 1; return 5;} => i = 1 -> ok **************************************** * Function call int f(int arg1, int arg2, int arg3) return arg1 + arg2 + arg3; int result; result = f(2,3,4); Function call: arg1 = 2 -> ok Function call: arg2 = 3 -> ok Function call: arg3 = 4 -> ok Function call: result = 9 -> ok i = 0; int f1() {i = 1; return 2;} f1(); => i = 1 -> ok i = 0; int f2() {i = 1; return 2;} i = 3; f2(); => i = 1 -> ok i = 0; int f3(int i) {i = 1; return 2;} f3(3); => i = 0 -> ok i = 0; int f4(int j) {i = j; return 2;} f4(3); => i = 3 -> ok