55import org .junit .jupiter .api .Test ;
66import simpleequations .SimpleEquationsMill ;
77import simpleequations ._ast .ASTProgramBlock ;
8+ import simpleequations ._ast .ASTSimpleEquationCompilationUnit ;
89import simpleequations ._parser .SimpleEquationsParser ;
910import simpleequations ._symboltable .SimpleEquationsScopesGenitorDelegator ;
1011
@@ -22,30 +23,33 @@ public void test() throws IOException {
2223 SimpleEquationsInterpreter interpreter = new SimpleEquationsInterpreter ();
2324 SimpleEquationsScopesGenitorDelegator delegator = SimpleEquationsMill .scopesGenitorDelegator ();
2425
25- ASTProgramBlock program = parser .parse_StringProgramBlock ("" +
26- "int a = 3; " +
27- "int b = 3; " +
28- "int func func1(int a, int b){ " +
29- " int c = a; " +
30- " if( b > 0 ){ " +
31- " b = b - 1; " +
32- " a = a;" +
33- " c = a * 3; " +
34- " int d = func1(c, b);" +
35- " return d;" +
36- " } else { " +
37- " return a;" +
38- " };" +
39- "}" +
40- "int result = func1(a, b);" +
41- "print(result);" ).get ();
26+ ASTSimpleEquationCompilationUnit program = parser .parse_StringSimpleEquationCompilationUnit ("" +
27+ "Program {" +
28+ " int a = 3; " +
29+ " int b = 3; " +
30+ " int func func1(int a, int b){ " +
31+ " int c = a; " +
32+ " if( b > 0 ){ " +
33+ " b = b - 1; " +
34+ " a = a;" +
35+ " c = a * 3; " +
36+ " int d = func1(c, b);" +
37+ " return d;" +
38+ " } else { " +
39+ " return a;" +
40+ " };" +
41+ " }" +
42+ " int result = func1(a, b);" +
43+ " print(result);" +
44+ "}" ).get ();
4245 delegator .createFromAST (program );
4346 MIValue functionResult = interpreter .interpret (program );
4447 assertTrue (functionResult .isInt ());
4548 assertEquals (81 , functionResult .asInt ());
4649
4750 //test recursive method definition
48- //program = parser.parse_StringProgramBlock("" +
51+ //program = parser.parse_StringSimpleEquationCompilationUnit("" +
52+ // "Program {" +
4953 // "int a = 3;" +
5054 // "int b = 3;" +
5155 // "int func func1(int a, int b){" +
@@ -57,14 +61,22 @@ public void test() throws IOException {
5761 // " return func1(a,b);" +
5862 // "};" +
5963 // "int result = func1(a,b); " +
60- // "print(result);").get();
64+ // "print(result);"
65+ // "}").get();
6166 //delegator.createFromAST(program);
6267 //MIValue recursiveResult = interpreter.interpret(program);
6368 //assertTrue(recursiveResult.isInt());
6469 //assertEquals(18, recursiveResult.asInt() );
6570
6671
67- program = parser .parse_StringProgramBlock ("var a=3.5; var b=4; print(a); var c=a+b; c;" ).get ();
72+ program = parser .parse_StringSimpleEquationCompilationUnit ("" +
73+ "Program {" +
74+ " var a=3.5; " +
75+ " var b=4; " +
76+ " print(a); " +
77+ " var c=a+b; " +
78+ " c;" +
79+ "}" ).get ();
6880
6981 delegator .createFromAST (program );
7082 MIValue result = interpreter .interpret (program );
@@ -75,10 +87,12 @@ public void test() throws IOException {
7587 SimpleEquationsMill .reset ();
7688 SimpleEquationsMill .init ();
7789 interpreter = new SimpleEquationsInterpreter ();
78- program = parser .parse_StringProgramBlock (
79- "var a = 40; " +
80- "a = 45;" +
81- "a;" ).get ();
90+ program = parser .parse_StringSimpleEquationCompilationUnit (
91+ "Program {" +
92+ " var a = 40; " +
93+ " a = 45;" +
94+ " a;" +
95+ "}" ).get ();
8296
8397 delegator .createFromAST (program );
8498 result = interpreter .interpret (program );
0 commit comments