diff --git a/.classpath b/.classpath index 98e4377..646ce8c 100644 --- a/.classpath +++ b/.classpath @@ -2,9 +2,10 @@ + + - - + diff --git a/.project b/.project index 18eecfe..7f068ef 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - Javali-HW2 + Javali-HW3 diff --git a/.settings/com.github.jknack.antlr4ide.Antlr4.prefs b/.settings/com.github.jknack.antlr4ide.Antlr4.prefs deleted file mode 100644 index 67ef6b9..0000000 --- a/.settings/com.github.jknack.antlr4ide.Antlr4.prefs +++ /dev/null @@ -1,13 +0,0 @@ -antlr4.antlrRegisteredTools=4.4@/tmp/antlr-4.4-complete.jar\:4.7.1@/home/carlos/eth/cd/nop90/HW2/lib/antlr-4.7.1-complete.jar -antlr4.antlrToolPath=/home/carlos/eth/cd/nop90/HW2/lib/antlr-4.7.1-complete.jar -antlr4.encoding=UTF-8 -antlr4.listener=true -antlr4.visitor=false -antlr4.vmArgs= -antlr4ide.is_project_specific=true -autobuilding=true -eclipse.preferences.version=1 -is_project_specific= -outlet.DEFAULT_OUTPUT.cleanupDerived=true -outlet.DEFAULT_OUTPUT.derived=true -outlet.DEFAULT_OUTPUT.directory=./target/generated-sources/antlr4 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 0c68a61..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Grade.txt b/Grade.txt index 9d05b6d..4d76e06 100644 --- a/Grade.txt +++ b/Grade.txt @@ -1,5 +1,6 @@ -Grade: 29/30 +Grade: 25/25 -251/251 tests passed [25/25] +105/105 tests passed [20/20] + +Submitted test cases: [5/5] -Submitted test cases: [4/5] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b1ad73f --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Compiler design +## Parser and syntactic analysis +See repo containing [Homework #2](https://svn.inf.ethz.ch/svn/trg/cd_students/ss18/teams/nop90/HW2). + +## Semantic analysis +This project checks a list class declaration as trees of Ast nodes for +possible semantic errors. + +### Design +The semantic checks described [here](./SemanticChecks.md) are implemented in three +phases. + +1. Circular inheritance check (just with the names, and checking for non-existent +types) to avoid stack overflow problems in the main analysis. May throw a +`NO_SUCH_TYPE` error if the parent of a given class doesn't exist. +2. Main semantic analysis, performed by `StmtAnalyzer` and `ExprAnalyzer`, +two visitors that traverse each `ClassDecl` and all of its contents looking +for semantic errors. Some types and methods may not have been discovered +when they are accessed, and to that end the functions `findType(String)` +and `findMethod(String,ClassSymbol)` lookup both, searching unvisited class +and method declarations in order to find the corresponding symbol. +3. Lookup of start point (method `void main()` in `Main` class) + +### Testing +A set of test cases (Javali programs, valid and invalid) are provided. The ones +designed specifically for this homework assignment are located in +`javali_tests/HW3_nop90`, and they cover all the code in the `cd.frontend.semantic` +and `cd.ir` packages. They cover all the kinds of errors that can arise +from a semantic analysis of Javali programs. As the order of the errors +is not determined, each test case only checks one failing condition, and +therefore many more test cases are needed for this homework than for +previous ones. + +The test files are organized in folders, with names ending in Tests or Errors, +the latter only contain test cases that result in semantic errors. + +To run the tests that exist in the `javali_tests` folder you can simply run + + $ ant clean clean-test compile test + +### Development environment +This project is designed for Eclipse and GNU/Linux, but it can be run +in other environments, as long as they have a 32bit `IA 86x assembly` compiler +and a `JVM`. Check the `Config` class for more information. + +### Documentation +Available as [javadoc](javadoc/index.html). It is generated running the following command: + + $ ant clean-doc generate-doc + +### Important files +* `TODO.md`: contains tasks to complete +* `SemanticChecks.md`: contains the semantic checks numbered for quick reference +* [Javali Grammar](https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-cs/lst-dam/documents/Education/Classes/Spring2018/210_Compiler_Design/Homework/javali.pdf) +* [HW3 statement](https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-cs/lst-dam/documents/Education/Classes/Spring2018/210_Compiler_Design/Homework/hw3.pdf) \ No newline at end of file diff --git a/SemanticChecks.md b/SemanticChecks.md new file mode 100644 index 0000000..ba0401f --- /dev/null +++ b/SemanticChecks.md @@ -0,0 +1,43 @@ +# Class and method declaration errors +1. All programs must have a method main() with void return type in the class Main (`INVALID_START_POINT`) +2. The superclass of each class exists (`NO_SUCH_TYPE`) +3. There is no circular inheritance (`CIRCULAR_INHERITANCE`) +4. No class is declared with the name `Object` (`OBJECT_CLASS_DEFINED`) +5. Unique names (`DOUBLE_DECLARATION`) for each group: + 1. Class names + 2. Field names in a single class (field shadowing is allowed) + 3. Method names in a single class (Override is allowed, overloading not) + 4. Method parameters and local variable names +6. Overridden methods must: (`INVALID_OVERRIDE`) + 1. Have the same number of parameters + 2. The return types must match + 3. The type of the parameters must match (name can differ) + +# Method body errors +1. `write()` must take one argument of type `int` (`TYPE_ERROR`) +2. `read()` and `writeln()` must take no arguments (`WRONG_NUMBER_OF_ARGUMENTS`) +3. The condition of a `while` or `if` statement must be typed `booelan` (`TYPE_ERROR`) +4. Assignments: the type of the right-hand side must be a suptype of the type of the left-hand side. (`TYPE_ERROR`) +5. Operators (`TYPE_ERROR`): + 1. `*`, `/`, `%`, `+`, `-`, `<`, `>`, `<=`, `>=` take `int` arguments only. + 2. `!`, `&&`, `||` take `boolean` arguments only. + 3. `==` and `!=` takes any couple of arguments as long as one of the types is a subtype of the other. + 4. A cast is only possible if one of the types is a subtype of the other +6. Method invocation, must match with declaration: + 1. The number of parameters (`WRONG_NUMBER_OF_ARGUMENTS`) + 2. The type of each of the parameters (`TYPE_ERROR`) +7. Arrays: + 1. When indexing, the index expression must be an `int` (`TYPE_ERROR`) + 2. When creating one, the index expression must be an `int` (`TYPE_ERROR`) +8. The constant `null` can be assigned to any reference type. +9. The type name in a `new` statement must exist (`NO_SUCH_TYPE`) +10. The left-hand side of an assignment can only be: (`NOT_ASSIGNABLE`) + 1. A variable + 2. A field + 3. Array dereferences (indexing) +11. There must be no attempt to access the field or method of a +non-object type, such as arrays or primitive types (`TYPE_ERROR`) +12. A method with a return type must have a return statement at the end +of all its paths (`MISSING_RETURN`). A while loop is not a valid return +regardless of the condition. A ifElse must have a return on both the +else and otherwise block. There may be some statements after a return. \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..f95cadc --- /dev/null +++ b/TODO.md @@ -0,0 +1,75 @@ +## Possible code changes +### General +* DONE Use more specific messages when throwing a `SemanticFailure` exception. This has the caveat that the automated testing relies on those tests? + +### StmtAnalyzer +* DONE Propagate the change of class parameter from `ExprAnalyzer`. +* DONE Complete checks for `MISSING_RETURN`, some ideas: + * DONE Assume no instructions will appear after a return statement and analyze only the last `Stmt` using other visitor + with different class parameters (for example passing the desired type and returning a `Optional`). + * DONE Decide the logic behind a return statement in a `while` loop, maybe treat it as an `if` with an empty `else` block. + * A `while` as last instruction is not a valid return. + * A `if` as last instruction must have a valid return a the end of its then and otherwise blocks. + +### ExprAnalyzer +* DONE Change the second class parameter to give method AND class information (needed by var and this nodes) + * DISCARDED Add a ClassSymbol to MethodSymbol and use it as class parameter, the problem arises when visiting a method, + should an empty method with the proper class be provided? Could also be solved by using `Symbol` as class parameter. + * DONE Create a new class that includes a `ClassSymbol` and a `MethodSymbol` and use that. Keep `MethodSymbol == null` + when appropriate. + +## Tests +This tests have been selected to increase to 100% the code coverage obtained by running the tests designed for the previous HW, +which are in folder svn/HW2/javali_tests/HW2_nop90 + +As they are mostly related to errors that haven't been triggered, each test should be separate, in order to generate all +of the errors. + +### Remaining +### Done +* access var from class or superclass +* test ! operator +* type error in unaryOp +* type error in array size +* call method from superclass +* call a method that doesn't exist +* call a method with the wrong type of params +* call a method with the wrong number of params +* assign to all possible syntactically correct options + * field + * var + * array index + * method (error) + * this (error) +* indexing both types error +* try to access a field of something that is not a class type +* typing error in cast +* AND and OR operations +* equals operators (a case that is OK and another that's not) +* binary operation with wrong type (any but == and !=) +* search for a type that doesn't exist in a method body +* don't have a Main class +* don't have a main() method in the Main class (all possibilities) + * wrong name + * wrong return value + * wrong parameters +* inherited main method (it should work) +* write something that is not an integer +* declare a variable mutiple times (local variables) +* declare a local variable with the same name as a parameter +* check MISSING_RETURN + * nested ifElse as end of method + * while as end of method + * normal returns at the end of the method + * return with further statements after it +* while with non-int condition +* use a array type that hasn't been discovered yet + * ```class A { B[] name; } class B {}``` +* name a class Object +* name a class like another class +* name a parameter like another +* override methods and try to break that + * same return type + * same number of params + * same type of params +* name a variable like another (field level) diff --git a/build.xml b/build.xml index ea0e895..7beb2b1 100644 --- a/build.xml +++ b/build.xml @@ -1,4 +1,4 @@ - + - - - - - - - - - - - - - - + - - + @@ -66,6 +36,7 @@ + @@ -108,4 +79,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/javali_tests/HW3/ErrCallBase.javali b/javali_tests/HW3/ErrCallBase.javali new file mode 100644 index 0000000..d7e4729 --- /dev/null +++ b/javali_tests/HW3/ErrCallBase.javali @@ -0,0 +1,9 @@ +// Test that you cannot invoke a method on an integer. + +class Main { + void main() { + int x; + x = 1; + x.foo(); + } +} diff --git a/javali_tests/HW3/ErrCircularInheritance.javali b/javali_tests/HW3/ErrCircularInheritance.javali new file mode 100644 index 0000000..d8554e9 --- /dev/null +++ b/javali_tests/HW3/ErrCircularInheritance.javali @@ -0,0 +1,9 @@ +/* Test that the circular inheritance between Foo and Bar is detected */ +class Foo extends Bar { } +class Bar extends Foo { } + +class Main { + void main() { + writeln(); + } +} diff --git a/javali_tests/HW3/ErrIfCondition.javali b/javali_tests/HW3/ErrIfCondition.javali new file mode 100644 index 0000000..ce30780 --- /dev/null +++ b/javali_tests/HW3/ErrIfCondition.javali @@ -0,0 +1,11 @@ +/* Test that if conditions must be boolean */ +class Main { + void main() { + if (84 / 2) { + write(1); + writeln(); + } + write(2); + writeln(); + } +} diff --git a/javali_tests/HW3/ErrUnknownField1.javali b/javali_tests/HW3/ErrUnknownField1.javali new file mode 100644 index 0000000..bd66d1e --- /dev/null +++ b/javali_tests/HW3/ErrUnknownField1.javali @@ -0,0 +1,14 @@ +/* Test that an invalid field name is detected */ + +class X { + int field; +} + +class Main { + void main() { + X x; + x = new X(); + x.field = 0; + x.notafield = 1; /* ILLEGAL: bad field name */ + } +} diff --git a/javali_tests/HW3/OkInheritanceFields.javali b/javali_tests/HW3/OkInheritanceFields.javali new file mode 100644 index 0000000..ac7b1ac --- /dev/null +++ b/javali_tests/HW3/OkInheritanceFields.javali @@ -0,0 +1,30 @@ +/* Test that fields are inherited */ + +class A { + int foo; +} + +class B extends A { + int bar; +} + +class Main { + void main() { + A a; + B b; + + a = new A(); + a.foo = 1; + write(a.foo); + + a = new B(); + a.foo = 2; + write(a.foo); + + b = new B(); + b.foo = 3; + b.bar = 4; + write(b.foo); + write(b.bar); + } +} diff --git a/javali_tests/HW3_nop90/Assignments/Errors/ArrayAreNotCovariant.javali b/javali_tests/HW3_nop90/Assignments/Errors/ArrayAreNotCovariant.javali new file mode 100644 index 0000000..a34e588 --- /dev/null +++ b/javali_tests/HW3_nop90/Assignments/Errors/ArrayAreNotCovariant.javali @@ -0,0 +1,16 @@ +// Test that arrays are not covariant + +class Main { + void main() { + boolean y; + A[] Array1; + B[] Array2; + Array2 = new B[10]; + + Array1 = Array2; + } +} + +class B extends A {} + +class A {} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/Assignments/Errors/AssignToMethodCall.javali b/javali_tests/HW3_nop90/Assignments/Errors/AssignToMethodCall.javali new file mode 100644 index 0000000..284a6f7 --- /dev/null +++ b/javali_tests/HW3_nop90/Assignments/Errors/AssignToMethodCall.javali @@ -0,0 +1,11 @@ +// The left-hand side of an assignment cannot be a method call +// Valid options are variable accesses, fields or an indexed array + +class Main { + void main() { + action() = read(); + } + int action() { + return 0; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/Assignments/Errors/AssignToThis.javali b/javali_tests/HW3_nop90/Assignments/Errors/AssignToThis.javali new file mode 100644 index 0000000..62b6743 --- /dev/null +++ b/javali_tests/HW3_nop90/Assignments/Errors/AssignToThis.javali @@ -0,0 +1,15 @@ +// The left-hand side of an assignment cannot be a reference to this +// Valid options are variable accesses, fields or an indexed array + +class Main { + void main () { + int b; + int[] c; + c = new int[5]; + this.a = 10; + b = 10; + c[4] = 10; + this = null; + } + int a; +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/Assignments/OkArraySubtypes.javali b/javali_tests/HW3_nop90/Assignments/OkArraySubtypes.javali new file mode 100644 index 0000000..bbaf6b9 --- /dev/null +++ b/javali_tests/HW3_nop90/Assignments/OkArraySubtypes.javali @@ -0,0 +1,14 @@ +// any array is a subtype of Object +// assignment and 'is equal' with an object of type 'Object' is fine + +class Main { + void main() { + boolean y; + Object x; + int[] testArray; + testArray = new int[10]; + x = testArray; + testArray = null; + x = null; + } +} diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleClass.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleClass.javali new file mode 100644 index 0000000..dd0ed29 --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleClass.javali @@ -0,0 +1,8 @@ +// Multiple classes can't share the same name + +class Aclass {} +class Aclass {} + +class Main { + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleField.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleField.javali new file mode 100644 index 0000000..5e787c0 --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleField.javali @@ -0,0 +1,8 @@ +// Two fields in a class cannot share the same name + +class Main { + void main() {} + int a; + Object b; + Main a; +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleLocalVar.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleLocalVar.javali new file mode 100644 index 0000000..685a4f5 --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleLocalVar.javali @@ -0,0 +1,8 @@ +// Two local variables in a method cannot share the same name + +class Main { + void main() {} + void test() { + int a, a; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParamAndLocal.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParamAndLocal.javali new file mode 100644 index 0000000..9ddf500 --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParamAndLocal.javali @@ -0,0 +1,10 @@ +// test double declaration +// test local variable and parameter have same name + +class Main { + void main() {} + int action(int p1, boolean p2) { + Object p1; + return 1; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParams.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParams.javali new file mode 100644 index 0000000..9767fdd --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/DoubleParams.javali @@ -0,0 +1,6 @@ +// No pair of parameters in a method declaration can have the same name + +class Main { + void main() {} + int action(int p1, boolean p2, Object p, Object p) {} +} diff --git a/javali_tests/HW3_nop90/DoubleDeclarationsErrors/ObjectClass.javali b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/ObjectClass.javali new file mode 100644 index 0000000..7b3b0a2 --- /dev/null +++ b/javali_tests/HW3_nop90/DoubleDeclarationsErrors/ObjectClass.javali @@ -0,0 +1,7 @@ +// No class can have the name "Object" + +class Aclass {} +class Object extends Aclass {} +class Main extends Object { + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/EntrypointTests/ErrorMainReturnType.javali b/javali_tests/HW3_nop90/EntrypointTests/ErrorMainReturnType.javali new file mode 100644 index 0000000..cd6a10a --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/ErrorMainReturnType.javali @@ -0,0 +1,7 @@ +// Error: the return type of the "main" method must be "void" + +class Main { + int main() { + return 10; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/EntrypointTests/ErrorMainWithParams.javali b/javali_tests/HW3_nop90/EntrypointTests/ErrorMainWithParams.javali new file mode 100644 index 0000000..e53df03 --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/ErrorMainWithParams.javali @@ -0,0 +1,5 @@ +// Error: the main method must have no arguments + +class Main { + void main(Object[] args) {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainClass.javali b/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainClass.javali new file mode 100644 index 0000000..a354e98 --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainClass.javali @@ -0,0 +1,4 @@ +// Error: there is no class called Main (case-sensitive) + +class MAIN {} +class main extends Object {} diff --git a/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainMethod.javali b/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainMethod.javali new file mode 100644 index 0000000..f2732c5 --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/ErrorNoMainMethod.javali @@ -0,0 +1,11 @@ +// Error: the "Main" class does not contain a method called "main" + +class Main { + void maini() {} + void mein() {} + void moon() {} +} + +class NotMain extends Main { + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/EntrypointTests/OkInheritedMainMethod.javali b/javali_tests/HW3_nop90/EntrypointTests/OkInheritedMainMethod.javali new file mode 100644 index 0000000..6f653bf --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/OkInheritedMainMethod.javali @@ -0,0 +1,7 @@ +// The main method can be inherited from another class + +class OtherMain { + void main () {} +} + +class Main extends OtherMain {} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/EntrypointTests/OkOverriddenMainMethod.javali b/javali_tests/HW3_nop90/EntrypointTests/OkOverriddenMainMethod.javali new file mode 100644 index 0000000..5e91d23 --- /dev/null +++ b/javali_tests/HW3_nop90/EntrypointTests/OkOverriddenMainMethod.javali @@ -0,0 +1,15 @@ +// The main method can be overridden in the inherit process, as any other method can + +class A { + void main() { + write(1); + } +} + +class B extends A { + void main() { + write(2); + } +} + +class Main extends B {} diff --git a/javali_tests/HW3_nop90/ErrorOverloadMethod.javali b/javali_tests/HW3_nop90/ErrorOverloadMethod.javali new file mode 100644 index 0000000..a0c5d2d --- /dev/null +++ b/javali_tests/HW3_nop90/ErrorOverloadMethod.javali @@ -0,0 +1,7 @@ +// Methods cannot be overloaded + +class Main { + void main() {} + void method(int a) {} + void method(int[] a) {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/FieldTests/ErrorAccessField.javali b/javali_tests/HW3_nop90/FieldTests/ErrorAccessField.javali new file mode 100644 index 0000000..cd452d2 --- /dev/null +++ b/javali_tests/HW3_nop90/FieldTests/ErrorAccessField.javali @@ -0,0 +1,21 @@ +// Test 'NO SUCH FIELD' + +class Main { + void main() { + C1 c1; + C2 c2; + c1 = new C1(); + c2 = new C2(); + c1.a = 5; + c2.b = 6; + } +} + +class C1{ + int a; +} + +class C2 extends C1 {} + +class C3 extends C2 {} + diff --git a/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromArray.javali b/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromArray.javali new file mode 100644 index 0000000..5222402 --- /dev/null +++ b/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromArray.javali @@ -0,0 +1,9 @@ +// Access a field from an array (error, not a class type). Not even the length field exists + +class Main { + void main() { + int[] c; + c = new int[10]; + write(c.length); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromInt.javali b/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromInt.javali new file mode 100644 index 0000000..d169464 --- /dev/null +++ b/javali_tests/HW3_nop90/FieldTests/ErrorFieldFromInt.javali @@ -0,0 +1,8 @@ +// Error: access a field from a non-class type (primitive type int) + +class Main { + void main() { + int a; + write(a.end); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/FieldTests/OkInheritedFieldAccess.javali b/javali_tests/HW3_nop90/FieldTests/OkInheritedFieldAccess.javali new file mode 100644 index 0000000..ec165e5 --- /dev/null +++ b/javali_tests/HW3_nop90/FieldTests/OkInheritedFieldAccess.javali @@ -0,0 +1,27 @@ +// access a field from a class and a superclass (also includes hidden fields) + +class Main { + void main() { + C1 c1; + C2 c2; + C4 c4; + c1 = new C1(); + c2 = new C2(); + c4 = new C4(); + c1.a = 5; + c2.a = 6; + c4.a = false; + } +} + +class C1{ + int a; +} + +class C2 extends C1 {} + +class C3 extends C2 {} + +class C4 extends C3 { + boolean a; +} diff --git a/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ComplexLoop.javali b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ComplexLoop.javali new file mode 100644 index 0000000..7f758ff --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ComplexLoop.javali @@ -0,0 +1,17 @@ +// Test more complex/nested cases of CIRCULAR INHERITANCE + +class Main { + void main() {} +} + +class D1 extends C{} + +class E extends D1{} + +class D2 extends C{} + +class E2 extends D2{} + +class F extends E2{} + +class C extends F{} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/LongLoop.javali b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/LongLoop.javali new file mode 100644 index 0000000..941e79b --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/LongLoop.javali @@ -0,0 +1,28 @@ +// Test long loops of circular inheritance + +class A extends Z {} +class B extends A {} +class C extends B {} +class D extends C {} +class E extends D {} +class F extends E {} +class G extends F {} +class H extends G {} +class I extends H {} +class J extends I {} +class K extends J {} +class L extends K {} +class M extends L {} +class N extends M {} +class O extends N {} +class P extends O {} +class Q extends P {} +class R extends Q {} +class S extends R {} +class T extends S {} +class U extends T {} +class V extends U {} +class W extends V {} +class X extends W {} +class Y extends X {} +class Z extends Y {} diff --git a/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/SelfLoop.javali b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/SelfLoop.javali new file mode 100644 index 0000000..d9919af --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/SelfLoop.javali @@ -0,0 +1,5 @@ +// Test inheritance of itself + +class Main extends Main { + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ShortLoop.javali b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ShortLoop.javali new file mode 100644 index 0000000..8ec07f3 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/CircularInheritanceErrors/ShortLoop.javali @@ -0,0 +1,7 @@ +// Simple circular inheritance loop + +class Main extends Other { + void main() {} +} + +class Other extends Main {} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/ErrorOverloadInheritedMethod.javali b/javali_tests/HW3_nop90/InheritanceTests/ErrorOverloadInheritedMethod.javali new file mode 100644 index 0000000..48ae4bc --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/ErrorOverloadInheritedMethod.javali @@ -0,0 +1,10 @@ +// Inherited methods cannot be overloaded + +class Main extends Other { + void main() {} + void method(int a) {} +} + +class Other { + void method() {} +} diff --git a/javali_tests/HW3_nop90/InheritanceTests/OkAccessField.javali b/javali_tests/HW3_nop90/InheritanceTests/OkAccessField.javali new file mode 100644 index 0000000..6895e56 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OkAccessField.javali @@ -0,0 +1,30 @@ +// Access inherited and hidden fields (general check) + +class Other { + int a; + int b; + Object c; + Other o; +} + +class Main extends Other { + int a, b; + + void main() { + Other o; + o = (Other) this; + a = 1; + b = 2; + o.a = -1; + o.b = -2; + write(a); + write(b); + write(o.a); + write(o.b); + if (c != null) { + if (o.o != null) { + write(0); + } + } + } +} diff --git a/javali_tests/HW3_nop90/InheritanceTests/OkCallInheritedMethod.javali b/javali_tests/HW3_nop90/InheritanceTests/OkCallInheritedMethod.javali new file mode 100644 index 0000000..41c491c --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OkCallInheritedMethod.javali @@ -0,0 +1,17 @@ +// call an method from a superclass + +class Main { + void main() { + C2 c; + c = new C2(); + c.aux(); + } +} + +class C1{ + void aux(){ + write(2); + } +} + +class C2 extends C1 {} diff --git a/javali_tests/HW3_nop90/InheritanceTests/OkHideField.javali b/javali_tests/HW3_nop90/InheritanceTests/OkHideField.javali new file mode 100644 index 0000000..cf9cc60 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OkHideField.javali @@ -0,0 +1,16 @@ +// Hide a field from a superclass (type doesn't need to match) + +class Parent { + int a; +} +class Main extends Parent { + Object a; + Main b; + void main() { + Parent c; + b = new Main(); + b.a = new Object(); + c = new Parent(); + c.a = 10; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideNumberParams.javali b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideNumberParams.javali new file mode 100644 index 0000000..01a96a6 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideNumberParams.javali @@ -0,0 +1,16 @@ +// The number of parameters when overriding a method must be equal + +class Other { + void action() { + write(10); + } +} + +class Main extends Other { + void action(int num) { + write(num); + return num + 1; + } + + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideReturnType.javali b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideReturnType.javali new file mode 100644 index 0000000..f8172dc --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideReturnType.javali @@ -0,0 +1,14 @@ +// The return type when overriding a method must be equal + +class Other { + void action() {} +} + +class Main extends Other { + int action() { + write(10); + return 8; + } + + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideTypeParams.javali b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideTypeParams.javali new file mode 100644 index 0000000..e543bc1 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/ErrorOverrideTypeParams.javali @@ -0,0 +1,17 @@ +// The type of parameters when overriding a method must match the overridden method + +class Other { + void action(int num) { + write(num); + } +} + +class Main extends Other{ + void action(boolean name) { + if (name) { + writeln(); + } + } + + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/OkCallOverriddenMethod.javali b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/OkCallOverriddenMethod.javali new file mode 100644 index 0000000..972bf55 --- /dev/null +++ b/javali_tests/HW3_nop90/InheritanceTests/OverrideTests/OkCallOverriddenMethod.javali @@ -0,0 +1,16 @@ +// Call method that has been overridden (both the new and old one) + +class Other { + void method() {} +} + +class Main extends Other { + void main() { + Other o; + method(); + o = (Other) this; + o.method(); + } + + void method() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromArray.javali b/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromArray.javali new file mode 100644 index 0000000..1a17f9e --- /dev/null +++ b/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromArray.javali @@ -0,0 +1,8 @@ +// An array doesn't have methods + +class Main { + Object[] array; + void main() { + array.go(); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromPrimitive.javali b/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromPrimitive.javali new file mode 100644 index 0000000..d20f597 --- /dev/null +++ b/javali_tests/HW3_nop90/MethodCallsErrors/MethodFromPrimitive.javali @@ -0,0 +1,8 @@ +// A primitive variable doesn't have methods + +class Main { + int a; + void main() { + a.go(); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamNumber.javali b/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamNumber.javali new file mode 100644 index 0000000..3f0debf --- /dev/null +++ b/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamNumber.javali @@ -0,0 +1,9 @@ +// call an method with wrong number of parameters + +class Main { + void main() { + aux(a, b, c); + } + + void aux(int a, int b) {} +} diff --git a/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamType.javali b/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamType.javali new file mode 100644 index 0000000..3b95679 --- /dev/null +++ b/javali_tests/HW3_nop90/MethodCallsErrors/WrongParamType.javali @@ -0,0 +1,11 @@ +// call an method with wrong types of parameters + +class Main { + void main() { + int a; + boolean b; + aux(a, b); + } + + void aux(int a, int b) {} +} diff --git a/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchMethod.javali b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchMethod.javali new file mode 100644 index 0000000..daf1561 --- /dev/null +++ b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchMethod.javali @@ -0,0 +1,19 @@ +// call an method that does not exist (even in superclass) + +class Main extends Other { + void main() { + aux(); + go(); + } + + void aux() {} +} + +class Other { + void aux() {} + void otherAux() {} + void noGo() {} + void GO() {} + void gO() {} + void Go() {} +} diff --git a/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassBody.javali b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassBody.javali new file mode 100644 index 0000000..f053271 --- /dev/null +++ b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassBody.javali @@ -0,0 +1,6 @@ +// No such type in method body (handled by TypeGenerator) + +class Main { + void method(NoSuchType param) {} + void main() {} +} diff --git a/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassHeader.javali b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassHeader.javali new file mode 100644 index 0000000..5963900 --- /dev/null +++ b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeClassHeader.javali @@ -0,0 +1,5 @@ +// No such type in method body (handled by checkCircularInheritance) + +class Main extends NoSuchType { + void main() {} +} diff --git a/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeMethodBody.javali b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeMethodBody.javali new file mode 100644 index 0000000..0427c8a --- /dev/null +++ b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchTypeMethodBody.javali @@ -0,0 +1,8 @@ +// No such type in method body (handled by ExprVisitor and StmtVisitor) + +class Main { + void main() { + Object a; + write((NoType) a); + } +} diff --git a/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchVariable.javali b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchVariable.javali new file mode 100644 index 0000000..67cb221 --- /dev/null +++ b/javali_tests/HW3_nop90/NoSuchSymbolErrors/NoSuchVariable.javali @@ -0,0 +1,28 @@ +// Test NO SUCH VARIABLE +// All referenced variables must exist. + +class Main extends Other { + int a; + int b; + int C; + Object notC; + + void main() { + int a; + boolean b; + write(c + 1); + } +} + +class Other { + boolean a; + boolean b; + boolean C; + Object[] notC; + + void main() { + int a; + boolean b; + Object c; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/OkDoubleNamesDiffScopes.javali b/javali_tests/HW3_nop90/OkDoubleNamesDiffScopes.javali new file mode 100644 index 0000000..56eca0d --- /dev/null +++ b/javali_tests/HW3_nop90/OkDoubleNamesDiffScopes.javali @@ -0,0 +1,22 @@ +// Names are case-sensitive +// There exists different scopes for fields, methods, class types, parameters and local variables + +class main extends Main { + main main; + Main Main; + + main main(Main main, main Main) { + Main MAIN; + main maiN; + maiN = new Main(); + return maiN; + } +} + +class Main { + main main; + Main Main; + void main() { + + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/OkUndiscoveredType.javali b/javali_tests/HW3_nop90/OkUndiscoveredType.javali new file mode 100644 index 0000000..bcd0238 --- /dev/null +++ b/javali_tests/HW3_nop90/OkUndiscoveredType.javali @@ -0,0 +1,31 @@ +// This method is used to force TypeGenerator to search through the list of class declarations and find +// types that don't exist in the type list but have a class declared for them. + +class Other { + // Must discover in class declaration list + Main[] array; + Third third; + // Already exist + Fourth fourth; // discovered as parent of Third + Other other; // already visited + int a; // primitive and object types (and corresponding arrays) created before visiting classes + boolean b; + int[] As; + boolean[] Bs; + Object o; + Object[] Os; + Third[] thirds; // array types created when visiting corresponding classes + Other[] others; +} + +class Main { + void main() {} +} + +class Third extends Fourth { + +} + +class Fourth { + +} diff --git a/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpDifferentTypes.javali b/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpDifferentTypes.javali new file mode 100644 index 0000000..af38251 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpDifferentTypes.javali @@ -0,0 +1,9 @@ +// The arguments of a BinaryOp (except == and !=) must be of the type specified by the operator + +class Main { + void main() { + int a; + boolean b; + write( a + b ); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpType.javali b/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpType.javali new file mode 100644 index 0000000..19f7719 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/ErrorBinaryOpType.javali @@ -0,0 +1,11 @@ +// Error: both sides of a BinaryOp (except == and !=) must be of the same type + +class Main { + void main() { + int a, b, c; + boolean d, e; + a = a + b; + d = a <= b; + d = b && c; + } +} diff --git a/javali_tests/HW3_nop90/OperatorTests/ErrorEquals.javali b/javali_tests/HW3_nop90/OperatorTests/ErrorEquals.javali new file mode 100644 index 0000000..02070f5 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/ErrorEquals.javali @@ -0,0 +1,25 @@ +// Test the equal/not equal operations +// this test should trigger an TYPE ERROR + +class Main { + void main() { + C1 a; + C3 d; + D1 f; + boolean x,y,z; + a = new C1(); + d = new C3(); + f = new D1(); + + y = f == d; + x = a != f; + } +} + +class C1 {} + +class C2 extends C1{} + +class C3 extends C2{} + +class D1 {} diff --git a/javali_tests/HW3_nop90/OperatorTests/ErrorUnaryOp.javali b/javali_tests/HW3_nop90/OperatorTests/ErrorUnaryOp.javali new file mode 100644 index 0000000..bcdfd41 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/ErrorUnaryOp.javali @@ -0,0 +1,19 @@ +// Test type errors with unary operator + +class Main { + void main() { + int x,y,z; + boolean a; + x = -100; + y = 5; + + a = -true; + z = -y; + x = +x; + write(x); + writeln(); + write(z); + writeln(); + write(-a); + } +} diff --git a/javali_tests/HW3_nop90/OperatorTests/OkBooleanAndOr.javali b/javali_tests/HW3_nop90/OperatorTests/OkBooleanAndOr.javali new file mode 100644 index 0000000..f0f70c5 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/OkBooleanAndOr.javali @@ -0,0 +1,8 @@ +// Test boolean && and || operators + +class Main { + void main() { + boolean a, b, c; + a = b && c || a; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/OperatorTests/OkEquals.javali b/javali_tests/HW3_nop90/OperatorTests/OkEquals.javali new file mode 100644 index 0000000..ee0e562 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/OkEquals.javali @@ -0,0 +1,31 @@ +// Test the equal/not equal operations, one of the types must be a subtype of the other + +class Main { + void main() { + C1 c1; + C2 c2; + C3 c3; + Object o1, o2; + boolean s; + + o1 = new Object(); + o2 = new Object(); + c1 = new C1(); + c2 = new C2(); + c3 = new C3(); + + s = o1 == o2; + s = c1 != c2; + s = c3 == c1; + s = o2 != o1; + s = null == c2; + s = o1 == c2; + s = null == o; + } +} + +class C1 {} + +class C2 extends C1{} + +class C3 extends C2{} diff --git a/javali_tests/HW3_nop90/OperatorTests/OkNot.javali b/javali_tests/HW3_nop90/OperatorTests/OkNot.javali new file mode 100644 index 0000000..eb293e7 --- /dev/null +++ b/javali_tests/HW3_nop90/OperatorTests/OkNot.javali @@ -0,0 +1,36 @@ +// Test '!' operator + +class Main { + void main() { + boolean a,b,c,d; + int x,y; + + a = true; + c = !false; + b = !a; + x = 100; + y = 5; + + if (a) { + write(1);} + writeln(); + + if (!b){ + write(2); + } + writeln(); + + while(c){ + write(3); + c = false; + } + writeln(); + + // !x < 2 * y --> !x type error + // !(x < 2 * y) --> correct syntax + while(!(x<2*y)){ + write(y); + y = y*2; + } + } +} diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorEmptyReturn.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorEmptyReturn.javali new file mode 100644 index 0000000..0aa5593 --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorEmptyReturn.javali @@ -0,0 +1,9 @@ +// A method that returns a non-void type should have arguments in all returns + +class Main { + int method() { + return; + } + + void main() {} +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorIfNoReturnInElse.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorIfNoReturnInElse.javali new file mode 100644 index 0000000..f398e45 --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorIfNoReturnInElse.javali @@ -0,0 +1,18 @@ +// For a if/else to be a valid return, it needs to have a return statement in both sides + +class Main { + void main() { + write(things()); + writeln(); + } + + int things() { + Object c, d; + c = new Object(); + d = new Object(); + + if (c == d) { + return 10; + } + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorIncompatibleReturnType.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorIncompatibleReturnType.javali new file mode 100644 index 0000000..bca5f38 --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorIncompatibleReturnType.javali @@ -0,0 +1,20 @@ +// The return type must be a subtype of the method's return type + +class Main { + Main main; + Object object; + + void main() {} + + Object method() { + return null; + return object; + return main; + } + + Main otherMethod() { + return null; + return main; + return object; // error + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturn.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturn.javali new file mode 100644 index 0000000..4d25c8f --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturn.javali @@ -0,0 +1,20 @@ +// A method with a non-void return type must have a return statement + +class Main { + void main() { + write(things()); + writeln(); + } + + int things() { + int a; + int b; + Object c, d; + a = 10; + b = 100; + c = new Object(); + d = new Object(); + a = b; + c = d; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnNestedIfElse.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnNestedIfElse.javali new file mode 100644 index 0000000..f2a4702 --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnNestedIfElse.javali @@ -0,0 +1,29 @@ +// Test nested return statement +// the return statement is nested in if/else statements +// conditions for the if/else aren't checked + +class Main { + void main() {} + + int aux (boolean e){ + boolean a,b,c,d; + a = true; + b = true; + c = false; + + if (a){ + if (b){ + if (c){ + + } else { + if (e) { + return 1; + } else { + return 0; + } + } + } + } + } + +} diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnWhile.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnWhile.javali new file mode 100644 index 0000000..a0a9fee --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorNoReturnWhile.javali @@ -0,0 +1,11 @@ +// Test return statement in while loop + +class Main { + void main() {} + + int aux() { + while (true) { + return 1; + } + } +} diff --git a/javali_tests/HW3_nop90/ReturnTests/ErrorReturnWithArg.javali b/javali_tests/HW3_nop90/ReturnTests/ErrorReturnWithArg.javali new file mode 100644 index 0000000..b25bb08 --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/ErrorReturnWithArg.javali @@ -0,0 +1,7 @@ +// A method that returns void can't have a return with an argument + +class Main { + void main() { + return 3; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/OkComplexIfElseAndReturnSubtyping.javali b/javali_tests/HW3_nop90/ReturnTests/OkComplexIfElseAndReturnSubtyping.javali new file mode 100644 index 0000000..cef633a --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/OkComplexIfElseAndReturnSubtyping.javali @@ -0,0 +1,79 @@ +// A if/else block is valid return statment if all possible branches return some value +// Also serves to check subtyping +// The return logic leads to nonsensical programs with statements after the return, but that's ok + +class Main { + // All returns must be empty, but we don't care for their existence + void main() { + int a, b, c; + if (a == b) { + return; + } else { + while (a > b) { + return; + } + if (c > b) { + return; + } + } + } + + // All returns must be null, Main (all subtypes of Main), and there must be an unconditional return + Main action1() { + Main a; + Object b; + boolean x, y; + if (x) { + if (y) { + if (x || y) { + if (x == y && x != y) { + return null; + } else { + return a; + } + } else { + if (b == null) { + return a; + } else { + return a; + } + } + } else { + if (b == a || a == null) { + return null; + } else { + return a; + } + } + } else { + return null; + } + } + + // All returns must be null, Main[] (all subtypes of Main[]), and there must be an unconditional return + Main[] action2() { + Main[] a, b; + if (a == b) { + return a; + } else { + if (b != null) { + return b; + } else { + return null; + } + } + } + + // All returns must be int (no subtypes), and there must be an unconditional return + int action3() { + int a, b, c, d; + if (a > b) { + return c - d; + while (a != a) { + return b; + } + } else { + return c * d / a + b % c - a; + } + } +} diff --git a/javali_tests/HW3_nop90/ReturnTests/OkMiddleReturn.javali b/javali_tests/HW3_nop90/ReturnTests/OkMiddleReturn.javali new file mode 100644 index 0000000..fb2622f --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/OkMiddleReturn.javali @@ -0,0 +1,21 @@ +// The return statement can be placed in the middle of the method, and no warning will be thrown about unexecuted +// statements + +class Main { + void main() { + write(things()); + writeln(); + } + + int things() { + int a; + a = 10; + return a; + + // These statements won't be reached + // but there is a complete return statement + a = 20; + writeln(); + writeln(); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/ReturnTests/OkSimpleIfElse.javali b/javali_tests/HW3_nop90/ReturnTests/OkSimpleIfElse.javali new file mode 100644 index 0000000..bb6f83a --- /dev/null +++ b/javali_tests/HW3_nop90/ReturnTests/OkSimpleIfElse.javali @@ -0,0 +1,24 @@ +// A if/else with a return in both branches is valid + +class Main { + void main() { + write(things()); + writeln(); + } + + int things() { + int a; + int b; + Object c, d; + a = 10; + b = 100; + c = new Object(); + d = new Object(); + + if (c == d) { + return 10; + } else { + return 5; + } + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/ArrayIndex.javali b/javali_tests/HW3_nop90/TypeErrors/ArrayIndex.javali new file mode 100644 index 0000000..8bedc19 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/ArrayIndex.javali @@ -0,0 +1,12 @@ +// Test type errors when accessing an Array + +class Main { + void main() { + boolean x; + int y; + int [] testArray; + testArray = new int[10]; + + y = testArray[x]; + } +} diff --git a/javali_tests/HW3_nop90/TypeErrors/CastUnrelatedType.javali b/javali_tests/HW3_nop90/TypeErrors/CastUnrelatedType.javali new file mode 100644 index 0000000..d9f7eb5 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/CastUnrelatedType.javali @@ -0,0 +1,22 @@ +// Test types in a Cast (cannot cast to unrelated type) +// Casts to primitive types and arrays are controlled by the parser + +class Main { + void main() { + C1 a, b; + C2 c, d; + Object o; + c = new C2(); + a = new C1(); + + b = (C1) c; + d = (C2) a; + o = (Object) a; + o = (Object) c; + o = (Main) c; + } +} + +class C1 {} + +class C2 extends C1{} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/ConditionIf.javali b/javali_tests/HW3_nop90/TypeErrors/ConditionIf.javali new file mode 100644 index 0000000..4a62be2 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/ConditionIf.javali @@ -0,0 +1,9 @@ +// The condition of an if statement must be an int + +class Main { + void main() { + if (null) { + return; + } + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/ConditionWhile.javali b/javali_tests/HW3_nop90/TypeErrors/ConditionWhile.javali new file mode 100644 index 0000000..ac73fd5 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/ConditionWhile.javali @@ -0,0 +1,7 @@ +// The condition of a while must be an boolean + +class Main { + void main() { + while (null) {} + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/IndexObjectType.javali b/javali_tests/HW3_nop90/TypeErrors/IndexObjectType.javali new file mode 100644 index 0000000..48a273c --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/IndexObjectType.javali @@ -0,0 +1,8 @@ +// A object (non-array) type cannot be indexed + +class Main { + void main() { + Object a; + a[1] = new Object(); + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/IndexPrimitiveType.javali b/javali_tests/HW3_nop90/TypeErrors/IndexPrimitiveType.javali new file mode 100644 index 0000000..c099572 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/IndexPrimitiveType.javali @@ -0,0 +1,8 @@ +// A primitive type cannot be indexed + +class Main { + void main() { + int a; + a[1] = 10; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/NewArraySize.javali b/javali_tests/HW3_nop90/TypeErrors/NewArraySize.javali new file mode 100644 index 0000000..adc6769 --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/NewArraySize.javali @@ -0,0 +1,8 @@ +// The size for a new array declaration must be an int + +class Main { + void main() { + Object[] array; + array = new Object[array]; + } +} \ No newline at end of file diff --git a/javali_tests/HW3_nop90/TypeErrors/WriteArg.javali b/javali_tests/HW3_nop90/TypeErrors/WriteArg.javali new file mode 100644 index 0000000..83d463f --- /dev/null +++ b/javali_tests/HW3_nop90/TypeErrors/WriteArg.javali @@ -0,0 +1,10 @@ +// Test type error in write() statement + +class Main { + void main() { + boolean a; + a = true; + write(10); + write(a); + } +} diff --git a/javali_tests/from_prev_HW/Arrays.javali b/javali_tests/from_prev_HW/Arrays.javali new file mode 100644 index 0000000..2638373 --- /dev/null +++ b/javali_tests/from_prev_HW/Arrays.javali @@ -0,0 +1,24 @@ +/* testing arrays with primitive types as well as new objects +the if/else statements shows that the array is boolean array is initialized with false + */ +class Main { + void main() { + int [] testArray; + boolean [] boolarray; + + boolarray = new boolean [3]; + testArray = new int [10]; + + testArray[5] = 3; + boolarray[1] = true; + + if (boolarray[0]){ + write(1);} + else{ + write(5);} + writeln(); + if (boolarray[1]){ + write(1);} + + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/Assignments.javali b/javali_tests/from_prev_HW/Assignments.javali new file mode 100644 index 0000000..d239f5f --- /dev/null +++ b/javali_tests/from_prev_HW/Assignments.javali @@ -0,0 +1,12 @@ +/* testing assign statements*/ +class Main { + void main() { + a = read(); + b = methodCall(); + c = methodCall(param1, param2); + d = object.access; + e = new Ast(); + d = new int[size]; + f = new Object[size]; + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/Casts.javali b/javali_tests/from_prev_HW/Casts.javali new file mode 100755 index 0000000..a33c216 --- /dev/null +++ b/javali_tests/from_prev_HW/Casts.javali @@ -0,0 +1,16 @@ +/* testing casting as well as creating new Objects*/ +class Main +{ + void main() + { + int a; + int b; + Object c; + Object d; + + c = null; + d = new Object(); + a = 10; + c = (Object) d; + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/Division.javali b/javali_tests/from_prev_HW/Division.javali new file mode 100755 index 0000000..13358d3 --- /dev/null +++ b/javali_tests/from_prev_HW/Division.javali @@ -0,0 +1,21 @@ +class Main { + void main() { + int a, b, c, d, e; + + a = 10; + b = -1; + c = 0; + d = 100; + e = 2; + + write(a / b); writeln(); + write(d / e); writeln(); + write(c / d); writeln(); + write(b / a + c); writeln(); + write(d / e * a / b * c); writeln(); + write(d / e * a / b); writeln(); + write(d / e + a / b); writeln(); + write(d / e * a * b * c); writeln(); + write(d / e * a - b + c); writeln(); + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/DoubleInheritance.javali b/javali_tests/from_prev_HW/DoubleInheritance.javali new file mode 100644 index 0000000..f950cea --- /dev/null +++ b/javali_tests/from_prev_HW/DoubleInheritance.javali @@ -0,0 +1,9 @@ +/* testing basic inheritance*/ +class C1 {} +class C2 extends C1 {} +class C3 extends C2 {} +class C4 extends C2 {} +class C5 extends C3 {} +class Main { + void main() {} +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/EightVariablesWrite.javali b/javali_tests/from_prev_HW/EightVariablesWrite.javali new file mode 100755 index 0000000..e9391ca --- /dev/null +++ b/javali_tests/from_prev_HW/EightVariablesWrite.javali @@ -0,0 +1,20 @@ +/* Test expression evaluation with 8 variables */ +class Main { + void main() { + int r1, r2, r3; + int i0, i1, i2, i3, i4, i5, i6, i7; + + i0 = 0; + i1 = 1; + i2 = 2; + i3 = 3; + i4 = 4; + i5 = 5; + i6 = 6; + i7 = 7; + + write(i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + i7))))))); writeln(); + write(((((((i0 + i1) + i2) + i3) + i4) + i5) + i6) + i7); writeln(); + write(((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7))); writeln(); + } +} diff --git a/javali_tests/from_prev_HW/Expressions.javali b/javali_tests/from_prev_HW/Expressions.javali new file mode 100644 index 0000000..54830ce --- /dev/null +++ b/javali_tests/from_prev_HW/Expressions.javali @@ -0,0 +1,22 @@ +/* testing different expressions +compiler should recognize Type error: Return statement of method with void return type should not have arguments + */ +class Main { + void main() { + return; + return true; + return false; + return 0x10; + return 10; + return variable; + return array[index]; + return methodAccess(); + return object.field; + return object.call(); + return op + op2; + return op / asd * asd && a == true; + return this.run(); + return this; + return this.field; + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/Multiplication.javali b/javali_tests/from_prev_HW/Multiplication.javali new file mode 100755 index 0000000..0c092a6 --- /dev/null +++ b/javali_tests/from_prev_HW/Multiplication.javali @@ -0,0 +1,31 @@ +class Main { + void main() { + int r1; + int i0, i1; + int x,y,z; + + i0 = 5; + i1 = 2; + + r1 = i1 * 3; + write(r1); writeln(); + + r1 = i0 * i1; + write(r1); writeln(); + + r1 = r1 * i0 * i1 * 3; + write(r1); writeln(); + + y = 5; + z = 10; + x = (-y * z); + write(x); writeln(); + + y = 0; + z = - 10; + x = (y * z); + write(x); writeln(); + write(y * z); writeln(); + write(0 * -10); writeln(); + } +} diff --git a/javali_tests/from_prev_HW/NULLTest.javali b/javali_tests/from_prev_HW/NULLTest.javali new file mode 100755 index 0000000..206f3cb --- /dev/null +++ b/javali_tests/from_prev_HW/NULLTest.javali @@ -0,0 +1,20 @@ +/* testing null references: +assigning null to an int or a boolean results in an error +write(null) results in a parser failure + */ +class Main { + void main() { + int a; + boolean b; + Object c; + + a = null; + b = null; + c = null; + + write(a); + writeln(); + //write(null) + + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/OrderOfDeclarations.javali b/javali_tests/from_prev_HW/OrderOfDeclarations.javali new file mode 100644 index 0000000..ea555ab --- /dev/null +++ b/javali_tests/from_prev_HW/OrderOfDeclarations.javali @@ -0,0 +1,8 @@ +/*Check the order of the declarations in the generated parser +* Do the variables come always first or in their place? */ +class ClassName { + void a() {} + int a; + void a() {} + void tests(boolean d, nulle a) {} +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/Overflow.javali b/javali_tests/from_prev_HW/Overflow.javali new file mode 100755 index 0000000..97725ac --- /dev/null +++ b/javali_tests/from_prev_HW/Overflow.javali @@ -0,0 +1,25 @@ +/* Test what happens for Integers that are to big for 32bits +2147483647 (=0x7FFFFFFF) is the biggest integer in 32bits (IntMAX) +*/ +class Main { + void main() { + int x,y,z; + x = 2147483647; + write( x ); writeln(); + /* add 1 to IntMax and output it */ + write( x + 1); writeln(); + + /* read an int bigger than IntMAX */ + x = read(); + write(x); writeln(); + + /* performe some operation that should generate an int overflow */ + x = 21474836400; + y = 60000; + write( x + y); writeln(); + z = 20000000; + write( y * z); writeln(); + write( (y * z) ); writeln(); + + } +} diff --git a/javali_tests/from_prev_HW/Overflow.javali.in b/javali_tests/from_prev_HW/Overflow.javali.in new file mode 100755 index 0000000..a51fa7d --- /dev/null +++ b/javali_tests/from_prev_HW/Overflow.javali.in @@ -0,0 +1 @@ +2147483647 diff --git a/javali_tests/from_prev_HW/ParamLists.javali b/javali_tests/from_prev_HW/ParamLists.javali new file mode 100644 index 0000000..ac19360 --- /dev/null +++ b/javali_tests/from_prev_HW/ParamLists.javali @@ -0,0 +1,15 @@ +/*Testing all related to methods (declaration and execution)*/ +class Main { + void main() { + callWithParams(a, b, c, 0, false); + object.call(a, b, d); + } + + int method(int a, String b, int[] c) { + + } + + int[] method2() {} + Object method3() {} + Model[] method4() {} +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/ReadWrite.javali b/javali_tests/from_prev_HW/ReadWrite.javali new file mode 100755 index 0000000..e9f3944 --- /dev/null +++ b/javali_tests/from_prev_HW/ReadWrite.javali @@ -0,0 +1,26 @@ +/* Test read/write native functions */ +class Main { + void main() { + int r1, r2, readvar, a1; + + r1 = 6; + /* r2 = 22 */ + r2 = read(); + + write(r1); writeln(); // 6 + + /* test expressions inside write() */ + write(r1 - 3); writeln(); // 3 + write(r1 - 6); writeln(); // 0 + write(r1 - 7); writeln(); // -1 + /* should output 111 */ + readvar = read(); // 1 + write( (r1 + (r2 * 5)) + readvar); // 117 + write(- r1); // -6 + writeln(); + /* should output 15 */ + a1 = read(); // -15 + write(- a1); // 15 + + } +} diff --git a/javali_tests/from_prev_HW/ReadWrite.javali.in b/javali_tests/from_prev_HW/ReadWrite.javali.in new file mode 100755 index 0000000..fff4c89 --- /dev/null +++ b/javali_tests/from_prev_HW/ReadWrite.javali.in @@ -0,0 +1,6 @@ + 22 + + + 1 + +-15 diff --git a/javali_tests/from_prev_HW/Statements.javali b/javali_tests/from_prev_HW/Statements.javali new file mode 100644 index 0000000..f5f2279 --- /dev/null +++ b/javali_tests/from_prev_HW/Statements.javali @@ -0,0 +1,34 @@ +/* testing different statements +'condition' is not initialized + */ +class Main { + void main() { + if (condition) { + instructions(); + asd.b = c; + if (cond2) { + + } else { + nonEmptyBlock = a; + } + } else { + + } + // Whiles + while (condition) { + while (anotherLoop == false) { + nestedLoops(); + } + } + while (false) {} // emptyloop + // Returns + return; // empty + return expr; // with expressions (expressions already tested) + return array[index]; + // Writes + write(a); + write(9 + 10); + writeln(); + write(call()); + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/UnaryOperators.javali b/javali_tests/from_prev_HW/UnaryOperators.javali new file mode 100755 index 0000000..4a5485b --- /dev/null +++ b/javali_tests/from_prev_HW/UnaryOperators.javali @@ -0,0 +1,15 @@ +class Main { + void main() { + int a, b; + + a = 1; + b = 2; + + write(+a); writeln(); + write(-a); writeln(); + write(+a --b); writeln(); + write(-a--b); writeln(); + write(-----a-----5--b); writeln(); + write(-----a*---------b);writeln(); + } +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/conditionExpressions.javali b/javali_tests/from_prev_HW/conditionExpressions.javali new file mode 100755 index 0000000..5257a61 --- /dev/null +++ b/javali_tests/from_prev_HW/conditionExpressions.javali @@ -0,0 +1,24 @@ +/* testing conditions*/ +class Main { + void main() { + boolean a; + int b,c, d, e; + b = 10; + c = 3; + d = 40; + e = 1; + + while ( b > c ) { + write(b); + b = b-1; + } + a = c < (b+4-5/2); + if (a){ + write(13);} + if (100/2>d*e){ + while(e0 ) { + a = a-1; + } + + + +} \ No newline at end of file diff --git a/javali_tests/from_prev_HW/noParentheses.javali b/javali_tests/from_prev_HW/noParentheses.javali new file mode 100755 index 0000000..0413586 --- /dev/null +++ b/javali_tests/from_prev_HW/noParentheses.javali @@ -0,0 +1,24 @@ +/* test what happens if there are no parentheses */ + +class Main { + void main() { + int x; + int y; + int z; + + x = 5; + y = 10; + z = 100; + + write( x + y + z); writeln(); + /* */ + write( - x + y - z); writeln(); + + /* should output 205 */ + write( x + 2 * z); writeln(); + + write( x + 2 * z / x + 1); writeln(); + write(+x); writeln(); + + } +} diff --git a/src/cd/Config.java b/src/cd/Config.java index db99934..2655fc1 100644 --- a/src/cd/Config.java +++ b/src/cd/Config.java @@ -10,6 +10,11 @@ public class Config { MACOSX } + /** + * What kind of system we are on + */ + public static final SystemKind systemKind; + /** * Defines the extension used for assembler files on this platform. * Currently always {@code .s}. @@ -79,9 +84,11 @@ public class Config { public static final String JAVA_EXE; static { + final String os = System.getProperty("os.name").toLowerCase(); if(os.contains("windows") || os.contains("nt")) { + systemKind = SystemKind.WINDOWS; BINARYEXT = ".exe"; MAIN = "_main"; PRINTF = "_printf"; @@ -101,6 +108,7 @@ public class Config { COMMENT_SEP = "#"; } else if(os.contains("mac os x") || os.contains("darwin")) { + systemKind = SystemKind.MACOSX; BINARYEXT = ".bin"; MAIN = "_main"; PRINTF = "_printf"; @@ -118,6 +126,7 @@ public class Config { COMMENT_SEP = "#"; } else { + systemKind = SystemKind.LINUX; BINARYEXT = ".bin"; MAIN = "main"; PRINTF = "printf"; diff --git a/src/cd/Main.java b/src/cd/Main.java index e4a1335..16ba79f 100644 --- a/src/cd/Main.java +++ b/src/cd/Main.java @@ -19,7 +19,10 @@ import cd.frontend.parser.JavaliLexer; import cd.frontend.parser.JavaliParser; import cd.frontend.parser.JavaliParser.UnitContext; import cd.frontend.parser.ParseFailure; +import cd.frontend.semantic.SemanticAnalyzer; import cd.ir.Ast.ClassDecl; +import cd.ir.Symbol; +import cd.ir.Symbol.TypeSymbol; import cd.util.debug.AstDump; /** @@ -34,9 +37,15 @@ public class Main { // Set to non-null to write debug info out public Writer debug = null; - // Set to non-null to write dump of control flow graph + // Set to non-null to write dump of control flow graph (Advanced Compiler Design) public File cfgdumpbase; + /** Symbol for the Main type */ + public Symbol.ClassSymbol mainType; + + /** List of all type symbols, used by code generator. */ + public List allTypeSymbols; + public void debug(String format, Object... args) { if (debug != null) { String result = String.format(format, args); @@ -62,6 +71,9 @@ public class Main { // Parse: List astRoots = m.parse(fin); + + // Run the semantic check: + m.semanticCheck(astRoots); } } } @@ -94,7 +106,11 @@ public class Main { } - + public void semanticCheck(List astRoots) { + { + new SemanticAnalyzer(this).check(astRoots); + } + } /** Dumps the AST to the debug stream */ private void dumpAst(List astRoots) throws IOException { diff --git a/src/cd/frontend/parser/Javali.g4 b/src/cd/frontend/parser/Javali.g4 deleted file mode 100644 index 4ea3d4f..0000000 --- a/src/cd/frontend/parser/Javali.g4 +++ /dev/null @@ -1,203 +0,0 @@ -grammar Javali; // parser grammar, parses streams of tokens - -@header { - // Java header - package cd.frontend.parser; -} - - - -// PARSER RULES -literal - : 'null' # NullLiteral - | Boolean # BoolLiteral - | Integer # IntLiteral - ; - -// Types -type - : primitiveType - | referenceType - ; - -referenceType - : Ident - | arrayType - ; - -arrayType - : Ident '[' ']' - | primitiveType '[' ']' - ; - -primitiveType - : 'boolean' - | 'int' - ; - -// Program structure -unit - : classDecl+ EOF - ; - -classDecl - : 'class' Ident ('extends' Ident)? '{' memberList '}' - ; - -memberList - : (varDecl | methodDecl)* - ; - -varDecl - : type Ident (',' Ident)* ';' - ; - -methodDecl - : (type | 'void') Ident '(' formalParamList? ')' '{' varDecl* stmt* '}' - ; - -formalParamList - : type Ident (',' type Ident)* - ; - -// Statements -stmt - : assignmentStmt - | methodCallStmt - | ifStmt - | whileStmt - | returnStmt - | writeStmt - ; - -stmtBlock - : '{' stmt* '}' - ; - -methodCallStmt - : Ident '(' actualParamList? ')' ';' # LocalMethodCallStmt - | identAccess '.' Ident '(' actualParamList? ')' ';' # ObjectMethodCallStmt - ; - -assignmentStmt - : identAccess '=' (expr | newExpr | readExpr) ';' - ; - -writeStmt - : 'write' '(' expr ')' ';' # Write - | 'writeln' '(' ')' ';' # WriteLn - ; - -ifStmt - : 'if' '(' expr ')' stmtBlock ('else' stmtBlock)? - ; - -whileStmt - : 'while' '(' expr ')' stmtBlock - ; - -returnStmt - : 'return' expr? ';' - ; - -// Expressions -newExpr - : 'new' Ident '(' ')' # NewObject - | 'new' Ident '[' expr ']' # NewObjectArray - | 'new' primitiveType '[' expr ']' # NewPrimitiveArray - ; - -readExpr - : 'read' '(' ')' - ; - -actualParamList - : expr (',' expr)* - ; - -identAccess - : Ident # AccessLocalField - | 'this' # AccessThis - | identAccess '.' Ident # AccessObjectField - | identAccess '[' expr ']' # AccessArray - | Ident '(' actualParamList? ')' # AccessLocalMethod - | identAccess '.' Ident '(' actualParamList? ')'# AccessObjectMethod - ; - -expr - : literal # ExprConstant - | identAccess # ExprIdentAccess - | '(' expr ')' # ExprParentheses - | ('+'|'-'|'!') expr # ExprUnary - | '(' referenceType ')' expr # ExprCast - | expr ('*'|'/'|'%') expr # ExprBinary - | expr ('+'|'-') expr # ExprBinary - | expr ('<'|'>'|'<='|'>=') expr # ExprBinary - | expr ('=='|'!=') expr # ExprBinary - | expr '&&' expr # ExprBinary - | expr '||' expr # ExprBinary - ; - - -// LEXER RULES -fragment -Letter - : 'A'..'Z' - | 'a'..'z' - ; - -fragment -Digit - : '0'..'9' - ; - -fragment -HexDigit - : Digit - | 'a'..'f' - | 'A'..'F' - ; - -fragment -Decimal - : '0' - | '1'..'9' Digit* - ; - -fragment -Hexadecimal - : ('0x'|'0X') HexDigit+ - ; - -Integer - : Decimal - | Hexadecimal - ; - -Boolean - : 'false' - | 'true' - ; - -Ident - : Letter (Letter|Digit)* - ; - - - -// comments and white space does not produce tokens: -COMMENT - : '/*' .*? '*/' -> skip - ; - -LINE_COMMENT - : '//' ~('\n'|'\r')* -> skip - ; - -WS - : (' '|'\r'|'\t'|'\n') -> skip - ; - - -// handle characters which failed to match any other token -ErrorCharacter : . ; diff --git a/src/cd/frontend/parser/Javali.interp b/src/cd/frontend/parser/Javali.interp deleted file mode 100644 index 639ff83..0000000 --- a/src/cd/frontend/parser/Javali.interp +++ /dev/null @@ -1,127 +0,0 @@ -token literal names: -null -'null' -'[' -']' -'boolean' -'int' -'class' -'extends' -'{' -'}' -',' -';' -'void' -'(' -')' -'.' -'=' -'write' -'writeln' -'if' -'else' -'while' -'return' -'new' -'read' -'this' -'+' -'-' -'!' -'*' -'/' -'%' -'<' -'>' -'<=' -'>=' -'==' -'!=' -'&&' -'||' -null -null -null -null -null -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -Integer -Boolean -Ident -COMMENT -LINE_COMMENT -WS -ErrorCharacter - -rule names: -literal -type -referenceType -arrayType -primitiveType -unit -classDecl -memberList -varDecl -methodDecl -formalParamList -stmt -stmtBlock -methodCallStmt -assignmentStmt -writeStmt -ifStmt -whileStmt -returnStmt -newExpr -readExpr -actualParamList -identAccess -expr - - -atn: -[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 48, 325, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 3, 2, 3, 2, 3, 2, 5, 2, 54, 10, 2, 3, 3, 3, 3, 5, 3, 58, 10, 3, 3, 4, 3, 4, 5, 4, 62, 10, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 71, 10, 5, 3, 6, 3, 6, 3, 7, 6, 7, 76, 10, 7, 13, 7, 14, 7, 77, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 5, 8, 86, 10, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 7, 9, 94, 10, 9, 12, 9, 14, 9, 97, 11, 9, 3, 10, 3, 10, 3, 10, 3, 10, 7, 10, 103, 10, 10, 12, 10, 14, 10, 106, 11, 10, 3, 10, 3, 10, 3, 11, 3, 11, 5, 11, 112, 10, 11, 3, 11, 3, 11, 3, 11, 5, 11, 117, 10, 11, 3, 11, 3, 11, 3, 11, 7, 11, 122, 10, 11, 12, 11, 14, 11, 125, 11, 11, 3, 11, 7, 11, 128, 10, 11, 12, 11, 14, 11, 131, 11, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 7, 12, 141, 10, 12, 12, 12, 14, 12, 144, 11, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 5, 13, 152, 10, 13, 3, 14, 3, 14, 7, 14, 156, 10, 14, 12, 14, 14, 14, 159, 11, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 5, 15, 166, 10, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 5, 15, 175, 10, 15, 3, 15, 3, 15, 3, 15, 5, 15, 180, 10, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 5, 16, 187, 10, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 5, 17, 201, 10, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 5, 18, 210, 10, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 5, 20, 220, 10, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 5, 21, 240, 10, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 23, 7, 23, 249, 10, 23, 12, 23, 14, 23, 252, 11, 23, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 5, 24, 260, 10, 24, 3, 24, 5, 24, 263, 10, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 5, 24, 278, 10, 24, 3, 24, 7, 24, 281, 10, 24, 12, 24, 14, 24, 284, 11, 24, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 5, 25, 300, 10, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 7, 25, 320, 10, 25, 12, 25, 14, 25, 323, 11, 25, 3, 25, 2, 4, 46, 48, 26, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 2, 8, 3, 2, 6, 7, 3, 2, 28, 30, 3, 2, 31, 33, 3, 2, 28, 29, 3, 2, 34, 37, 3, 2, 38, 39, 2, 349, 2, 53, 3, 2, 2, 2, 4, 57, 3, 2, 2, 2, 6, 61, 3, 2, 2, 2, 8, 70, 3, 2, 2, 2, 10, 72, 3, 2, 2, 2, 12, 75, 3, 2, 2, 2, 14, 81, 3, 2, 2, 2, 16, 95, 3, 2, 2, 2, 18, 98, 3, 2, 2, 2, 20, 111, 3, 2, 2, 2, 22, 134, 3, 2, 2, 2, 24, 151, 3, 2, 2, 2, 26, 153, 3, 2, 2, 2, 28, 179, 3, 2, 2, 2, 30, 181, 3, 2, 2, 2, 32, 200, 3, 2, 2, 2, 34, 202, 3, 2, 2, 2, 36, 211, 3, 2, 2, 2, 38, 217, 3, 2, 2, 2, 40, 239, 3, 2, 2, 2, 42, 241, 3, 2, 2, 2, 44, 245, 3, 2, 2, 2, 46, 262, 3, 2, 2, 2, 48, 299, 3, 2, 2, 2, 50, 54, 7, 3, 2, 2, 51, 54, 7, 43, 2, 2, 52, 54, 7, 42, 2, 2, 53, 50, 3, 2, 2, 2, 53, 51, 3, 2, 2, 2, 53, 52, 3, 2, 2, 2, 54, 3, 3, 2, 2, 2, 55, 58, 5, 10, 6, 2, 56, 58, 5, 6, 4, 2, 57, 55, 3, 2, 2, 2, 57, 56, 3, 2, 2, 2, 58, 5, 3, 2, 2, 2, 59, 62, 7, 44, 2, 2, 60, 62, 5, 8, 5, 2, 61, 59, 3, 2, 2, 2, 61, 60, 3, 2, 2, 2, 62, 7, 3, 2, 2, 2, 63, 64, 7, 44, 2, 2, 64, 65, 7, 4, 2, 2, 65, 71, 7, 5, 2, 2, 66, 67, 5, 10, 6, 2, 67, 68, 7, 4, 2, 2, 68, 69, 7, 5, 2, 2, 69, 71, 3, 2, 2, 2, 70, 63, 3, 2, 2, 2, 70, 66, 3, 2, 2, 2, 71, 9, 3, 2, 2, 2, 72, 73, 9, 2, 2, 2, 73, 11, 3, 2, 2, 2, 74, 76, 5, 14, 8, 2, 75, 74, 3, 2, 2, 2, 76, 77, 3, 2, 2, 2, 77, 75, 3, 2, 2, 2, 77, 78, 3, 2, 2, 2, 78, 79, 3, 2, 2, 2, 79, 80, 7, 2, 2, 3, 80, 13, 3, 2, 2, 2, 81, 82, 7, 8, 2, 2, 82, 85, 7, 44, 2, 2, 83, 84, 7, 9, 2, 2, 84, 86, 7, 44, 2, 2, 85, 83, 3, 2, 2, 2, 85, 86, 3, 2, 2, 2, 86, 87, 3, 2, 2, 2, 87, 88, 7, 10, 2, 2, 88, 89, 5, 16, 9, 2, 89, 90, 7, 11, 2, 2, 90, 15, 3, 2, 2, 2, 91, 94, 5, 18, 10, 2, 92, 94, 5, 20, 11, 2, 93, 91, 3, 2, 2, 2, 93, 92, 3, 2, 2, 2, 94, 97, 3, 2, 2, 2, 95, 93, 3, 2, 2, 2, 95, 96, 3, 2, 2, 2, 96, 17, 3, 2, 2, 2, 97, 95, 3, 2, 2, 2, 98, 99, 5, 4, 3, 2, 99, 104, 7, 44, 2, 2, 100, 101, 7, 12, 2, 2, 101, 103, 7, 44, 2, 2, 102, 100, 3, 2, 2, 2, 103, 106, 3, 2, 2, 2, 104, 102, 3, 2, 2, 2, 104, 105, 3, 2, 2, 2, 105, 107, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 107, 108, 7, 13, 2, 2, 108, 19, 3, 2, 2, 2, 109, 112, 5, 4, 3, 2, 110, 112, 7, 14, 2, 2, 111, 109, 3, 2, 2, 2, 111, 110, 3, 2, 2, 2, 112, 113, 3, 2, 2, 2, 113, 114, 7, 44, 2, 2, 114, 116, 7, 15, 2, 2, 115, 117, 5, 22, 12, 2, 116, 115, 3, 2, 2, 2, 116, 117, 3, 2, 2, 2, 117, 118, 3, 2, 2, 2, 118, 119, 7, 16, 2, 2, 119, 123, 7, 10, 2, 2, 120, 122, 5, 18, 10, 2, 121, 120, 3, 2, 2, 2, 122, 125, 3, 2, 2, 2, 123, 121, 3, 2, 2, 2, 123, 124, 3, 2, 2, 2, 124, 129, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 126, 128, 5, 24, 13, 2, 127, 126, 3, 2, 2, 2, 128, 131, 3, 2, 2, 2, 129, 127, 3, 2, 2, 2, 129, 130, 3, 2, 2, 2, 130, 132, 3, 2, 2, 2, 131, 129, 3, 2, 2, 2, 132, 133, 7, 11, 2, 2, 133, 21, 3, 2, 2, 2, 134, 135, 5, 4, 3, 2, 135, 142, 7, 44, 2, 2, 136, 137, 7, 12, 2, 2, 137, 138, 5, 4, 3, 2, 138, 139, 7, 44, 2, 2, 139, 141, 3, 2, 2, 2, 140, 136, 3, 2, 2, 2, 141, 144, 3, 2, 2, 2, 142, 140, 3, 2, 2, 2, 142, 143, 3, 2, 2, 2, 143, 23, 3, 2, 2, 2, 144, 142, 3, 2, 2, 2, 145, 152, 5, 30, 16, 2, 146, 152, 5, 28, 15, 2, 147, 152, 5, 34, 18, 2, 148, 152, 5, 36, 19, 2, 149, 152, 5, 38, 20, 2, 150, 152, 5, 32, 17, 2, 151, 145, 3, 2, 2, 2, 151, 146, 3, 2, 2, 2, 151, 147, 3, 2, 2, 2, 151, 148, 3, 2, 2, 2, 151, 149, 3, 2, 2, 2, 151, 150, 3, 2, 2, 2, 152, 25, 3, 2, 2, 2, 153, 157, 7, 10, 2, 2, 154, 156, 5, 24, 13, 2, 155, 154, 3, 2, 2, 2, 156, 159, 3, 2, 2, 2, 157, 155, 3, 2, 2, 2, 157, 158, 3, 2, 2, 2, 158, 160, 3, 2, 2, 2, 159, 157, 3, 2, 2, 2, 160, 161, 7, 11, 2, 2, 161, 27, 3, 2, 2, 2, 162, 163, 7, 44, 2, 2, 163, 165, 7, 15, 2, 2, 164, 166, 5, 44, 23, 2, 165, 164, 3, 2, 2, 2, 165, 166, 3, 2, 2, 2, 166, 167, 3, 2, 2, 2, 167, 168, 7, 16, 2, 2, 168, 180, 7, 13, 2, 2, 169, 170, 5, 46, 24, 2, 170, 171, 7, 17, 2, 2, 171, 172, 7, 44, 2, 2, 172, 174, 7, 15, 2, 2, 173, 175, 5, 44, 23, 2, 174, 173, 3, 2, 2, 2, 174, 175, 3, 2, 2, 2, 175, 176, 3, 2, 2, 2, 176, 177, 7, 16, 2, 2, 177, 178, 7, 13, 2, 2, 178, 180, 3, 2, 2, 2, 179, 162, 3, 2, 2, 2, 179, 169, 3, 2, 2, 2, 180, 29, 3, 2, 2, 2, 181, 182, 5, 46, 24, 2, 182, 186, 7, 18, 2, 2, 183, 187, 5, 48, 25, 2, 184, 187, 5, 40, 21, 2, 185, 187, 5, 42, 22, 2, 186, 183, 3, 2, 2, 2, 186, 184, 3, 2, 2, 2, 186, 185, 3, 2, 2, 2, 187, 188, 3, 2, 2, 2, 188, 189, 7, 13, 2, 2, 189, 31, 3, 2, 2, 2, 190, 191, 7, 19, 2, 2, 191, 192, 7, 15, 2, 2, 192, 193, 5, 48, 25, 2, 193, 194, 7, 16, 2, 2, 194, 195, 7, 13, 2, 2, 195, 201, 3, 2, 2, 2, 196, 197, 7, 20, 2, 2, 197, 198, 7, 15, 2, 2, 198, 199, 7, 16, 2, 2, 199, 201, 7, 13, 2, 2, 200, 190, 3, 2, 2, 2, 200, 196, 3, 2, 2, 2, 201, 33, 3, 2, 2, 2, 202, 203, 7, 21, 2, 2, 203, 204, 7, 15, 2, 2, 204, 205, 5, 48, 25, 2, 205, 206, 7, 16, 2, 2, 206, 209, 5, 26, 14, 2, 207, 208, 7, 22, 2, 2, 208, 210, 5, 26, 14, 2, 209, 207, 3, 2, 2, 2, 209, 210, 3, 2, 2, 2, 210, 35, 3, 2, 2, 2, 211, 212, 7, 23, 2, 2, 212, 213, 7, 15, 2, 2, 213, 214, 5, 48, 25, 2, 214, 215, 7, 16, 2, 2, 215, 216, 5, 26, 14, 2, 216, 37, 3, 2, 2, 2, 217, 219, 7, 24, 2, 2, 218, 220, 5, 48, 25, 2, 219, 218, 3, 2, 2, 2, 219, 220, 3, 2, 2, 2, 220, 221, 3, 2, 2, 2, 221, 222, 7, 13, 2, 2, 222, 39, 3, 2, 2, 2, 223, 224, 7, 25, 2, 2, 224, 225, 7, 44, 2, 2, 225, 226, 7, 15, 2, 2, 226, 240, 7, 16, 2, 2, 227, 228, 7, 25, 2, 2, 228, 229, 7, 44, 2, 2, 229, 230, 7, 4, 2, 2, 230, 231, 5, 48, 25, 2, 231, 232, 7, 5, 2, 2, 232, 240, 3, 2, 2, 2, 233, 234, 7, 25, 2, 2, 234, 235, 5, 10, 6, 2, 235, 236, 7, 4, 2, 2, 236, 237, 5, 48, 25, 2, 237, 238, 7, 5, 2, 2, 238, 240, 3, 2, 2, 2, 239, 223, 3, 2, 2, 2, 239, 227, 3, 2, 2, 2, 239, 233, 3, 2, 2, 2, 240, 41, 3, 2, 2, 2, 241, 242, 7, 26, 2, 2, 242, 243, 7, 15, 2, 2, 243, 244, 7, 16, 2, 2, 244, 43, 3, 2, 2, 2, 245, 250, 5, 48, 25, 2, 246, 247, 7, 12, 2, 2, 247, 249, 5, 48, 25, 2, 248, 246, 3, 2, 2, 2, 249, 252, 3, 2, 2, 2, 250, 248, 3, 2, 2, 2, 250, 251, 3, 2, 2, 2, 251, 45, 3, 2, 2, 2, 252, 250, 3, 2, 2, 2, 253, 254, 8, 24, 1, 2, 254, 263, 7, 44, 2, 2, 255, 263, 7, 27, 2, 2, 256, 257, 7, 44, 2, 2, 257, 259, 7, 15, 2, 2, 258, 260, 5, 44, 23, 2, 259, 258, 3, 2, 2, 2, 259, 260, 3, 2, 2, 2, 260, 261, 3, 2, 2, 2, 261, 263, 7, 16, 2, 2, 262, 253, 3, 2, 2, 2, 262, 255, 3, 2, 2, 2, 262, 256, 3, 2, 2, 2, 263, 282, 3, 2, 2, 2, 264, 265, 12, 6, 2, 2, 265, 266, 7, 17, 2, 2, 266, 281, 7, 44, 2, 2, 267, 268, 12, 5, 2, 2, 268, 269, 7, 4, 2, 2, 269, 270, 5, 48, 25, 2, 270, 271, 7, 5, 2, 2, 271, 281, 3, 2, 2, 2, 272, 273, 12, 3, 2, 2, 273, 274, 7, 17, 2, 2, 274, 275, 7, 44, 2, 2, 275, 277, 7, 15, 2, 2, 276, 278, 5, 44, 23, 2, 277, 276, 3, 2, 2, 2, 277, 278, 3, 2, 2, 2, 278, 279, 3, 2, 2, 2, 279, 281, 7, 16, 2, 2, 280, 264, 3, 2, 2, 2, 280, 267, 3, 2, 2, 2, 280, 272, 3, 2, 2, 2, 281, 284, 3, 2, 2, 2, 282, 280, 3, 2, 2, 2, 282, 283, 3, 2, 2, 2, 283, 47, 3, 2, 2, 2, 284, 282, 3, 2, 2, 2, 285, 286, 8, 25, 1, 2, 286, 300, 5, 2, 2, 2, 287, 300, 5, 46, 24, 2, 288, 289, 7, 15, 2, 2, 289, 290, 5, 48, 25, 2, 290, 291, 7, 16, 2, 2, 291, 300, 3, 2, 2, 2, 292, 293, 9, 3, 2, 2, 293, 300, 5, 48, 25, 10, 294, 295, 7, 15, 2, 2, 295, 296, 5, 6, 4, 2, 296, 297, 7, 16, 2, 2, 297, 298, 5, 48, 25, 9, 298, 300, 3, 2, 2, 2, 299, 285, 3, 2, 2, 2, 299, 287, 3, 2, 2, 2, 299, 288, 3, 2, 2, 2, 299, 292, 3, 2, 2, 2, 299, 294, 3, 2, 2, 2, 300, 321, 3, 2, 2, 2, 301, 302, 12, 8, 2, 2, 302, 303, 9, 4, 2, 2, 303, 320, 5, 48, 25, 9, 304, 305, 12, 7, 2, 2, 305, 306, 9, 5, 2, 2, 306, 320, 5, 48, 25, 8, 307, 308, 12, 6, 2, 2, 308, 309, 9, 6, 2, 2, 309, 320, 5, 48, 25, 7, 310, 311, 12, 5, 2, 2, 311, 312, 9, 7, 2, 2, 312, 320, 5, 48, 25, 6, 313, 314, 12, 4, 2, 2, 314, 315, 7, 40, 2, 2, 315, 320, 5, 48, 25, 5, 316, 317, 12, 3, 2, 2, 317, 318, 7, 41, 2, 2, 318, 320, 5, 48, 25, 4, 319, 301, 3, 2, 2, 2, 319, 304, 3, 2, 2, 2, 319, 307, 3, 2, 2, 2, 319, 310, 3, 2, 2, 2, 319, 313, 3, 2, 2, 2, 319, 316, 3, 2, 2, 2, 320, 323, 3, 2, 2, 2, 321, 319, 3, 2, 2, 2, 321, 322, 3, 2, 2, 2, 322, 49, 3, 2, 2, 2, 323, 321, 3, 2, 2, 2, 35, 53, 57, 61, 70, 77, 85, 93, 95, 104, 111, 116, 123, 129, 142, 151, 157, 165, 174, 179, 186, 200, 209, 219, 239, 250, 259, 262, 277, 280, 282, 299, 319, 321] \ No newline at end of file diff --git a/src/cd/frontend/parser/Javali.tokens b/src/cd/frontend/parser/Javali.tokens deleted file mode 100644 index 0bd9b31..0000000 --- a/src/cd/frontend/parser/Javali.tokens +++ /dev/null @@ -1,85 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -T__27=28 -T__28=29 -T__29=30 -T__30=31 -T__31=32 -T__32=33 -T__33=34 -T__34=35 -T__35=36 -T__36=37 -T__37=38 -T__38=39 -Integer=40 -Boolean=41 -Ident=42 -COMMENT=43 -LINE_COMMENT=44 -WS=45 -ErrorCharacter=46 -'null'=1 -'['=2 -']'=3 -'boolean'=4 -'int'=5 -'class'=6 -'extends'=7 -'{'=8 -'}'=9 -','=10 -';'=11 -'void'=12 -'('=13 -')'=14 -'.'=15 -'='=16 -'write'=17 -'writeln'=18 -'if'=19 -'else'=20 -'while'=21 -'return'=22 -'new'=23 -'read'=24 -'this'=25 -'+'=26 -'-'=27 -'!'=28 -'*'=29 -'/'=30 -'%'=31 -'<'=32 -'>'=33 -'<='=34 -'>='=35 -'=='=36 -'!='=37 -'&&'=38 -'||'=39 diff --git a/src/cd/frontend/parser/JavaliAstVisitor.java b/src/cd/frontend/parser/JavaliAstVisitor.java deleted file mode 100644 index f9b3559..0000000 --- a/src/cd/frontend/parser/JavaliAstVisitor.java +++ /dev/null @@ -1,329 +0,0 @@ -package cd.frontend.parser; - -import cd.frontend.parser.JavaliParser.*; -import cd.ir.Ast; -import cd.ir.Ast.*; -import cd.ir.Ast.BinaryOp.BOp; -import cd.ir.Ast.UnaryOp.UOp; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.TerminalNode; - -import java.util.ArrayList; -import java.util.List; - -public final class JavaliAstVisitor extends JavaliBaseVisitor { - - public List classDecls = new ArrayList<>(); - - @Override - public Ast visitUnit(UnitContext ctx) { - for (ClassDeclContext classDeclContext : ctx.classDecl()) - classDecls.add((ClassDecl) visit(classDeclContext)); - return new Seq(new ArrayList<>(classDecls)); - } - - @Override - public Ast visitClassDecl(ClassDeclContext ctx) { - String name = ctx.Ident(0).getText(); - String superClass = "Object"; // Common superclass - if (ctx.Ident().size() == 2) - superClass = ctx.Ident(1).getText(); - Seq members = (Seq) visit(ctx.memberList()); - return new ClassDecl(name, superClass, members.children()); - } - - @Override - public Ast visitMemberList(MemberListContext ctx) { - if (ctx.children == null) { - return new Seq(new ArrayList<>()); - } - List list = new ArrayList<>(ctx.children.size()); - for (ParseTree parseTree : ctx.children) { - if (parseTree instanceof VarDeclContext) { - Seq seqVars = (Seq) visit(parseTree); - list.addAll(seqVars.children()); - } else { - assert parseTree instanceof MethodDeclContext; - list.add(visit(parseTree)); - } - } - return new Seq(list); - } - - @Override - public Ast visitVarDecl(VarDeclContext ctx) { - List list = new ArrayList<>(ctx.Ident().size()); - String type = ctx.type().getText(); - for (TerminalNode n : ctx.Ident()) - list.add(new VarDecl(type, n.getText())); - return new Seq(list); - } - - @Override - public Ast visitMethodDecl(MethodDeclContext ctx) { - List argumentTypes = new ArrayList<>(); - List argumentNames = new ArrayList<>(); - if (ctx.formalParamList() != null) { - Seq paramList = (Seq) visit(ctx.formalParamList()); - for (Ast ast : paramList.children()) { - VarDecl var = (VarDecl) ast; - argumentNames.add(var.name); - argumentTypes.add(var.type); - } - } - - List decls = new ArrayList<>(ctx.varDecl().size()); - for (VarDeclContext varDecl : ctx.varDecl()) { - Seq declarationSeq = (Seq) visit(varDecl); - decls.addAll(declarationSeq.children()); - } - - List stmts = new ArrayList<>(ctx.stmt().size()); - for (StmtContext s : ctx.stmt()) - stmts.add(visit(s)); - - return new MethodDecl( - ctx.type() == null ? "void" : ctx.type().getText(), - ctx.Ident().getText(), - argumentTypes, - argumentNames, - new Seq(decls), - new Seq(stmts) - ); - } - - @Override - public Ast visitFormalParamList(FormalParamListContext ctx) { - List list = new ArrayList<>(ctx.type().size()); - for (int i = 0; i < ctx.type().size(); i++) { - String type = ctx.type(i).getText(); - String name = ctx.Ident(i).getText(); - list.add(new VarDecl(type, name)); - } - return new Seq(list); - } - - @Override - public Ast visitStmt(StmtContext ctx) { - return visit(ctx.children.get(0)); - } - - @Override - public Ast visitStmtBlock(StmtBlockContext ctx) { - List list = new ArrayList<>(ctx.stmt().size()); - for (StmtContext stmtContext : ctx.stmt()) - list.add(visit(stmtContext)); - return new Seq(list); - } - - @Override - public Ast visitLocalMethodCallStmt(LocalMethodCallStmtContext ctx) { - return new MethodCall(new MethodCallExpr( - new ThisRef(), - ctx.Ident().getText(), - getParams(ctx.actualParamList()) - )); - } - - @Override - public Ast visitObjectMethodCallStmt(ObjectMethodCallStmtContext ctx) { - return new MethodCall(new MethodCallExpr( - (Expr) visit(ctx.identAccess()), - ctx.Ident().getText(), - getParams(ctx.actualParamList()) - )); - } - - @Override - public Ast visitAssignmentStmt(AssignmentStmtContext ctx) { - Expr left = (Expr) visit(ctx.children.get(0)); - Expr right = (Expr) visit(ctx.children.get(2)); - return new Assign(left, right); - } - - @Override - public Ast visitWrite(WriteContext ctx) { - return new BuiltInWrite((Expr) visit(ctx.expr())); - } - - @Override - public Ast visitWriteLn(WriteLnContext ctx) { - return new BuiltInWriteln(); - } - - @Override - public Ast visitIfStmt(IfStmtContext ctx) { - Expr condition = (Expr) visit(ctx.expr()); - Ast then = visit(ctx.stmtBlock(0)); - Ast otherwise = new Nop(); - if (ctx.stmtBlock().size() == 2) - otherwise = visit(ctx.stmtBlock(1)); - return new IfElse(condition, then, otherwise); - } - - @Override - public Ast visitWhileStmt(WhileStmtContext ctx) { - Expr condition = (Expr) visit(ctx.expr()); - Ast body = visit(ctx.stmtBlock()); - return new WhileLoop(condition, body); - } - - @Override - public Ast visitReturnStmt(ReturnStmtContext ctx) { - if (ctx.expr() != null) - return new ReturnStmt((Expr) visit(ctx.expr())); - else - return new ReturnStmt(null); - } - - @Override - public Ast visitNewObject(NewObjectContext ctx) { - return new NewObject(ctx.Ident().getText()); - } - - @Override - public Ast visitNewObjectArray(NewObjectArrayContext ctx) { - String type = ctx.Ident().getText(); - Expr size = (Expr) visit(ctx.expr()); - return new NewArray(type + "[]", size); - } - - @Override - public Ast visitNewPrimitiveArray(NewPrimitiveArrayContext ctx) { - String type = ctx.primitiveType().getText(); - Expr size = (Expr) visit(ctx.expr()); - return new NewArray(type + "[]", size); - } - - @Override - public Ast visitReadExpr(ReadExprContext ctx) { - return new BuiltInRead(); - } - - @Override - public Ast visitActualParamList(ActualParamListContext ctx) { - List list = new ArrayList<>(ctx.expr().size()); - for (ExprContext exprContext : ctx.expr()) - list.add(visit(exprContext)); - return new Seq(list); - } - - @Override - public Ast visitAccessThis(AccessThisContext ctx) { - return new ThisRef(); - } - - @Override - public Ast visitAccessLocalField(AccessLocalFieldContext ctx) { - return new Var(ctx.Ident().getText()); - } - - @Override - public Ast visitAccessObjectField(AccessObjectFieldContext ctx) { - Expr arg = (Expr) visit(ctx.identAccess()); - String fieldName = ctx.Ident().getText(); - return new Field(arg, fieldName); - } - - @Override - public Ast visitAccessLocalMethod(AccessLocalMethodContext ctx) { - return new MethodCallExpr( - new ThisRef(), - ctx.Ident().getText(), - getParams(ctx.actualParamList()) - ); - } - - @Override - public Ast visitAccessArray(AccessArrayContext ctx) { - Expr array = (Expr) visit(ctx.identAccess()); - Expr index = (Expr) visit(ctx.expr()); - return new Index(array, index); - } - - @Override - public Ast visitAccessObjectMethod(AccessObjectMethodContext ctx) { - return new MethodCallExpr( - (Expr) visit(ctx.identAccess()), - ctx.Ident().getText(), - getParams(ctx.actualParamList()) - ); - } - - @Override - public Ast visitExprBinary(ExprBinaryContext ctx) { - Expr left = (Expr) visit(ctx.expr(0)); - Expr right = (Expr) visit(ctx.expr(1)); - String op = ctx.getChild(1).getText(); - for (BOp bop : BOp.values()) - if (bop.repr.equals(op)) - return new BinaryOp(left, bop, right); - throw new RuntimeException("BOp enum is inconsistent with grammar"); - } - - @Override - public Ast visitExprCast(ExprCastContext ctx) { - Expr arg = (Expr) visit(ctx.expr()); - String typeName = ctx.referenceType().getText(); - return new Cast(arg, typeName); - } - - @Override - public Ast visitExprParentheses(ExprParenthesesContext ctx) { - return visit(ctx.expr()); - } - - @Override - public Ast visitExprUnary(ExprUnaryContext ctx) { - Expr expr = (Expr) visit(ctx.expr()); - String op = ctx.getChild(0).getText(); - for (UOp uop : UOp.values()) - if (uop.repr.equals(op)) - return new UnaryOp(uop, expr); - throw new RuntimeException("UOp enum is inconsistent with grammar"); - } - - @Override - public Ast visitExprConstant(ExprConstantContext ctx) { - return visit(ctx.literal()); - } - - @Override - public Ast visitNullLiteral(NullLiteralContext ctx) { - return new NullConst(); - } - - @Override - public Ast visitBoolLiteral(BoolLiteralContext ctx) { - return new BooleanConst(ctx.Boolean().getText().equals("true")); - } - - @Override - public Ast visitIntLiteral(IntLiteralContext ctx) { - try { - return new IntConst(Integer.decode(ctx.Integer().getText())); - } catch (NumberFormatException exception) { - throw new ParseFailure(ctx.start.getLine(), "Value not in 32bit signed int range"); - } - } - - @Override - public Ast visitExprIdentAccess(ExprIdentAccessContext ctx) { - return visit(ctx.identAccess()); - } - - /** - * Obtain the parameters for a method call - * @param paramListContext Formal parameter list from the ANTRL tree - * @return List of parameters for the method call - */ - private List getParams(ActualParamListContext paramListContext) { - List paramList = new ArrayList<>(); - if (paramListContext != null) { - Seq paramSeq = (Seq) visit(paramListContext); - for (Ast ast : paramSeq.children()) - paramList.add((Expr) ast); - } - return paramList; - } -} diff --git a/src/cd/frontend/parser/JavaliBaseVisitor.java b/src/cd/frontend/parser/JavaliBaseVisitor.java deleted file mode 100644 index a3a15ac..0000000 --- a/src/cd/frontend/parser/JavaliBaseVisitor.java +++ /dev/null @@ -1,297 +0,0 @@ -// Generated from /home/carlos/eth/cd/nop90/HW2/src/cd/frontend/parser/Javali.g4 by ANTLR 4.7.1 - - // Java header - package cd.frontend.parser; - -import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; - -/** - * This class provides an empty implementation of {@link JavaliVisitor}, - * which can be extended to create a visitor which only needs to handle a subset - * of the available methods. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public class JavaliBaseVisitor extends AbstractParseTreeVisitor implements JavaliVisitor { - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitNullLiteral(JavaliParser.NullLiteralContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitBoolLiteral(JavaliParser.BoolLiteralContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitIntLiteral(JavaliParser.IntLiteralContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitType(JavaliParser.TypeContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitReferenceType(JavaliParser.ReferenceTypeContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitArrayType(JavaliParser.ArrayTypeContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitPrimitiveType(JavaliParser.PrimitiveTypeContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitUnit(JavaliParser.UnitContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitClassDecl(JavaliParser.ClassDeclContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitMemberList(JavaliParser.MemberListContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitVarDecl(JavaliParser.VarDeclContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitMethodDecl(JavaliParser.MethodDeclContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitFormalParamList(JavaliParser.FormalParamListContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitStmt(JavaliParser.StmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitStmtBlock(JavaliParser.StmtBlockContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitLocalMethodCallStmt(JavaliParser.LocalMethodCallStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitObjectMethodCallStmt(JavaliParser.ObjectMethodCallStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAssignmentStmt(JavaliParser.AssignmentStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitWrite(JavaliParser.WriteContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitWriteLn(JavaliParser.WriteLnContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitIfStmt(JavaliParser.IfStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitWhileStmt(JavaliParser.WhileStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitReturnStmt(JavaliParser.ReturnStmtContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitNewObject(JavaliParser.NewObjectContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitNewObjectArray(JavaliParser.NewObjectArrayContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitNewPrimitiveArray(JavaliParser.NewPrimitiveArrayContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitReadExpr(JavaliParser.ReadExprContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitActualParamList(JavaliParser.ActualParamListContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessThis(JavaliParser.AccessThisContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessLocalField(JavaliParser.AccessLocalFieldContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessObjectField(JavaliParser.AccessObjectFieldContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessLocalMethod(JavaliParser.AccessLocalMethodContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessArray(JavaliParser.AccessArrayContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitAccessObjectMethod(JavaliParser.AccessObjectMethodContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprBinary(JavaliParser.ExprBinaryContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprCast(JavaliParser.ExprCastContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprParentheses(JavaliParser.ExprParenthesesContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprUnary(JavaliParser.ExprUnaryContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprConstant(JavaliParser.ExprConstantContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitExprIdentAccess(JavaliParser.ExprIdentAccessContext ctx) { return visitChildren(ctx); } -} \ No newline at end of file diff --git a/src/cd/frontend/parser/JavaliLexer.interp b/src/cd/frontend/parser/JavaliLexer.interp deleted file mode 100644 index 6244602..0000000 --- a/src/cd/frontend/parser/JavaliLexer.interp +++ /dev/null @@ -1,160 +0,0 @@ -token literal names: -null -'null' -'[' -']' -'boolean' -'int' -'class' -'extends' -'{' -'}' -',' -';' -'void' -'(' -')' -'.' -'=' -'write' -'writeln' -'if' -'else' -'while' -'return' -'new' -'read' -'this' -'+' -'-' -'!' -'*' -'/' -'%' -'<' -'>' -'<=' -'>=' -'==' -'!=' -'&&' -'||' -null -null -null -null -null -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -Integer -Boolean -Ident -COMMENT -LINE_COMMENT -WS -ErrorCharacter - -rule names: -T__0 -T__1 -T__2 -T__3 -T__4 -T__5 -T__6 -T__7 -T__8 -T__9 -T__10 -T__11 -T__12 -T__13 -T__14 -T__15 -T__16 -T__17 -T__18 -T__19 -T__20 -T__21 -T__22 -T__23 -T__24 -T__25 -T__26 -T__27 -T__28 -T__29 -T__30 -T__31 -T__32 -T__33 -T__34 -T__35 -T__36 -T__37 -T__38 -Letter -Digit -HexDigit -Decimal -Hexadecimal -Integer -Boolean -Ident -COMMENT -LINE_COMMENT -WS -ErrorCharacter - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 48, 327, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 4, 34, 9, 34, 4, 35, 9, 35, 4, 36, 9, 36, 4, 37, 9, 37, 4, 38, 9, 38, 4, 39, 9, 39, 4, 40, 9, 40, 4, 41, 9, 41, 4, 42, 9, 42, 4, 43, 9, 43, 4, 44, 9, 44, 4, 45, 9, 45, 4, 46, 9, 46, 4, 47, 9, 47, 4, 48, 9, 48, 4, 49, 9, 49, 4, 50, 9, 50, 4, 51, 9, 51, 4, 52, 9, 52, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 3, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 3, 24, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 3, 26, 3, 26, 3, 27, 3, 27, 3, 28, 3, 28, 3, 29, 3, 29, 3, 30, 3, 30, 3, 31, 3, 31, 3, 32, 3, 32, 3, 33, 3, 33, 3, 34, 3, 34, 3, 35, 3, 35, 3, 35, 3, 36, 3, 36, 3, 36, 3, 37, 3, 37, 3, 37, 3, 38, 3, 38, 3, 38, 3, 39, 3, 39, 3, 39, 3, 40, 3, 40, 3, 40, 3, 41, 3, 41, 3, 42, 3, 42, 3, 43, 3, 43, 5, 43, 251, 10, 43, 3, 44, 3, 44, 3, 44, 7, 44, 256, 10, 44, 12, 44, 14, 44, 259, 11, 44, 5, 44, 261, 10, 44, 3, 45, 3, 45, 3, 45, 3, 45, 5, 45, 267, 10, 45, 3, 45, 6, 45, 270, 10, 45, 13, 45, 14, 45, 271, 3, 46, 3, 46, 5, 46, 276, 10, 46, 3, 47, 3, 47, 3, 47, 3, 47, 3, 47, 3, 47, 3, 47, 3, 47, 3, 47, 5, 47, 287, 10, 47, 3, 48, 3, 48, 3, 48, 7, 48, 292, 10, 48, 12, 48, 14, 48, 295, 11, 48, 3, 49, 3, 49, 3, 49, 3, 49, 7, 49, 301, 10, 49, 12, 49, 14, 49, 304, 11, 49, 3, 49, 3, 49, 3, 49, 3, 49, 3, 49, 3, 50, 3, 50, 3, 50, 3, 50, 7, 50, 315, 10, 50, 12, 50, 14, 50, 318, 11, 50, 3, 50, 3, 50, 3, 51, 3, 51, 3, 51, 3, 51, 3, 52, 3, 52, 3, 302, 2, 53, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 24, 47, 25, 49, 26, 51, 27, 53, 28, 55, 29, 57, 30, 59, 31, 61, 32, 63, 33, 65, 34, 67, 35, 69, 36, 71, 37, 73, 38, 75, 39, 77, 40, 79, 41, 81, 2, 83, 2, 85, 2, 87, 2, 89, 2, 91, 42, 93, 43, 95, 44, 97, 45, 99, 46, 101, 47, 103, 48, 3, 2, 6, 4, 2, 67, 92, 99, 124, 4, 2, 67, 72, 99, 104, 4, 2, 12, 12, 15, 15, 5, 2, 11, 12, 15, 15, 34, 34, 2, 332, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 2, 57, 3, 2, 2, 2, 2, 59, 3, 2, 2, 2, 2, 61, 3, 2, 2, 2, 2, 63, 3, 2, 2, 2, 2, 65, 3, 2, 2, 2, 2, 67, 3, 2, 2, 2, 2, 69, 3, 2, 2, 2, 2, 71, 3, 2, 2, 2, 2, 73, 3, 2, 2, 2, 2, 75, 3, 2, 2, 2, 2, 77, 3, 2, 2, 2, 2, 79, 3, 2, 2, 2, 2, 91, 3, 2, 2, 2, 2, 93, 3, 2, 2, 2, 2, 95, 3, 2, 2, 2, 2, 97, 3, 2, 2, 2, 2, 99, 3, 2, 2, 2, 2, 101, 3, 2, 2, 2, 2, 103, 3, 2, 2, 2, 3, 105, 3, 2, 2, 2, 5, 110, 3, 2, 2, 2, 7, 112, 3, 2, 2, 2, 9, 114, 3, 2, 2, 2, 11, 122, 3, 2, 2, 2, 13, 126, 3, 2, 2, 2, 15, 132, 3, 2, 2, 2, 17, 140, 3, 2, 2, 2, 19, 142, 3, 2, 2, 2, 21, 144, 3, 2, 2, 2, 23, 146, 3, 2, 2, 2, 25, 148, 3, 2, 2, 2, 27, 153, 3, 2, 2, 2, 29, 155, 3, 2, 2, 2, 31, 157, 3, 2, 2, 2, 33, 159, 3, 2, 2, 2, 35, 161, 3, 2, 2, 2, 37, 167, 3, 2, 2, 2, 39, 175, 3, 2, 2, 2, 41, 178, 3, 2, 2, 2, 43, 183, 3, 2, 2, 2, 45, 189, 3, 2, 2, 2, 47, 196, 3, 2, 2, 2, 49, 200, 3, 2, 2, 2, 51, 205, 3, 2, 2, 2, 53, 210, 3, 2, 2, 2, 55, 212, 3, 2, 2, 2, 57, 214, 3, 2, 2, 2, 59, 216, 3, 2, 2, 2, 61, 218, 3, 2, 2, 2, 63, 220, 3, 2, 2, 2, 65, 222, 3, 2, 2, 2, 67, 224, 3, 2, 2, 2, 69, 226, 3, 2, 2, 2, 71, 229, 3, 2, 2, 2, 73, 232, 3, 2, 2, 2, 75, 235, 3, 2, 2, 2, 77, 238, 3, 2, 2, 2, 79, 241, 3, 2, 2, 2, 81, 244, 3, 2, 2, 2, 83, 246, 3, 2, 2, 2, 85, 250, 3, 2, 2, 2, 87, 260, 3, 2, 2, 2, 89, 266, 3, 2, 2, 2, 91, 275, 3, 2, 2, 2, 93, 286, 3, 2, 2, 2, 95, 288, 3, 2, 2, 2, 97, 296, 3, 2, 2, 2, 99, 310, 3, 2, 2, 2, 101, 321, 3, 2, 2, 2, 103, 325, 3, 2, 2, 2, 105, 106, 7, 112, 2, 2, 106, 107, 7, 119, 2, 2, 107, 108, 7, 110, 2, 2, 108, 109, 7, 110, 2, 2, 109, 4, 3, 2, 2, 2, 110, 111, 7, 93, 2, 2, 111, 6, 3, 2, 2, 2, 112, 113, 7, 95, 2, 2, 113, 8, 3, 2, 2, 2, 114, 115, 7, 100, 2, 2, 115, 116, 7, 113, 2, 2, 116, 117, 7, 113, 2, 2, 117, 118, 7, 110, 2, 2, 118, 119, 7, 103, 2, 2, 119, 120, 7, 99, 2, 2, 120, 121, 7, 112, 2, 2, 121, 10, 3, 2, 2, 2, 122, 123, 7, 107, 2, 2, 123, 124, 7, 112, 2, 2, 124, 125, 7, 118, 2, 2, 125, 12, 3, 2, 2, 2, 126, 127, 7, 101, 2, 2, 127, 128, 7, 110, 2, 2, 128, 129, 7, 99, 2, 2, 129, 130, 7, 117, 2, 2, 130, 131, 7, 117, 2, 2, 131, 14, 3, 2, 2, 2, 132, 133, 7, 103, 2, 2, 133, 134, 7, 122, 2, 2, 134, 135, 7, 118, 2, 2, 135, 136, 7, 103, 2, 2, 136, 137, 7, 112, 2, 2, 137, 138, 7, 102, 2, 2, 138, 139, 7, 117, 2, 2, 139, 16, 3, 2, 2, 2, 140, 141, 7, 125, 2, 2, 141, 18, 3, 2, 2, 2, 142, 143, 7, 127, 2, 2, 143, 20, 3, 2, 2, 2, 144, 145, 7, 46, 2, 2, 145, 22, 3, 2, 2, 2, 146, 147, 7, 61, 2, 2, 147, 24, 3, 2, 2, 2, 148, 149, 7, 120, 2, 2, 149, 150, 7, 113, 2, 2, 150, 151, 7, 107, 2, 2, 151, 152, 7, 102, 2, 2, 152, 26, 3, 2, 2, 2, 153, 154, 7, 42, 2, 2, 154, 28, 3, 2, 2, 2, 155, 156, 7, 43, 2, 2, 156, 30, 3, 2, 2, 2, 157, 158, 7, 48, 2, 2, 158, 32, 3, 2, 2, 2, 159, 160, 7, 63, 2, 2, 160, 34, 3, 2, 2, 2, 161, 162, 7, 121, 2, 2, 162, 163, 7, 116, 2, 2, 163, 164, 7, 107, 2, 2, 164, 165, 7, 118, 2, 2, 165, 166, 7, 103, 2, 2, 166, 36, 3, 2, 2, 2, 167, 168, 7, 121, 2, 2, 168, 169, 7, 116, 2, 2, 169, 170, 7, 107, 2, 2, 170, 171, 7, 118, 2, 2, 171, 172, 7, 103, 2, 2, 172, 173, 7, 110, 2, 2, 173, 174, 7, 112, 2, 2, 174, 38, 3, 2, 2, 2, 175, 176, 7, 107, 2, 2, 176, 177, 7, 104, 2, 2, 177, 40, 3, 2, 2, 2, 178, 179, 7, 103, 2, 2, 179, 180, 7, 110, 2, 2, 180, 181, 7, 117, 2, 2, 181, 182, 7, 103, 2, 2, 182, 42, 3, 2, 2, 2, 183, 184, 7, 121, 2, 2, 184, 185, 7, 106, 2, 2, 185, 186, 7, 107, 2, 2, 186, 187, 7, 110, 2, 2, 187, 188, 7, 103, 2, 2, 188, 44, 3, 2, 2, 2, 189, 190, 7, 116, 2, 2, 190, 191, 7, 103, 2, 2, 191, 192, 7, 118, 2, 2, 192, 193, 7, 119, 2, 2, 193, 194, 7, 116, 2, 2, 194, 195, 7, 112, 2, 2, 195, 46, 3, 2, 2, 2, 196, 197, 7, 112, 2, 2, 197, 198, 7, 103, 2, 2, 198, 199, 7, 121, 2, 2, 199, 48, 3, 2, 2, 2, 200, 201, 7, 116, 2, 2, 201, 202, 7, 103, 2, 2, 202, 203, 7, 99, 2, 2, 203, 204, 7, 102, 2, 2, 204, 50, 3, 2, 2, 2, 205, 206, 7, 118, 2, 2, 206, 207, 7, 106, 2, 2, 207, 208, 7, 107, 2, 2, 208, 209, 7, 117, 2, 2, 209, 52, 3, 2, 2, 2, 210, 211, 7, 45, 2, 2, 211, 54, 3, 2, 2, 2, 212, 213, 7, 47, 2, 2, 213, 56, 3, 2, 2, 2, 214, 215, 7, 35, 2, 2, 215, 58, 3, 2, 2, 2, 216, 217, 7, 44, 2, 2, 217, 60, 3, 2, 2, 2, 218, 219, 7, 49, 2, 2, 219, 62, 3, 2, 2, 2, 220, 221, 7, 39, 2, 2, 221, 64, 3, 2, 2, 2, 222, 223, 7, 62, 2, 2, 223, 66, 3, 2, 2, 2, 224, 225, 7, 64, 2, 2, 225, 68, 3, 2, 2, 2, 226, 227, 7, 62, 2, 2, 227, 228, 7, 63, 2, 2, 228, 70, 3, 2, 2, 2, 229, 230, 7, 64, 2, 2, 230, 231, 7, 63, 2, 2, 231, 72, 3, 2, 2, 2, 232, 233, 7, 63, 2, 2, 233, 234, 7, 63, 2, 2, 234, 74, 3, 2, 2, 2, 235, 236, 7, 35, 2, 2, 236, 237, 7, 63, 2, 2, 237, 76, 3, 2, 2, 2, 238, 239, 7, 40, 2, 2, 239, 240, 7, 40, 2, 2, 240, 78, 3, 2, 2, 2, 241, 242, 7, 126, 2, 2, 242, 243, 7, 126, 2, 2, 243, 80, 3, 2, 2, 2, 244, 245, 9, 2, 2, 2, 245, 82, 3, 2, 2, 2, 246, 247, 4, 50, 59, 2, 247, 84, 3, 2, 2, 2, 248, 251, 5, 83, 42, 2, 249, 251, 9, 3, 2, 2, 250, 248, 3, 2, 2, 2, 250, 249, 3, 2, 2, 2, 251, 86, 3, 2, 2, 2, 252, 261, 7, 50, 2, 2, 253, 257, 4, 51, 59, 2, 254, 256, 5, 83, 42, 2, 255, 254, 3, 2, 2, 2, 256, 259, 3, 2, 2, 2, 257, 255, 3, 2, 2, 2, 257, 258, 3, 2, 2, 2, 258, 261, 3, 2, 2, 2, 259, 257, 3, 2, 2, 2, 260, 252, 3, 2, 2, 2, 260, 253, 3, 2, 2, 2, 261, 88, 3, 2, 2, 2, 262, 263, 7, 50, 2, 2, 263, 267, 7, 122, 2, 2, 264, 265, 7, 50, 2, 2, 265, 267, 7, 90, 2, 2, 266, 262, 3, 2, 2, 2, 266, 264, 3, 2, 2, 2, 267, 269, 3, 2, 2, 2, 268, 270, 5, 85, 43, 2, 269, 268, 3, 2, 2, 2, 270, 271, 3, 2, 2, 2, 271, 269, 3, 2, 2, 2, 271, 272, 3, 2, 2, 2, 272, 90, 3, 2, 2, 2, 273, 276, 5, 87, 44, 2, 274, 276, 5, 89, 45, 2, 275, 273, 3, 2, 2, 2, 275, 274, 3, 2, 2, 2, 276, 92, 3, 2, 2, 2, 277, 278, 7, 104, 2, 2, 278, 279, 7, 99, 2, 2, 279, 280, 7, 110, 2, 2, 280, 281, 7, 117, 2, 2, 281, 287, 7, 103, 2, 2, 282, 283, 7, 118, 2, 2, 283, 284, 7, 116, 2, 2, 284, 285, 7, 119, 2, 2, 285, 287, 7, 103, 2, 2, 286, 277, 3, 2, 2, 2, 286, 282, 3, 2, 2, 2, 287, 94, 3, 2, 2, 2, 288, 293, 5, 81, 41, 2, 289, 292, 5, 81, 41, 2, 290, 292, 5, 83, 42, 2, 291, 289, 3, 2, 2, 2, 291, 290, 3, 2, 2, 2, 292, 295, 3, 2, 2, 2, 293, 291, 3, 2, 2, 2, 293, 294, 3, 2, 2, 2, 294, 96, 3, 2, 2, 2, 295, 293, 3, 2, 2, 2, 296, 297, 7, 49, 2, 2, 297, 298, 7, 44, 2, 2, 298, 302, 3, 2, 2, 2, 299, 301, 11, 2, 2, 2, 300, 299, 3, 2, 2, 2, 301, 304, 3, 2, 2, 2, 302, 303, 3, 2, 2, 2, 302, 300, 3, 2, 2, 2, 303, 305, 3, 2, 2, 2, 304, 302, 3, 2, 2, 2, 305, 306, 7, 44, 2, 2, 306, 307, 7, 49, 2, 2, 307, 308, 3, 2, 2, 2, 308, 309, 8, 49, 2, 2, 309, 98, 3, 2, 2, 2, 310, 311, 7, 49, 2, 2, 311, 312, 7, 49, 2, 2, 312, 316, 3, 2, 2, 2, 313, 315, 10, 4, 2, 2, 314, 313, 3, 2, 2, 2, 315, 318, 3, 2, 2, 2, 316, 314, 3, 2, 2, 2, 316, 317, 3, 2, 2, 2, 317, 319, 3, 2, 2, 2, 318, 316, 3, 2, 2, 2, 319, 320, 8, 50, 2, 2, 320, 100, 3, 2, 2, 2, 321, 322, 9, 5, 2, 2, 322, 323, 3, 2, 2, 2, 323, 324, 8, 51, 2, 2, 324, 102, 3, 2, 2, 2, 325, 326, 11, 2, 2, 2, 326, 104, 3, 2, 2, 2, 14, 2, 250, 257, 260, 266, 271, 275, 286, 291, 293, 302, 316, 3, 8, 2, 2] \ No newline at end of file diff --git a/src/cd/frontend/parser/JavaliLexer.java b/src/cd/frontend/parser/JavaliLexer.java deleted file mode 100644 index 50aec9c..0000000 --- a/src/cd/frontend/parser/JavaliLexer.java +++ /dev/null @@ -1,232 +0,0 @@ -// Generated from /home/carlos/eth/cd/nop90/HW2/src/cd/frontend/parser/Javali.g4 by ANTLR 4.7.1 - - // Java header - package cd.frontend.parser; - -import org.antlr.v4.runtime.Lexer; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.*; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class JavaliLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, - T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, - T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, - T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, - T__38=39, Integer=40, Boolean=41, Ident=42, COMMENT=43, LINE_COMMENT=44, - WS=45, ErrorCharacter=46; - public static String[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static String[] modeNames = { - "DEFAULT_MODE" - }; - - public static final String[] ruleNames = { - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", - "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", - "T__25", "T__26", "T__27", "T__28", "T__29", "T__30", "T__31", "T__32", - "T__33", "T__34", "T__35", "T__36", "T__37", "T__38", "Letter", "Digit", - "HexDigit", "Decimal", "Hexadecimal", "Integer", "Boolean", "Ident", "COMMENT", - "LINE_COMMENT", "WS", "ErrorCharacter" - }; - - private static final String[] _LITERAL_NAMES = { - null, "'null'", "'['", "']'", "'boolean'", "'int'", "'class'", "'extends'", - "'{'", "'}'", "','", "';'", "'void'", "'('", "')'", "'.'", "'='", "'write'", - "'writeln'", "'if'", "'else'", "'while'", "'return'", "'new'", "'read'", - "'this'", "'+'", "'-'", "'!'", "'*'", "'/'", "'%'", "'<'", "'>'", "'<='", - "'>='", "'=='", "'!='", "'&&'", "'||'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, "Integer", "Boolean", "Ident", "COMMENT", "LINE_COMMENT", - "WS", "ErrorCharacter" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - - public JavaliLexer(CharStream input) { - super(input); - _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @Override - public String getGrammarFileName() { return "Javali.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public String[] getChannelNames() { return channelNames; } - - @Override - public String[] getModeNames() { return modeNames; } - - @Override - public ATN getATN() { return _ATN; } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\60\u0147\b\1\4\2"+ - "\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4"+ - "\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+ - "\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31"+ - "\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t"+ - " \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t"+ - "+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\4\64"+ - "\t\64\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5"+ - "\3\5\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+ - "\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\f\3\f\3\r\3\r\3\r\3\r\3\r\3\16\3\16"+ - "\3\17\3\17\3\20\3\20\3\21\3\21\3\22\3\22\3\22\3\22\3\22\3\22\3\23\3\23"+ - "\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3\24\3\24\3\25\3\25\3\25\3\25\3\25"+ - "\3\26\3\26\3\26\3\26\3\26\3\26\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\30"+ - "\3\30\3\30\3\30\3\31\3\31\3\31\3\31\3\31\3\32\3\32\3\32\3\32\3\32\3\33"+ - "\3\33\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3 \3 \3!\3!\3\"\3\"\3#\3"+ - "#\3#\3$\3$\3$\3%\3%\3%\3&\3&\3&\3\'\3\'\3\'\3(\3(\3(\3)\3)\3*\3*\3+\3"+ - "+\5+\u00fb\n+\3,\3,\3,\7,\u0100\n,\f,\16,\u0103\13,\5,\u0105\n,\3-\3-"+ - "\3-\3-\5-\u010b\n-\3-\6-\u010e\n-\r-\16-\u010f\3.\3.\5.\u0114\n.\3/\3"+ - "/\3/\3/\3/\3/\3/\3/\3/\5/\u011f\n/\3\60\3\60\3\60\7\60\u0124\n\60\f\60"+ - "\16\60\u0127\13\60\3\61\3\61\3\61\3\61\7\61\u012d\n\61\f\61\16\61\u0130"+ - "\13\61\3\61\3\61\3\61\3\61\3\61\3\62\3\62\3\62\3\62\7\62\u013b\n\62\f"+ - "\62\16\62\u013e\13\62\3\62\3\62\3\63\3\63\3\63\3\63\3\64\3\64\3\u012e"+ - "\2\65\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35"+ - "\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33\65\34\67\359\36"+ - ";\37= ?!A\"C#E$G%I&K\'M(O)Q\2S\2U\2W\2Y\2[*]+_,a-c.e/g\60\3\2\6\4\2C\\"+ - "c|\4\2CHch\4\2\f\f\17\17\5\2\13\f\17\17\"\"\2\u014c\2\3\3\2\2\2\2\5\3"+ - "\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2"+ - "\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3"+ - "\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'"+ - "\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2\2\2\63"+ - "\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2"+ - "?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2G\3\2\2\2\2I\3\2\2\2\2K\3"+ - "\2\2\2\2M\3\2\2\2\2O\3\2\2\2\2[\3\2\2\2\2]\3\2\2\2\2_\3\2\2\2\2a\3\2\2"+ - "\2\2c\3\2\2\2\2e\3\2\2\2\2g\3\2\2\2\3i\3\2\2\2\5n\3\2\2\2\7p\3\2\2\2\t"+ - "r\3\2\2\2\13z\3\2\2\2\r~\3\2\2\2\17\u0084\3\2\2\2\21\u008c\3\2\2\2\23"+ - "\u008e\3\2\2\2\25\u0090\3\2\2\2\27\u0092\3\2\2\2\31\u0094\3\2\2\2\33\u0099"+ - "\3\2\2\2\35\u009b\3\2\2\2\37\u009d\3\2\2\2!\u009f\3\2\2\2#\u00a1\3\2\2"+ - "\2%\u00a7\3\2\2\2\'\u00af\3\2\2\2)\u00b2\3\2\2\2+\u00b7\3\2\2\2-\u00bd"+ - "\3\2\2\2/\u00c4\3\2\2\2\61\u00c8\3\2\2\2\63\u00cd\3\2\2\2\65\u00d2\3\2"+ - "\2\2\67\u00d4\3\2\2\29\u00d6\3\2\2\2;\u00d8\3\2\2\2=\u00da\3\2\2\2?\u00dc"+ - "\3\2\2\2A\u00de\3\2\2\2C\u00e0\3\2\2\2E\u00e2\3\2\2\2G\u00e5\3\2\2\2I"+ - "\u00e8\3\2\2\2K\u00eb\3\2\2\2M\u00ee\3\2\2\2O\u00f1\3\2\2\2Q\u00f4\3\2"+ - "\2\2S\u00f6\3\2\2\2U\u00fa\3\2\2\2W\u0104\3\2\2\2Y\u010a\3\2\2\2[\u0113"+ - "\3\2\2\2]\u011e\3\2\2\2_\u0120\3\2\2\2a\u0128\3\2\2\2c\u0136\3\2\2\2e"+ - "\u0141\3\2\2\2g\u0145\3\2\2\2ij\7p\2\2jk\7w\2\2kl\7n\2\2lm\7n\2\2m\4\3"+ - "\2\2\2no\7]\2\2o\6\3\2\2\2pq\7_\2\2q\b\3\2\2\2rs\7d\2\2st\7q\2\2tu\7q"+ - "\2\2uv\7n\2\2vw\7g\2\2wx\7c\2\2xy\7p\2\2y\n\3\2\2\2z{\7k\2\2{|\7p\2\2"+ - "|}\7v\2\2}\f\3\2\2\2~\177\7e\2\2\177\u0080\7n\2\2\u0080\u0081\7c\2\2\u0081"+ - "\u0082\7u\2\2\u0082\u0083\7u\2\2\u0083\16\3\2\2\2\u0084\u0085\7g\2\2\u0085"+ - "\u0086\7z\2\2\u0086\u0087\7v\2\2\u0087\u0088\7g\2\2\u0088\u0089\7p\2\2"+ - "\u0089\u008a\7f\2\2\u008a\u008b\7u\2\2\u008b\20\3\2\2\2\u008c\u008d\7"+ - "}\2\2\u008d\22\3\2\2\2\u008e\u008f\7\177\2\2\u008f\24\3\2\2\2\u0090\u0091"+ - "\7.\2\2\u0091\26\3\2\2\2\u0092\u0093\7=\2\2\u0093\30\3\2\2\2\u0094\u0095"+ - "\7x\2\2\u0095\u0096\7q\2\2\u0096\u0097\7k\2\2\u0097\u0098\7f\2\2\u0098"+ - "\32\3\2\2\2\u0099\u009a\7*\2\2\u009a\34\3\2\2\2\u009b\u009c\7+\2\2\u009c"+ - "\36\3\2\2\2\u009d\u009e\7\60\2\2\u009e \3\2\2\2\u009f\u00a0\7?\2\2\u00a0"+ - "\"\3\2\2\2\u00a1\u00a2\7y\2\2\u00a2\u00a3\7t\2\2\u00a3\u00a4\7k\2\2\u00a4"+ - "\u00a5\7v\2\2\u00a5\u00a6\7g\2\2\u00a6$\3\2\2\2\u00a7\u00a8\7y\2\2\u00a8"+ - "\u00a9\7t\2\2\u00a9\u00aa\7k\2\2\u00aa\u00ab\7v\2\2\u00ab\u00ac\7g\2\2"+ - "\u00ac\u00ad\7n\2\2\u00ad\u00ae\7p\2\2\u00ae&\3\2\2\2\u00af\u00b0\7k\2"+ - "\2\u00b0\u00b1\7h\2\2\u00b1(\3\2\2\2\u00b2\u00b3\7g\2\2\u00b3\u00b4\7"+ - "n\2\2\u00b4\u00b5\7u\2\2\u00b5\u00b6\7g\2\2\u00b6*\3\2\2\2\u00b7\u00b8"+ - "\7y\2\2\u00b8\u00b9\7j\2\2\u00b9\u00ba\7k\2\2\u00ba\u00bb\7n\2\2\u00bb"+ - "\u00bc\7g\2\2\u00bc,\3\2\2\2\u00bd\u00be\7t\2\2\u00be\u00bf\7g\2\2\u00bf"+ - "\u00c0\7v\2\2\u00c0\u00c1\7w\2\2\u00c1\u00c2\7t\2\2\u00c2\u00c3\7p\2\2"+ - "\u00c3.\3\2\2\2\u00c4\u00c5\7p\2\2\u00c5\u00c6\7g\2\2\u00c6\u00c7\7y\2"+ - "\2\u00c7\60\3\2\2\2\u00c8\u00c9\7t\2\2\u00c9\u00ca\7g\2\2\u00ca\u00cb"+ - "\7c\2\2\u00cb\u00cc\7f\2\2\u00cc\62\3\2\2\2\u00cd\u00ce\7v\2\2\u00ce\u00cf"+ - "\7j\2\2\u00cf\u00d0\7k\2\2\u00d0\u00d1\7u\2\2\u00d1\64\3\2\2\2\u00d2\u00d3"+ - "\7-\2\2\u00d3\66\3\2\2\2\u00d4\u00d5\7/\2\2\u00d58\3\2\2\2\u00d6\u00d7"+ - "\7#\2\2\u00d7:\3\2\2\2\u00d8\u00d9\7,\2\2\u00d9<\3\2\2\2\u00da\u00db\7"+ - "\61\2\2\u00db>\3\2\2\2\u00dc\u00dd\7\'\2\2\u00dd@\3\2\2\2\u00de\u00df"+ - "\7>\2\2\u00dfB\3\2\2\2\u00e0\u00e1\7@\2\2\u00e1D\3\2\2\2\u00e2\u00e3\7"+ - ">\2\2\u00e3\u00e4\7?\2\2\u00e4F\3\2\2\2\u00e5\u00e6\7@\2\2\u00e6\u00e7"+ - "\7?\2\2\u00e7H\3\2\2\2\u00e8\u00e9\7?\2\2\u00e9\u00ea\7?\2\2\u00eaJ\3"+ - "\2\2\2\u00eb\u00ec\7#\2\2\u00ec\u00ed\7?\2\2\u00edL\3\2\2\2\u00ee\u00ef"+ - "\7(\2\2\u00ef\u00f0\7(\2\2\u00f0N\3\2\2\2\u00f1\u00f2\7~\2\2\u00f2\u00f3"+ - "\7~\2\2\u00f3P\3\2\2\2\u00f4\u00f5\t\2\2\2\u00f5R\3\2\2\2\u00f6\u00f7"+ - "\4\62;\2\u00f7T\3\2\2\2\u00f8\u00fb\5S*\2\u00f9\u00fb\t\3\2\2\u00fa\u00f8"+ - "\3\2\2\2\u00fa\u00f9\3\2\2\2\u00fbV\3\2\2\2\u00fc\u0105\7\62\2\2\u00fd"+ - "\u0101\4\63;\2\u00fe\u0100\5S*\2\u00ff\u00fe\3\2\2\2\u0100\u0103\3\2\2"+ - "\2\u0101\u00ff\3\2\2\2\u0101\u0102\3\2\2\2\u0102\u0105\3\2\2\2\u0103\u0101"+ - "\3\2\2\2\u0104\u00fc\3\2\2\2\u0104\u00fd\3\2\2\2\u0105X\3\2\2\2\u0106"+ - "\u0107\7\62\2\2\u0107\u010b\7z\2\2\u0108\u0109\7\62\2\2\u0109\u010b\7"+ - "Z\2\2\u010a\u0106\3\2\2\2\u010a\u0108\3\2\2\2\u010b\u010d\3\2\2\2\u010c"+ - "\u010e\5U+\2\u010d\u010c\3\2\2\2\u010e\u010f\3\2\2\2\u010f\u010d\3\2\2"+ - "\2\u010f\u0110\3\2\2\2\u0110Z\3\2\2\2\u0111\u0114\5W,\2\u0112\u0114\5"+ - "Y-\2\u0113\u0111\3\2\2\2\u0113\u0112\3\2\2\2\u0114\\\3\2\2\2\u0115\u0116"+ - "\7h\2\2\u0116\u0117\7c\2\2\u0117\u0118\7n\2\2\u0118\u0119\7u\2\2\u0119"+ - "\u011f\7g\2\2\u011a\u011b\7v\2\2\u011b\u011c\7t\2\2\u011c\u011d\7w\2\2"+ - "\u011d\u011f\7g\2\2\u011e\u0115\3\2\2\2\u011e\u011a\3\2\2\2\u011f^\3\2"+ - "\2\2\u0120\u0125\5Q)\2\u0121\u0124\5Q)\2\u0122\u0124\5S*\2\u0123\u0121"+ - "\3\2\2\2\u0123\u0122\3\2\2\2\u0124\u0127\3\2\2\2\u0125\u0123\3\2\2\2\u0125"+ - "\u0126\3\2\2\2\u0126`\3\2\2\2\u0127\u0125\3\2\2\2\u0128\u0129\7\61\2\2"+ - "\u0129\u012a\7,\2\2\u012a\u012e\3\2\2\2\u012b\u012d\13\2\2\2\u012c\u012b"+ - "\3\2\2\2\u012d\u0130\3\2\2\2\u012e\u012f\3\2\2\2\u012e\u012c\3\2\2\2\u012f"+ - "\u0131\3\2\2\2\u0130\u012e\3\2\2\2\u0131\u0132\7,\2\2\u0132\u0133\7\61"+ - "\2\2\u0133\u0134\3\2\2\2\u0134\u0135\b\61\2\2\u0135b\3\2\2\2\u0136\u0137"+ - "\7\61\2\2\u0137\u0138\7\61\2\2\u0138\u013c\3\2\2\2\u0139\u013b\n\4\2\2"+ - "\u013a\u0139\3\2\2\2\u013b\u013e\3\2\2\2\u013c\u013a\3\2\2\2\u013c\u013d"+ - "\3\2\2\2\u013d\u013f\3\2\2\2\u013e\u013c\3\2\2\2\u013f\u0140\b\62\2\2"+ - "\u0140d\3\2\2\2\u0141\u0142\t\5\2\2\u0142\u0143\3\2\2\2\u0143\u0144\b"+ - "\63\2\2\u0144f\3\2\2\2\u0145\u0146\13\2\2\2\u0146h\3\2\2\2\16\2\u00fa"+ - "\u0101\u0104\u010a\u010f\u0113\u011e\u0123\u0125\u012e\u013c\3\b\2\2"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/cd/frontend/parser/JavaliLexer.tokens b/src/cd/frontend/parser/JavaliLexer.tokens deleted file mode 100644 index 0bd9b31..0000000 --- a/src/cd/frontend/parser/JavaliLexer.tokens +++ /dev/null @@ -1,85 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -T__27=28 -T__28=29 -T__29=30 -T__30=31 -T__31=32 -T__32=33 -T__33=34 -T__34=35 -T__35=36 -T__36=37 -T__37=38 -T__38=39 -Integer=40 -Boolean=41 -Ident=42 -COMMENT=43 -LINE_COMMENT=44 -WS=45 -ErrorCharacter=46 -'null'=1 -'['=2 -']'=3 -'boolean'=4 -'int'=5 -'class'=6 -'extends'=7 -'{'=8 -'}'=9 -','=10 -';'=11 -'void'=12 -'('=13 -')'=14 -'.'=15 -'='=16 -'write'=17 -'writeln'=18 -'if'=19 -'else'=20 -'while'=21 -'return'=22 -'new'=23 -'read'=24 -'this'=25 -'+'=26 -'-'=27 -'!'=28 -'*'=29 -'/'=30 -'%'=31 -'<'=32 -'>'=33 -'<='=34 -'>='=35 -'=='=36 -'!='=37 -'&&'=38 -'||'=39 diff --git a/src/cd/frontend/parser/JavaliParser.java b/src/cd/frontend/parser/JavaliParser.java deleted file mode 100644 index a79d41b..0000000 --- a/src/cd/frontend/parser/JavaliParser.java +++ /dev/null @@ -1,2315 +0,0 @@ -// Generated from /home/carlos/eth/cd/nop90/HW2/src/cd/frontend/parser/Javali.g4 by ANTLR 4.7.1 - - // Java header - package cd.frontend.parser; - -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.misc.*; -import org.antlr.v4.runtime.tree.*; -import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class JavaliParser extends Parser { - static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, - T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, - T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, - T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, - T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, - T__38=39, Integer=40, Boolean=41, Ident=42, COMMENT=43, LINE_COMMENT=44, - WS=45, ErrorCharacter=46; - public static final int - RULE_literal = 0, RULE_type = 1, RULE_referenceType = 2, RULE_arrayType = 3, - RULE_primitiveType = 4, RULE_unit = 5, RULE_classDecl = 6, RULE_memberList = 7, - RULE_varDecl = 8, RULE_methodDecl = 9, RULE_formalParamList = 10, RULE_stmt = 11, - RULE_stmtBlock = 12, RULE_methodCallStmt = 13, RULE_assignmentStmt = 14, - RULE_writeStmt = 15, RULE_ifStmt = 16, RULE_whileStmt = 17, RULE_returnStmt = 18, - RULE_newExpr = 19, RULE_readExpr = 20, RULE_actualParamList = 21, RULE_identAccess = 22, - RULE_expr = 23; - public static final String[] ruleNames = { - "literal", "type", "referenceType", "arrayType", "primitiveType", "unit", - "classDecl", "memberList", "varDecl", "methodDecl", "formalParamList", - "stmt", "stmtBlock", "methodCallStmt", "assignmentStmt", "writeStmt", - "ifStmt", "whileStmt", "returnStmt", "newExpr", "readExpr", "actualParamList", - "identAccess", "expr" - }; - - private static final String[] _LITERAL_NAMES = { - null, "'null'", "'['", "']'", "'boolean'", "'int'", "'class'", "'extends'", - "'{'", "'}'", "','", "';'", "'void'", "'('", "')'", "'.'", "'='", "'write'", - "'writeln'", "'if'", "'else'", "'while'", "'return'", "'new'", "'read'", - "'this'", "'+'", "'-'", "'!'", "'*'", "'/'", "'%'", "'<'", "'>'", "'<='", - "'>='", "'=='", "'!='", "'&&'", "'||'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, "Integer", "Boolean", "Ident", "COMMENT", "LINE_COMMENT", - "WS", "ErrorCharacter" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - @Override - public String getGrammarFileName() { return "Javali.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public ATN getATN() { return _ATN; } - - public JavaliParser(TokenStream input) { - super(input); - _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - public static class LiteralContext extends ParserRuleContext { - public LiteralContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_literal; } - - public LiteralContext() { } - public void copyFrom(LiteralContext ctx) { - super.copyFrom(ctx); - } - } - public static class BoolLiteralContext extends LiteralContext { - public TerminalNode Boolean() { return getToken(JavaliParser.Boolean, 0); } - public BoolLiteralContext(LiteralContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitBoolLiteral(this); - else return visitor.visitChildren(this); - } - } - public static class IntLiteralContext extends LiteralContext { - public TerminalNode Integer() { return getToken(JavaliParser.Integer, 0); } - public IntLiteralContext(LiteralContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitIntLiteral(this); - else return visitor.visitChildren(this); - } - } - public static class NullLiteralContext extends LiteralContext { - public NullLiteralContext(LiteralContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitNullLiteral(this); - else return visitor.visitChildren(this); - } - } - - public final LiteralContext literal() throws RecognitionException { - LiteralContext _localctx = new LiteralContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_literal); - try { - setState(51); - _errHandler.sync(this); - switch (_input.LA(1)) { - case T__0: - _localctx = new NullLiteralContext(_localctx); - enterOuterAlt(_localctx, 1); - { - setState(48); - match(T__0); - } - break; - case Boolean: - _localctx = new BoolLiteralContext(_localctx); - enterOuterAlt(_localctx, 2); - { - setState(49); - match(Boolean); - } - break; - case Integer: - _localctx = new IntLiteralContext(_localctx); - enterOuterAlt(_localctx, 3); - { - setState(50); - match(Integer); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class TypeContext extends ParserRuleContext { - public PrimitiveTypeContext primitiveType() { - return getRuleContext(PrimitiveTypeContext.class,0); - } - public ReferenceTypeContext referenceType() { - return getRuleContext(ReferenceTypeContext.class,0); - } - public TypeContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_type; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitType(this); - else return visitor.visitChildren(this); - } - } - - public final TypeContext type() throws RecognitionException { - TypeContext _localctx = new TypeContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_type); - try { - setState(55); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) { - case 1: - enterOuterAlt(_localctx, 1); - { - setState(53); - primitiveType(); - } - break; - case 2: - enterOuterAlt(_localctx, 2); - { - setState(54); - referenceType(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ReferenceTypeContext extends ParserRuleContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ArrayTypeContext arrayType() { - return getRuleContext(ArrayTypeContext.class,0); - } - public ReferenceTypeContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_referenceType; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitReferenceType(this); - else return visitor.visitChildren(this); - } - } - - public final ReferenceTypeContext referenceType() throws RecognitionException { - ReferenceTypeContext _localctx = new ReferenceTypeContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_referenceType); - try { - setState(59); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) { - case 1: - enterOuterAlt(_localctx, 1); - { - setState(57); - match(Ident); - } - break; - case 2: - enterOuterAlt(_localctx, 2); - { - setState(58); - arrayType(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ArrayTypeContext extends ParserRuleContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public PrimitiveTypeContext primitiveType() { - return getRuleContext(PrimitiveTypeContext.class,0); - } - public ArrayTypeContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_arrayType; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitArrayType(this); - else return visitor.visitChildren(this); - } - } - - public final ArrayTypeContext arrayType() throws RecognitionException { - ArrayTypeContext _localctx = new ArrayTypeContext(_ctx, getState()); - enterRule(_localctx, 6, RULE_arrayType); - try { - setState(68); - _errHandler.sync(this); - switch (_input.LA(1)) { - case Ident: - enterOuterAlt(_localctx, 1); - { - setState(61); - match(Ident); - setState(62); - match(T__1); - setState(63); - match(T__2); - } - break; - case T__3: - case T__4: - enterOuterAlt(_localctx, 2); - { - setState(64); - primitiveType(); - setState(65); - match(T__1); - setState(66); - match(T__2); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class PrimitiveTypeContext extends ParserRuleContext { - public PrimitiveTypeContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_primitiveType; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitPrimitiveType(this); - else return visitor.visitChildren(this); - } - } - - public final PrimitiveTypeContext primitiveType() throws RecognitionException { - PrimitiveTypeContext _localctx = new PrimitiveTypeContext(_ctx, getState()); - enterRule(_localctx, 8, RULE_primitiveType); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(70); - _la = _input.LA(1); - if ( !(_la==T__3 || _la==T__4) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class UnitContext extends ParserRuleContext { - public TerminalNode EOF() { return getToken(JavaliParser.EOF, 0); } - public List classDecl() { - return getRuleContexts(ClassDeclContext.class); - } - public ClassDeclContext classDecl(int i) { - return getRuleContext(ClassDeclContext.class,i); - } - public UnitContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_unit; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitUnit(this); - else return visitor.visitChildren(this); - } - } - - public final UnitContext unit() throws RecognitionException { - UnitContext _localctx = new UnitContext(_ctx, getState()); - enterRule(_localctx, 10, RULE_unit); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(73); - _errHandler.sync(this); - _la = _input.LA(1); - do { - { - { - setState(72); - classDecl(); - } - } - setState(75); - _errHandler.sync(this); - _la = _input.LA(1); - } while ( _la==T__5 ); - setState(77); - match(EOF); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ClassDeclContext extends ParserRuleContext { - public List Ident() { return getTokens(JavaliParser.Ident); } - public TerminalNode Ident(int i) { - return getToken(JavaliParser.Ident, i); - } - public MemberListContext memberList() { - return getRuleContext(MemberListContext.class,0); - } - public ClassDeclContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_classDecl; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitClassDecl(this); - else return visitor.visitChildren(this); - } - } - - public final ClassDeclContext classDecl() throws RecognitionException { - ClassDeclContext _localctx = new ClassDeclContext(_ctx, getState()); - enterRule(_localctx, 12, RULE_classDecl); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(79); - match(T__5); - setState(80); - match(Ident); - setState(83); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==T__6) { - { - setState(81); - match(T__6); - setState(82); - match(Ident); - } - } - - setState(85); - match(T__7); - setState(86); - memberList(); - setState(87); - match(T__8); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class MemberListContext extends ParserRuleContext { - public List varDecl() { - return getRuleContexts(VarDeclContext.class); - } - public VarDeclContext varDecl(int i) { - return getRuleContext(VarDeclContext.class,i); - } - public List methodDecl() { - return getRuleContexts(MethodDeclContext.class); - } - public MethodDeclContext methodDecl(int i) { - return getRuleContext(MethodDeclContext.class,i); - } - public MemberListContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_memberList; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitMemberList(this); - else return visitor.visitChildren(this); - } - } - - public final MemberListContext memberList() throws RecognitionException { - MemberListContext _localctx = new MemberListContext(_ctx, getState()); - enterRule(_localctx, 14, RULE_memberList); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(93); - _errHandler.sync(this); - _la = _input.LA(1); - while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__3) | (1L << T__4) | (1L << T__11) | (1L << Ident))) != 0)) { - { - setState(91); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) { - case 1: - { - setState(89); - varDecl(); - } - break; - case 2: - { - setState(90); - methodDecl(); - } - break; - } - } - setState(95); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class VarDeclContext extends ParserRuleContext { - public TypeContext type() { - return getRuleContext(TypeContext.class,0); - } - public List Ident() { return getTokens(JavaliParser.Ident); } - public TerminalNode Ident(int i) { - return getToken(JavaliParser.Ident, i); - } - public VarDeclContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_varDecl; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitVarDecl(this); - else return visitor.visitChildren(this); - } - } - - public final VarDeclContext varDecl() throws RecognitionException { - VarDeclContext _localctx = new VarDeclContext(_ctx, getState()); - enterRule(_localctx, 16, RULE_varDecl); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(96); - type(); - setState(97); - match(Ident); - setState(102); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==T__9) { - { - { - setState(98); - match(T__9); - setState(99); - match(Ident); - } - } - setState(104); - _errHandler.sync(this); - _la = _input.LA(1); - } - setState(105); - match(T__10); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class MethodDeclContext extends ParserRuleContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public TypeContext type() { - return getRuleContext(TypeContext.class,0); - } - public FormalParamListContext formalParamList() { - return getRuleContext(FormalParamListContext.class,0); - } - public List varDecl() { - return getRuleContexts(VarDeclContext.class); - } - public VarDeclContext varDecl(int i) { - return getRuleContext(VarDeclContext.class,i); - } - public List stmt() { - return getRuleContexts(StmtContext.class); - } - public StmtContext stmt(int i) { - return getRuleContext(StmtContext.class,i); - } - public MethodDeclContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_methodDecl; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitMethodDecl(this); - else return visitor.visitChildren(this); - } - } - - public final MethodDeclContext methodDecl() throws RecognitionException { - MethodDeclContext _localctx = new MethodDeclContext(_ctx, getState()); - enterRule(_localctx, 18, RULE_methodDecl); - int _la; - try { - int _alt; - enterOuterAlt(_localctx, 1); - { - setState(109); - _errHandler.sync(this); - switch (_input.LA(1)) { - case T__3: - case T__4: - case Ident: - { - setState(107); - type(); - } - break; - case T__11: - { - setState(108); - match(T__11); - } - break; - default: - throw new NoViableAltException(this); - } - setState(111); - match(Ident); - setState(112); - match(T__12); - setState(114); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__3) | (1L << T__4) | (1L << Ident))) != 0)) { - { - setState(113); - formalParamList(); - } - } - - setState(116); - match(T__13); - setState(117); - match(T__7); - setState(121); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,11,_ctx); - while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - { - { - setState(118); - varDecl(); - } - } - } - setState(123); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,11,_ctx); - } - setState(127); - _errHandler.sync(this); - _la = _input.LA(1); - while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__16) | (1L << T__17) | (1L << T__18) | (1L << T__20) | (1L << T__21) | (1L << T__24) | (1L << Ident))) != 0)) { - { - { - setState(124); - stmt(); - } - } - setState(129); - _errHandler.sync(this); - _la = _input.LA(1); - } - setState(130); - match(T__8); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class FormalParamListContext extends ParserRuleContext { - public List type() { - return getRuleContexts(TypeContext.class); - } - public TypeContext type(int i) { - return getRuleContext(TypeContext.class,i); - } - public List Ident() { return getTokens(JavaliParser.Ident); } - public TerminalNode Ident(int i) { - return getToken(JavaliParser.Ident, i); - } - public FormalParamListContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_formalParamList; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitFormalParamList(this); - else return visitor.visitChildren(this); - } - } - - public final FormalParamListContext formalParamList() throws RecognitionException { - FormalParamListContext _localctx = new FormalParamListContext(_ctx, getState()); - enterRule(_localctx, 20, RULE_formalParamList); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(132); - type(); - setState(133); - match(Ident); - setState(140); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==T__9) { - { - { - setState(134); - match(T__9); - setState(135); - type(); - setState(136); - match(Ident); - } - } - setState(142); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class StmtContext extends ParserRuleContext { - public AssignmentStmtContext assignmentStmt() { - return getRuleContext(AssignmentStmtContext.class,0); - } - public MethodCallStmtContext methodCallStmt() { - return getRuleContext(MethodCallStmtContext.class,0); - } - public IfStmtContext ifStmt() { - return getRuleContext(IfStmtContext.class,0); - } - public WhileStmtContext whileStmt() { - return getRuleContext(WhileStmtContext.class,0); - } - public ReturnStmtContext returnStmt() { - return getRuleContext(ReturnStmtContext.class,0); - } - public WriteStmtContext writeStmt() { - return getRuleContext(WriteStmtContext.class,0); - } - public StmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_stmt; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitStmt(this); - else return visitor.visitChildren(this); - } - } - - public final StmtContext stmt() throws RecognitionException { - StmtContext _localctx = new StmtContext(_ctx, getState()); - enterRule(_localctx, 22, RULE_stmt); - try { - setState(149); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,14,_ctx) ) { - case 1: - enterOuterAlt(_localctx, 1); - { - setState(143); - assignmentStmt(); - } - break; - case 2: - enterOuterAlt(_localctx, 2); - { - setState(144); - methodCallStmt(); - } - break; - case 3: - enterOuterAlt(_localctx, 3); - { - setState(145); - ifStmt(); - } - break; - case 4: - enterOuterAlt(_localctx, 4); - { - setState(146); - whileStmt(); - } - break; - case 5: - enterOuterAlt(_localctx, 5); - { - setState(147); - returnStmt(); - } - break; - case 6: - enterOuterAlt(_localctx, 6); - { - setState(148); - writeStmt(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class StmtBlockContext extends ParserRuleContext { - public List stmt() { - return getRuleContexts(StmtContext.class); - } - public StmtContext stmt(int i) { - return getRuleContext(StmtContext.class,i); - } - public StmtBlockContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_stmtBlock; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitStmtBlock(this); - else return visitor.visitChildren(this); - } - } - - public final StmtBlockContext stmtBlock() throws RecognitionException { - StmtBlockContext _localctx = new StmtBlockContext(_ctx, getState()); - enterRule(_localctx, 24, RULE_stmtBlock); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(151); - match(T__7); - setState(155); - _errHandler.sync(this); - _la = _input.LA(1); - while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__16) | (1L << T__17) | (1L << T__18) | (1L << T__20) | (1L << T__21) | (1L << T__24) | (1L << Ident))) != 0)) { - { - { - setState(152); - stmt(); - } - } - setState(157); - _errHandler.sync(this); - _la = _input.LA(1); - } - setState(158); - match(T__8); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class MethodCallStmtContext extends ParserRuleContext { - public MethodCallStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_methodCallStmt; } - - public MethodCallStmtContext() { } - public void copyFrom(MethodCallStmtContext ctx) { - super.copyFrom(ctx); - } - } - public static class ObjectMethodCallStmtContext extends MethodCallStmtContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ActualParamListContext actualParamList() { - return getRuleContext(ActualParamListContext.class,0); - } - public ObjectMethodCallStmtContext(MethodCallStmtContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitObjectMethodCallStmt(this); - else return visitor.visitChildren(this); - } - } - public static class LocalMethodCallStmtContext extends MethodCallStmtContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ActualParamListContext actualParamList() { - return getRuleContext(ActualParamListContext.class,0); - } - public LocalMethodCallStmtContext(MethodCallStmtContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitLocalMethodCallStmt(this); - else return visitor.visitChildren(this); - } - } - - public final MethodCallStmtContext methodCallStmt() throws RecognitionException { - MethodCallStmtContext _localctx = new MethodCallStmtContext(_ctx, getState()); - enterRule(_localctx, 26, RULE_methodCallStmt); - int _la; - try { - setState(177); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,18,_ctx) ) { - case 1: - _localctx = new LocalMethodCallStmtContext(_localctx); - enterOuterAlt(_localctx, 1); - { - setState(160); - match(Ident); - setState(161); - match(T__12); - setState(163); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__12) | (1L << T__24) | (1L << T__25) | (1L << T__26) | (1L << T__27) | (1L << Integer) | (1L << Boolean) | (1L << Ident))) != 0)) { - { - setState(162); - actualParamList(); - } - } - - setState(165); - match(T__13); - setState(166); - match(T__10); - } - break; - case 2: - _localctx = new ObjectMethodCallStmtContext(_localctx); - enterOuterAlt(_localctx, 2); - { - setState(167); - identAccess(0); - setState(168); - match(T__14); - setState(169); - match(Ident); - setState(170); - match(T__12); - setState(172); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__12) | (1L << T__24) | (1L << T__25) | (1L << T__26) | (1L << T__27) | (1L << Integer) | (1L << Boolean) | (1L << Ident))) != 0)) { - { - setState(171); - actualParamList(); - } - } - - setState(174); - match(T__13); - setState(175); - match(T__10); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class AssignmentStmtContext extends ParserRuleContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public NewExprContext newExpr() { - return getRuleContext(NewExprContext.class,0); - } - public ReadExprContext readExpr() { - return getRuleContext(ReadExprContext.class,0); - } - public AssignmentStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_assignmentStmt; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAssignmentStmt(this); - else return visitor.visitChildren(this); - } - } - - public final AssignmentStmtContext assignmentStmt() throws RecognitionException { - AssignmentStmtContext _localctx = new AssignmentStmtContext(_ctx, getState()); - enterRule(_localctx, 28, RULE_assignmentStmt); - try { - enterOuterAlt(_localctx, 1); - { - setState(179); - identAccess(0); - setState(180); - match(T__15); - setState(184); - _errHandler.sync(this); - switch (_input.LA(1)) { - case T__0: - case T__12: - case T__24: - case T__25: - case T__26: - case T__27: - case Integer: - case Boolean: - case Ident: - { - setState(181); - expr(0); - } - break; - case T__22: - { - setState(182); - newExpr(); - } - break; - case T__23: - { - setState(183); - readExpr(); - } - break; - default: - throw new NoViableAltException(this); - } - setState(186); - match(T__10); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class WriteStmtContext extends ParserRuleContext { - public WriteStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_writeStmt; } - - public WriteStmtContext() { } - public void copyFrom(WriteStmtContext ctx) { - super.copyFrom(ctx); - } - } - public static class WriteContext extends WriteStmtContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public WriteContext(WriteStmtContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitWrite(this); - else return visitor.visitChildren(this); - } - } - public static class WriteLnContext extends WriteStmtContext { - public WriteLnContext(WriteStmtContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitWriteLn(this); - else return visitor.visitChildren(this); - } - } - - public final WriteStmtContext writeStmt() throws RecognitionException { - WriteStmtContext _localctx = new WriteStmtContext(_ctx, getState()); - enterRule(_localctx, 30, RULE_writeStmt); - try { - setState(198); - _errHandler.sync(this); - switch (_input.LA(1)) { - case T__16: - _localctx = new WriteContext(_localctx); - enterOuterAlt(_localctx, 1); - { - setState(188); - match(T__16); - setState(189); - match(T__12); - setState(190); - expr(0); - setState(191); - match(T__13); - setState(192); - match(T__10); - } - break; - case T__17: - _localctx = new WriteLnContext(_localctx); - enterOuterAlt(_localctx, 2); - { - setState(194); - match(T__17); - setState(195); - match(T__12); - setState(196); - match(T__13); - setState(197); - match(T__10); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class IfStmtContext extends ParserRuleContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public List stmtBlock() { - return getRuleContexts(StmtBlockContext.class); - } - public StmtBlockContext stmtBlock(int i) { - return getRuleContext(StmtBlockContext.class,i); - } - public IfStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_ifStmt; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitIfStmt(this); - else return visitor.visitChildren(this); - } - } - - public final IfStmtContext ifStmt() throws RecognitionException { - IfStmtContext _localctx = new IfStmtContext(_ctx, getState()); - enterRule(_localctx, 32, RULE_ifStmt); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(200); - match(T__18); - setState(201); - match(T__12); - setState(202); - expr(0); - setState(203); - match(T__13); - setState(204); - stmtBlock(); - setState(207); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==T__19) { - { - setState(205); - match(T__19); - setState(206); - stmtBlock(); - } - } - - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class WhileStmtContext extends ParserRuleContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public StmtBlockContext stmtBlock() { - return getRuleContext(StmtBlockContext.class,0); - } - public WhileStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_whileStmt; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitWhileStmt(this); - else return visitor.visitChildren(this); - } - } - - public final WhileStmtContext whileStmt() throws RecognitionException { - WhileStmtContext _localctx = new WhileStmtContext(_ctx, getState()); - enterRule(_localctx, 34, RULE_whileStmt); - try { - enterOuterAlt(_localctx, 1); - { - setState(209); - match(T__20); - setState(210); - match(T__12); - setState(211); - expr(0); - setState(212); - match(T__13); - setState(213); - stmtBlock(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ReturnStmtContext extends ParserRuleContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public ReturnStmtContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_returnStmt; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitReturnStmt(this); - else return visitor.visitChildren(this); - } - } - - public final ReturnStmtContext returnStmt() throws RecognitionException { - ReturnStmtContext _localctx = new ReturnStmtContext(_ctx, getState()); - enterRule(_localctx, 36, RULE_returnStmt); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(215); - match(T__21); - setState(217); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__12) | (1L << T__24) | (1L << T__25) | (1L << T__26) | (1L << T__27) | (1L << Integer) | (1L << Boolean) | (1L << Ident))) != 0)) { - { - setState(216); - expr(0); - } - } - - setState(219); - match(T__10); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class NewExprContext extends ParserRuleContext { - public NewExprContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_newExpr; } - - public NewExprContext() { } - public void copyFrom(NewExprContext ctx) { - super.copyFrom(ctx); - } - } - public static class NewObjectArrayContext extends NewExprContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public NewObjectArrayContext(NewExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitNewObjectArray(this); - else return visitor.visitChildren(this); - } - } - public static class NewPrimitiveArrayContext extends NewExprContext { - public PrimitiveTypeContext primitiveType() { - return getRuleContext(PrimitiveTypeContext.class,0); - } - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public NewPrimitiveArrayContext(NewExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitNewPrimitiveArray(this); - else return visitor.visitChildren(this); - } - } - public static class NewObjectContext extends NewExprContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public NewObjectContext(NewExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitNewObject(this); - else return visitor.visitChildren(this); - } - } - - public final NewExprContext newExpr() throws RecognitionException { - NewExprContext _localctx = new NewExprContext(_ctx, getState()); - enterRule(_localctx, 38, RULE_newExpr); - try { - setState(237); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,23,_ctx) ) { - case 1: - _localctx = new NewObjectContext(_localctx); - enterOuterAlt(_localctx, 1); - { - setState(221); - match(T__22); - setState(222); - match(Ident); - setState(223); - match(T__12); - setState(224); - match(T__13); - } - break; - case 2: - _localctx = new NewObjectArrayContext(_localctx); - enterOuterAlt(_localctx, 2); - { - setState(225); - match(T__22); - setState(226); - match(Ident); - setState(227); - match(T__1); - setState(228); - expr(0); - setState(229); - match(T__2); - } - break; - case 3: - _localctx = new NewPrimitiveArrayContext(_localctx); - enterOuterAlt(_localctx, 3); - { - setState(231); - match(T__22); - setState(232); - primitiveType(); - setState(233); - match(T__1); - setState(234); - expr(0); - setState(235); - match(T__2); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ReadExprContext extends ParserRuleContext { - public ReadExprContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_readExpr; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitReadExpr(this); - else return visitor.visitChildren(this); - } - } - - public final ReadExprContext readExpr() throws RecognitionException { - ReadExprContext _localctx = new ReadExprContext(_ctx, getState()); - enterRule(_localctx, 40, RULE_readExpr); - try { - enterOuterAlt(_localctx, 1); - { - setState(239); - match(T__23); - setState(240); - match(T__12); - setState(241); - match(T__13); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ActualParamListContext extends ParserRuleContext { - public List expr() { - return getRuleContexts(ExprContext.class); - } - public ExprContext expr(int i) { - return getRuleContext(ExprContext.class,i); - } - public ActualParamListContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_actualParamList; } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitActualParamList(this); - else return visitor.visitChildren(this); - } - } - - public final ActualParamListContext actualParamList() throws RecognitionException { - ActualParamListContext _localctx = new ActualParamListContext(_ctx, getState()); - enterRule(_localctx, 42, RULE_actualParamList); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(243); - expr(0); - setState(248); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==T__9) { - { - { - setState(244); - match(T__9); - setState(245); - expr(0); - } - } - setState(250); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class IdentAccessContext extends ParserRuleContext { - public IdentAccessContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_identAccess; } - - public IdentAccessContext() { } - public void copyFrom(IdentAccessContext ctx) { - super.copyFrom(ctx); - } - } - public static class AccessThisContext extends IdentAccessContext { - public AccessThisContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessThis(this); - else return visitor.visitChildren(this); - } - } - public static class AccessLocalFieldContext extends IdentAccessContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public AccessLocalFieldContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessLocalField(this); - else return visitor.visitChildren(this); - } - } - public static class AccessObjectFieldContext extends IdentAccessContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public AccessObjectFieldContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessObjectField(this); - else return visitor.visitChildren(this); - } - } - public static class AccessLocalMethodContext extends IdentAccessContext { - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ActualParamListContext actualParamList() { - return getRuleContext(ActualParamListContext.class,0); - } - public AccessLocalMethodContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessLocalMethod(this); - else return visitor.visitChildren(this); - } - } - public static class AccessArrayContext extends IdentAccessContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public AccessArrayContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessArray(this); - else return visitor.visitChildren(this); - } - } - public static class AccessObjectMethodContext extends IdentAccessContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public TerminalNode Ident() { return getToken(JavaliParser.Ident, 0); } - public ActualParamListContext actualParamList() { - return getRuleContext(ActualParamListContext.class,0); - } - public AccessObjectMethodContext(IdentAccessContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitAccessObjectMethod(this); - else return visitor.visitChildren(this); - } - } - - public final IdentAccessContext identAccess() throws RecognitionException { - return identAccess(0); - } - - private IdentAccessContext identAccess(int _p) throws RecognitionException { - ParserRuleContext _parentctx = _ctx; - int _parentState = getState(); - IdentAccessContext _localctx = new IdentAccessContext(_ctx, _parentState); - IdentAccessContext _prevctx = _localctx; - int _startState = 44; - enterRecursionRule(_localctx, 44, RULE_identAccess, _p); - int _la; - try { - int _alt; - enterOuterAlt(_localctx, 1); - { - setState(260); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,26,_ctx) ) { - case 1: - { - _localctx = new AccessLocalFieldContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - - setState(252); - match(Ident); - } - break; - case 2: - { - _localctx = new AccessThisContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(253); - match(T__24); - } - break; - case 3: - { - _localctx = new AccessLocalMethodContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(254); - match(Ident); - setState(255); - match(T__12); - setState(257); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__12) | (1L << T__24) | (1L << T__25) | (1L << T__26) | (1L << T__27) | (1L << Integer) | (1L << Boolean) | (1L << Ident))) != 0)) { - { - setState(256); - actualParamList(); - } - } - - setState(259); - match(T__13); - } - break; - } - _ctx.stop = _input.LT(-1); - setState(280); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,29,_ctx); - while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - if ( _parseListeners!=null ) triggerExitRuleEvent(); - _prevctx = _localctx; - { - setState(278); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,28,_ctx) ) { - case 1: - { - _localctx = new AccessObjectFieldContext(new IdentAccessContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_identAccess); - setState(262); - if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)"); - setState(263); - match(T__14); - setState(264); - match(Ident); - } - break; - case 2: - { - _localctx = new AccessArrayContext(new IdentAccessContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_identAccess); - setState(265); - if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)"); - setState(266); - match(T__1); - setState(267); - expr(0); - setState(268); - match(T__2); - } - break; - case 3: - { - _localctx = new AccessObjectMethodContext(new IdentAccessContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_identAccess); - setState(270); - if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)"); - setState(271); - match(T__14); - setState(272); - match(Ident); - setState(273); - match(T__12); - setState(275); - _errHandler.sync(this); - _la = _input.LA(1); - if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << T__12) | (1L << T__24) | (1L << T__25) | (1L << T__26) | (1L << T__27) | (1L << Integer) | (1L << Boolean) | (1L << Ident))) != 0)) { - { - setState(274); - actualParamList(); - } - } - - setState(277); - match(T__13); - } - break; - } - } - } - setState(282); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,29,_ctx); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - unrollRecursionContexts(_parentctx); - } - return _localctx; - } - - public static class ExprContext extends ParserRuleContext { - public ExprContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_expr; } - - public ExprContext() { } - public void copyFrom(ExprContext ctx) { - super.copyFrom(ctx); - } - } - public static class ExprBinaryContext extends ExprContext { - public List expr() { - return getRuleContexts(ExprContext.class); - } - public ExprContext expr(int i) { - return getRuleContext(ExprContext.class,i); - } - public ExprBinaryContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprBinary(this); - else return visitor.visitChildren(this); - } - } - public static class ExprCastContext extends ExprContext { - public ReferenceTypeContext referenceType() { - return getRuleContext(ReferenceTypeContext.class,0); - } - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public ExprCastContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprCast(this); - else return visitor.visitChildren(this); - } - } - public static class ExprParenthesesContext extends ExprContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public ExprParenthesesContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprParentheses(this); - else return visitor.visitChildren(this); - } - } - public static class ExprUnaryContext extends ExprContext { - public ExprContext expr() { - return getRuleContext(ExprContext.class,0); - } - public ExprUnaryContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprUnary(this); - else return visitor.visitChildren(this); - } - } - public static class ExprConstantContext extends ExprContext { - public LiteralContext literal() { - return getRuleContext(LiteralContext.class,0); - } - public ExprConstantContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprConstant(this); - else return visitor.visitChildren(this); - } - } - public static class ExprIdentAccessContext extends ExprContext { - public IdentAccessContext identAccess() { - return getRuleContext(IdentAccessContext.class,0); - } - public ExprIdentAccessContext(ExprContext ctx) { copyFrom(ctx); } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof JavaliVisitor ) return ((JavaliVisitor)visitor).visitExprIdentAccess(this); - else return visitor.visitChildren(this); - } - } - - public final ExprContext expr() throws RecognitionException { - return expr(0); - } - - private ExprContext expr(int _p) throws RecognitionException { - ParserRuleContext _parentctx = _ctx; - int _parentState = getState(); - ExprContext _localctx = new ExprContext(_ctx, _parentState); - ExprContext _prevctx = _localctx; - int _startState = 46; - enterRecursionRule(_localctx, 46, RULE_expr, _p); - int _la; - try { - int _alt; - enterOuterAlt(_localctx, 1); - { - setState(297); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,30,_ctx) ) { - case 1: - { - _localctx = new ExprConstantContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - - setState(284); - literal(); - } - break; - case 2: - { - _localctx = new ExprIdentAccessContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(285); - identAccess(0); - } - break; - case 3: - { - _localctx = new ExprParenthesesContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(286); - match(T__12); - setState(287); - expr(0); - setState(288); - match(T__13); - } - break; - case 4: - { - _localctx = new ExprUnaryContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(290); - _la = _input.LA(1); - if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__25) | (1L << T__26) | (1L << T__27))) != 0)) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(291); - expr(8); - } - break; - case 5: - { - _localctx = new ExprCastContext(_localctx); - _ctx = _localctx; - _prevctx = _localctx; - setState(292); - match(T__12); - setState(293); - referenceType(); - setState(294); - match(T__13); - setState(295); - expr(7); - } - break; - } - _ctx.stop = _input.LT(-1); - setState(319); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,32,_ctx); - while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - if ( _parseListeners!=null ) triggerExitRuleEvent(); - _prevctx = _localctx; - { - setState(317); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,31,_ctx) ) { - case 1: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(299); - if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); - setState(300); - _la = _input.LA(1); - if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__28) | (1L << T__29) | (1L << T__30))) != 0)) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(301); - expr(7); - } - break; - case 2: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(302); - if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)"); - setState(303); - _la = _input.LA(1); - if ( !(_la==T__25 || _la==T__26) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(304); - expr(6); - } - break; - case 3: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(305); - if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)"); - setState(306); - _la = _input.LA(1); - if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__31) | (1L << T__32) | (1L << T__33) | (1L << T__34))) != 0)) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(307); - expr(5); - } - break; - case 4: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(308); - if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)"); - setState(309); - _la = _input.LA(1); - if ( !(_la==T__35 || _la==T__36) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(310); - expr(4); - } - break; - case 5: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(311); - if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); - setState(312); - match(T__37); - setState(313); - expr(3); - } - break; - case 6: - { - _localctx = new ExprBinaryContext(new ExprContext(_parentctx, _parentState)); - pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(314); - if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)"); - setState(315); - match(T__38); - setState(316); - expr(2); - } - break; - } - } - } - setState(321); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,32,_ctx); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - unrollRecursionContexts(_parentctx); - } - return _localctx; - } - - public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { - switch (ruleIndex) { - case 22: - return identAccess_sempred((IdentAccessContext)_localctx, predIndex); - case 23: - return expr_sempred((ExprContext)_localctx, predIndex); - } - return true; - } - private boolean identAccess_sempred(IdentAccessContext _localctx, int predIndex) { - switch (predIndex) { - case 0: - return precpred(_ctx, 4); - case 1: - return precpred(_ctx, 3); - case 2: - return precpred(_ctx, 1); - } - return true; - } - private boolean expr_sempred(ExprContext _localctx, int predIndex) { - switch (predIndex) { - case 3: - return precpred(_ctx, 6); - case 4: - return precpred(_ctx, 5); - case 5: - return precpred(_ctx, 4); - case 6: - return precpred(_ctx, 3); - case 7: - return precpred(_ctx, 2); - case 8: - return precpred(_ctx, 1); - } - return true; - } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\60\u0145\4\2\t\2"+ - "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ - "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+ - "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+ - "\3\2\3\2\3\2\5\2\66\n\2\3\3\3\3\5\3:\n\3\3\4\3\4\5\4>\n\4\3\5\3\5\3\5"+ - "\3\5\3\5\3\5\3\5\5\5G\n\5\3\6\3\6\3\7\6\7L\n\7\r\7\16\7M\3\7\3\7\3\b\3"+ - "\b\3\b\3\b\5\bV\n\b\3\b\3\b\3\b\3\b\3\t\3\t\7\t^\n\t\f\t\16\ta\13\t\3"+ - "\n\3\n\3\n\3\n\7\ng\n\n\f\n\16\nj\13\n\3\n\3\n\3\13\3\13\5\13p\n\13\3"+ - "\13\3\13\3\13\5\13u\n\13\3\13\3\13\3\13\7\13z\n\13\f\13\16\13}\13\13\3"+ - "\13\7\13\u0080\n\13\f\13\16\13\u0083\13\13\3\13\3\13\3\f\3\f\3\f\3\f\3"+ - "\f\3\f\7\f\u008d\n\f\f\f\16\f\u0090\13\f\3\r\3\r\3\r\3\r\3\r\3\r\5\r\u0098"+ - "\n\r\3\16\3\16\7\16\u009c\n\16\f\16\16\16\u009f\13\16\3\16\3\16\3\17\3"+ - "\17\3\17\5\17\u00a6\n\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\5\17\u00af"+ - "\n\17\3\17\3\17\3\17\5\17\u00b4\n\17\3\20\3\20\3\20\3\20\3\20\5\20\u00bb"+ - "\n\20\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\5\21"+ - "\u00c9\n\21\3\22\3\22\3\22\3\22\3\22\3\22\3\22\5\22\u00d2\n\22\3\23\3"+ - "\23\3\23\3\23\3\23\3\23\3\24\3\24\5\24\u00dc\n\24\3\24\3\24\3\25\3\25"+ - "\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25"+ - "\5\25\u00f0\n\25\3\26\3\26\3\26\3\26\3\27\3\27\3\27\7\27\u00f9\n\27\f"+ - "\27\16\27\u00fc\13\27\3\30\3\30\3\30\3\30\3\30\3\30\5\30\u0104\n\30\3"+ - "\30\5\30\u0107\n\30\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3\30"+ - "\3\30\3\30\3\30\5\30\u0116\n\30\3\30\7\30\u0119\n\30\f\30\16\30\u011c"+ - "\13\30\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31"+ - "\3\31\5\31\u012c\n\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31"+ - "\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\7\31\u0140\n\31\f\31\16\31\u0143"+ - "\13\31\3\31\2\4.\60\32\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,"+ - ".\60\2\b\3\2\6\7\3\2\34\36\3\2\37!\3\2\34\35\3\2\"%\3\2&\'\2\u015d\2\65"+ - "\3\2\2\2\49\3\2\2\2\6=\3\2\2\2\bF\3\2\2\2\nH\3\2\2\2\fK\3\2\2\2\16Q\3"+ - "\2\2\2\20_\3\2\2\2\22b\3\2\2\2\24o\3\2\2\2\26\u0086\3\2\2\2\30\u0097\3"+ - "\2\2\2\32\u0099\3\2\2\2\34\u00b3\3\2\2\2\36\u00b5\3\2\2\2 \u00c8\3\2\2"+ - "\2\"\u00ca\3\2\2\2$\u00d3\3\2\2\2&\u00d9\3\2\2\2(\u00ef\3\2\2\2*\u00f1"+ - "\3\2\2\2,\u00f5\3\2\2\2.\u0106\3\2\2\2\60\u012b\3\2\2\2\62\66\7\3\2\2"+ - "\63\66\7+\2\2\64\66\7*\2\2\65\62\3\2\2\2\65\63\3\2\2\2\65\64\3\2\2\2\66"+ - "\3\3\2\2\2\67:\5\n\6\28:\5\6\4\29\67\3\2\2\298\3\2\2\2:\5\3\2\2\2;>\7"+ - ",\2\2<>\5\b\5\2=;\3\2\2\2=<\3\2\2\2>\7\3\2\2\2?@\7,\2\2@A\7\4\2\2AG\7"+ - "\5\2\2BC\5\n\6\2CD\7\4\2\2DE\7\5\2\2EG\3\2\2\2F?\3\2\2\2FB\3\2\2\2G\t"+ - "\3\2\2\2HI\t\2\2\2I\13\3\2\2\2JL\5\16\b\2KJ\3\2\2\2LM\3\2\2\2MK\3\2\2"+ - "\2MN\3\2\2\2NO\3\2\2\2OP\7\2\2\3P\r\3\2\2\2QR\7\b\2\2RU\7,\2\2ST\7\t\2"+ - "\2TV\7,\2\2US\3\2\2\2UV\3\2\2\2VW\3\2\2\2WX\7\n\2\2XY\5\20\t\2YZ\7\13"+ - "\2\2Z\17\3\2\2\2[^\5\22\n\2\\^\5\24\13\2][\3\2\2\2]\\\3\2\2\2^a\3\2\2"+ - "\2_]\3\2\2\2_`\3\2\2\2`\21\3\2\2\2a_\3\2\2\2bc\5\4\3\2ch\7,\2\2de\7\f"+ - "\2\2eg\7,\2\2fd\3\2\2\2gj\3\2\2\2hf\3\2\2\2hi\3\2\2\2ik\3\2\2\2jh\3\2"+ - "\2\2kl\7\r\2\2l\23\3\2\2\2mp\5\4\3\2np\7\16\2\2om\3\2\2\2on\3\2\2\2pq"+ - "\3\2\2\2qr\7,\2\2rt\7\17\2\2su\5\26\f\2ts\3\2\2\2tu\3\2\2\2uv\3\2\2\2"+ - "vw\7\20\2\2w{\7\n\2\2xz\5\22\n\2yx\3\2\2\2z}\3\2\2\2{y\3\2\2\2{|\3\2\2"+ - "\2|\u0081\3\2\2\2}{\3\2\2\2~\u0080\5\30\r\2\177~\3\2\2\2\u0080\u0083\3"+ - "\2\2\2\u0081\177\3\2\2\2\u0081\u0082\3\2\2\2\u0082\u0084\3\2\2\2\u0083"+ - "\u0081\3\2\2\2\u0084\u0085\7\13\2\2\u0085\25\3\2\2\2\u0086\u0087\5\4\3"+ - "\2\u0087\u008e\7,\2\2\u0088\u0089\7\f\2\2\u0089\u008a\5\4\3\2\u008a\u008b"+ - "\7,\2\2\u008b\u008d\3\2\2\2\u008c\u0088\3\2\2\2\u008d\u0090\3\2\2\2\u008e"+ - "\u008c\3\2\2\2\u008e\u008f\3\2\2\2\u008f\27\3\2\2\2\u0090\u008e\3\2\2"+ - "\2\u0091\u0098\5\36\20\2\u0092\u0098\5\34\17\2\u0093\u0098\5\"\22\2\u0094"+ - "\u0098\5$\23\2\u0095\u0098\5&\24\2\u0096\u0098\5 \21\2\u0097\u0091\3\2"+ - "\2\2\u0097\u0092\3\2\2\2\u0097\u0093\3\2\2\2\u0097\u0094\3\2\2\2\u0097"+ - "\u0095\3\2\2\2\u0097\u0096\3\2\2\2\u0098\31\3\2\2\2\u0099\u009d\7\n\2"+ - "\2\u009a\u009c\5\30\r\2\u009b\u009a\3\2\2\2\u009c\u009f\3\2\2\2\u009d"+ - "\u009b\3\2\2\2\u009d\u009e\3\2\2\2\u009e\u00a0\3\2\2\2\u009f\u009d\3\2"+ - "\2\2\u00a0\u00a1\7\13\2\2\u00a1\33\3\2\2\2\u00a2\u00a3\7,\2\2\u00a3\u00a5"+ - "\7\17\2\2\u00a4\u00a6\5,\27\2\u00a5\u00a4\3\2\2\2\u00a5\u00a6\3\2\2\2"+ - "\u00a6\u00a7\3\2\2\2\u00a7\u00a8\7\20\2\2\u00a8\u00b4\7\r\2\2\u00a9\u00aa"+ - "\5.\30\2\u00aa\u00ab\7\21\2\2\u00ab\u00ac\7,\2\2\u00ac\u00ae\7\17\2\2"+ - "\u00ad\u00af\5,\27\2\u00ae\u00ad\3\2\2\2\u00ae\u00af\3\2\2\2\u00af\u00b0"+ - "\3\2\2\2\u00b0\u00b1\7\20\2\2\u00b1\u00b2\7\r\2\2\u00b2\u00b4\3\2\2\2"+ - "\u00b3\u00a2\3\2\2\2\u00b3\u00a9\3\2\2\2\u00b4\35\3\2\2\2\u00b5\u00b6"+ - "\5.\30\2\u00b6\u00ba\7\22\2\2\u00b7\u00bb\5\60\31\2\u00b8\u00bb\5(\25"+ - "\2\u00b9\u00bb\5*\26\2\u00ba\u00b7\3\2\2\2\u00ba\u00b8\3\2\2\2\u00ba\u00b9"+ - "\3\2\2\2\u00bb\u00bc\3\2\2\2\u00bc\u00bd\7\r\2\2\u00bd\37\3\2\2\2\u00be"+ - "\u00bf\7\23\2\2\u00bf\u00c0\7\17\2\2\u00c0\u00c1\5\60\31\2\u00c1\u00c2"+ - "\7\20\2\2\u00c2\u00c3\7\r\2\2\u00c3\u00c9\3\2\2\2\u00c4\u00c5\7\24\2\2"+ - "\u00c5\u00c6\7\17\2\2\u00c6\u00c7\7\20\2\2\u00c7\u00c9\7\r\2\2\u00c8\u00be"+ - "\3\2\2\2\u00c8\u00c4\3\2\2\2\u00c9!\3\2\2\2\u00ca\u00cb\7\25\2\2\u00cb"+ - "\u00cc\7\17\2\2\u00cc\u00cd\5\60\31\2\u00cd\u00ce\7\20\2\2\u00ce\u00d1"+ - "\5\32\16\2\u00cf\u00d0\7\26\2\2\u00d0\u00d2\5\32\16\2\u00d1\u00cf\3\2"+ - "\2\2\u00d1\u00d2\3\2\2\2\u00d2#\3\2\2\2\u00d3\u00d4\7\27\2\2\u00d4\u00d5"+ - "\7\17\2\2\u00d5\u00d6\5\60\31\2\u00d6\u00d7\7\20\2\2\u00d7\u00d8\5\32"+ - "\16\2\u00d8%\3\2\2\2\u00d9\u00db\7\30\2\2\u00da\u00dc\5\60\31\2\u00db"+ - "\u00da\3\2\2\2\u00db\u00dc\3\2\2\2\u00dc\u00dd\3\2\2\2\u00dd\u00de\7\r"+ - "\2\2\u00de\'\3\2\2\2\u00df\u00e0\7\31\2\2\u00e0\u00e1\7,\2\2\u00e1\u00e2"+ - "\7\17\2\2\u00e2\u00f0\7\20\2\2\u00e3\u00e4\7\31\2\2\u00e4\u00e5\7,\2\2"+ - "\u00e5\u00e6\7\4\2\2\u00e6\u00e7\5\60\31\2\u00e7\u00e8\7\5\2\2\u00e8\u00f0"+ - "\3\2\2\2\u00e9\u00ea\7\31\2\2\u00ea\u00eb\5\n\6\2\u00eb\u00ec\7\4\2\2"+ - "\u00ec\u00ed\5\60\31\2\u00ed\u00ee\7\5\2\2\u00ee\u00f0\3\2\2\2\u00ef\u00df"+ - "\3\2\2\2\u00ef\u00e3\3\2\2\2\u00ef\u00e9\3\2\2\2\u00f0)\3\2\2\2\u00f1"+ - "\u00f2\7\32\2\2\u00f2\u00f3\7\17\2\2\u00f3\u00f4\7\20\2\2\u00f4+\3\2\2"+ - "\2\u00f5\u00fa\5\60\31\2\u00f6\u00f7\7\f\2\2\u00f7\u00f9\5\60\31\2\u00f8"+ - "\u00f6\3\2\2\2\u00f9\u00fc\3\2\2\2\u00fa\u00f8\3\2\2\2\u00fa\u00fb\3\2"+ - "\2\2\u00fb-\3\2\2\2\u00fc\u00fa\3\2\2\2\u00fd\u00fe\b\30\1\2\u00fe\u0107"+ - "\7,\2\2\u00ff\u0107\7\33\2\2\u0100\u0101\7,\2\2\u0101\u0103\7\17\2\2\u0102"+ - "\u0104\5,\27\2\u0103\u0102\3\2\2\2\u0103\u0104\3\2\2\2\u0104\u0105\3\2"+ - "\2\2\u0105\u0107\7\20\2\2\u0106\u00fd\3\2\2\2\u0106\u00ff\3\2\2\2\u0106"+ - "\u0100\3\2\2\2\u0107\u011a\3\2\2\2\u0108\u0109\f\6\2\2\u0109\u010a\7\21"+ - "\2\2\u010a\u0119\7,\2\2\u010b\u010c\f\5\2\2\u010c\u010d\7\4\2\2\u010d"+ - "\u010e\5\60\31\2\u010e\u010f\7\5\2\2\u010f\u0119\3\2\2\2\u0110\u0111\f"+ - "\3\2\2\u0111\u0112\7\21\2\2\u0112\u0113\7,\2\2\u0113\u0115\7\17\2\2\u0114"+ - "\u0116\5,\27\2\u0115\u0114\3\2\2\2\u0115\u0116\3\2\2\2\u0116\u0117\3\2"+ - "\2\2\u0117\u0119\7\20\2\2\u0118\u0108\3\2\2\2\u0118\u010b\3\2\2\2\u0118"+ - "\u0110\3\2\2\2\u0119\u011c\3\2\2\2\u011a\u0118\3\2\2\2\u011a\u011b\3\2"+ - "\2\2\u011b/\3\2\2\2\u011c\u011a\3\2\2\2\u011d\u011e\b\31\1\2\u011e\u012c"+ - "\5\2\2\2\u011f\u012c\5.\30\2\u0120\u0121\7\17\2\2\u0121\u0122\5\60\31"+ - "\2\u0122\u0123\7\20\2\2\u0123\u012c\3\2\2\2\u0124\u0125\t\3\2\2\u0125"+ - "\u012c\5\60\31\n\u0126\u0127\7\17\2\2\u0127\u0128\5\6\4\2\u0128\u0129"+ - "\7\20\2\2\u0129\u012a\5\60\31\t\u012a\u012c\3\2\2\2\u012b\u011d\3\2\2"+ - "\2\u012b\u011f\3\2\2\2\u012b\u0120\3\2\2\2\u012b\u0124\3\2\2\2\u012b\u0126"+ - "\3\2\2\2\u012c\u0141\3\2\2\2\u012d\u012e\f\b\2\2\u012e\u012f\t\4\2\2\u012f"+ - "\u0140\5\60\31\t\u0130\u0131\f\7\2\2\u0131\u0132\t\5\2\2\u0132\u0140\5"+ - "\60\31\b\u0133\u0134\f\6\2\2\u0134\u0135\t\6\2\2\u0135\u0140\5\60\31\7"+ - "\u0136\u0137\f\5\2\2\u0137\u0138\t\7\2\2\u0138\u0140\5\60\31\6\u0139\u013a"+ - "\f\4\2\2\u013a\u013b\7(\2\2\u013b\u0140\5\60\31\5\u013c\u013d\f\3\2\2"+ - "\u013d\u013e\7)\2\2\u013e\u0140\5\60\31\4\u013f\u012d\3\2\2\2\u013f\u0130"+ - "\3\2\2\2\u013f\u0133\3\2\2\2\u013f\u0136\3\2\2\2\u013f\u0139\3\2\2\2\u013f"+ - "\u013c\3\2\2\2\u0140\u0143\3\2\2\2\u0141\u013f\3\2\2\2\u0141\u0142\3\2"+ - "\2\2\u0142\61\3\2\2\2\u0143\u0141\3\2\2\2#\659=FMU]_hot{\u0081\u008e\u0097"+ - "\u009d\u00a5\u00ae\u00b3\u00ba\u00c8\u00d1\u00db\u00ef\u00fa\u0103\u0106"+ - "\u0115\u0118\u011a\u012b\u013f\u0141"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/cd/frontend/parser/JavaliVisitor.java b/src/cd/frontend/parser/JavaliVisitor.java deleted file mode 100644 index fca4db5..0000000 --- a/src/cd/frontend/parser/JavaliVisitor.java +++ /dev/null @@ -1,278 +0,0 @@ -// Generated from /home/carlos/eth/cd/nop90/HW2/src/cd/frontend/parser/Javali.g4 by ANTLR 4.7.1 - - // Java header - package cd.frontend.parser; - -import org.antlr.v4.runtime.tree.ParseTreeVisitor; - -/** - * This interface defines a complete generic visitor for a parse tree produced - * by {@link JavaliParser}. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public interface JavaliVisitor extends ParseTreeVisitor { - /** - * Visit a parse tree produced by the {@code NullLiteral} - * labeled alternative in {@link JavaliParser#literal}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitNullLiteral(JavaliParser.NullLiteralContext ctx); - /** - * Visit a parse tree produced by the {@code BoolLiteral} - * labeled alternative in {@link JavaliParser#literal}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitBoolLiteral(JavaliParser.BoolLiteralContext ctx); - /** - * Visit a parse tree produced by the {@code IntLiteral} - * labeled alternative in {@link JavaliParser#literal}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitIntLiteral(JavaliParser.IntLiteralContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#type}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitType(JavaliParser.TypeContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#referenceType}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitReferenceType(JavaliParser.ReferenceTypeContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#arrayType}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitArrayType(JavaliParser.ArrayTypeContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#primitiveType}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitPrimitiveType(JavaliParser.PrimitiveTypeContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#unit}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitUnit(JavaliParser.UnitContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#classDecl}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitClassDecl(JavaliParser.ClassDeclContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#memberList}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitMemberList(JavaliParser.MemberListContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#varDecl}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitVarDecl(JavaliParser.VarDeclContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#methodDecl}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitMethodDecl(JavaliParser.MethodDeclContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#formalParamList}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitFormalParamList(JavaliParser.FormalParamListContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#stmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitStmt(JavaliParser.StmtContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#stmtBlock}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitStmtBlock(JavaliParser.StmtBlockContext ctx); - /** - * Visit a parse tree produced by the {@code LocalMethodCallStmt} - * labeled alternative in {@link JavaliParser#methodCallStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitLocalMethodCallStmt(JavaliParser.LocalMethodCallStmtContext ctx); - /** - * Visit a parse tree produced by the {@code ObjectMethodCallStmt} - * labeled alternative in {@link JavaliParser#methodCallStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitObjectMethodCallStmt(JavaliParser.ObjectMethodCallStmtContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#assignmentStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAssignmentStmt(JavaliParser.AssignmentStmtContext ctx); - /** - * Visit a parse tree produced by the {@code Write} - * labeled alternative in {@link JavaliParser#writeStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitWrite(JavaliParser.WriteContext ctx); - /** - * Visit a parse tree produced by the {@code WriteLn} - * labeled alternative in {@link JavaliParser#writeStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitWriteLn(JavaliParser.WriteLnContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#ifStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitIfStmt(JavaliParser.IfStmtContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#whileStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitWhileStmt(JavaliParser.WhileStmtContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#returnStmt}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitReturnStmt(JavaliParser.ReturnStmtContext ctx); - /** - * Visit a parse tree produced by the {@code NewObject} - * labeled alternative in {@link JavaliParser#newExpr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitNewObject(JavaliParser.NewObjectContext ctx); - /** - * Visit a parse tree produced by the {@code NewObjectArray} - * labeled alternative in {@link JavaliParser#newExpr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitNewObjectArray(JavaliParser.NewObjectArrayContext ctx); - /** - * Visit a parse tree produced by the {@code NewPrimitiveArray} - * labeled alternative in {@link JavaliParser#newExpr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitNewPrimitiveArray(JavaliParser.NewPrimitiveArrayContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#readExpr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitReadExpr(JavaliParser.ReadExprContext ctx); - /** - * Visit a parse tree produced by {@link JavaliParser#actualParamList}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitActualParamList(JavaliParser.ActualParamListContext ctx); - /** - * Visit a parse tree produced by the {@code AccessThis} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessThis(JavaliParser.AccessThisContext ctx); - /** - * Visit a parse tree produced by the {@code AccessLocalField} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessLocalField(JavaliParser.AccessLocalFieldContext ctx); - /** - * Visit a parse tree produced by the {@code AccessObjectField} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessObjectField(JavaliParser.AccessObjectFieldContext ctx); - /** - * Visit a parse tree produced by the {@code AccessLocalMethod} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessLocalMethod(JavaliParser.AccessLocalMethodContext ctx); - /** - * Visit a parse tree produced by the {@code AccessArray} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessArray(JavaliParser.AccessArrayContext ctx); - /** - * Visit a parse tree produced by the {@code AccessObjectMethod} - * labeled alternative in {@link JavaliParser#identAccess}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitAccessObjectMethod(JavaliParser.AccessObjectMethodContext ctx); - /** - * Visit a parse tree produced by the {@code ExprBinary} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprBinary(JavaliParser.ExprBinaryContext ctx); - /** - * Visit a parse tree produced by the {@code ExprCast} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprCast(JavaliParser.ExprCastContext ctx); - /** - * Visit a parse tree produced by the {@code ExprParentheses} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprParentheses(JavaliParser.ExprParenthesesContext ctx); - /** - * Visit a parse tree produced by the {@code ExprUnary} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprUnary(JavaliParser.ExprUnaryContext ctx); - /** - * Visit a parse tree produced by the {@code ExprConstant} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprConstant(JavaliParser.ExprConstantContext ctx); - /** - * Visit a parse tree produced by the {@code ExprIdentAccess} - * labeled alternative in {@link JavaliParser#expr}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitExprIdentAccess(JavaliParser.ExprIdentAccessContext ctx); -} \ No newline at end of file diff --git a/src/cd/frontend/parser/ParseFailure.java b/src/cd/frontend/parser/ParseFailure.java deleted file mode 100644 index 71ae266..0000000 --- a/src/cd/frontend/parser/ParseFailure.java +++ /dev/null @@ -1,9 +0,0 @@ -package cd.frontend.parser; - -public class ParseFailure extends RuntimeException { - private static final long serialVersionUID = -949992757679367939L; - public ParseFailure(int line, String string) { - super(String.format("Parse failure on line %d: %s", - line, string)); - } -} diff --git a/src/cd/frontend/semantic/ExprAnalyzer.java b/src/cd/frontend/semantic/ExprAnalyzer.java new file mode 100644 index 0000000..ee81ec0 --- /dev/null +++ b/src/cd/frontend/semantic/ExprAnalyzer.java @@ -0,0 +1,346 @@ +package cd.frontend.semantic; + +import cd.frontend.semantic.SemanticAnalyzer.SemanticLocation; +import cd.frontend.semantic.SemanticFailure.Cause; +import cd.ir.Ast; +import cd.ir.Ast.*; +import cd.ir.ExprVisitor; +import cd.ir.Symbol; +import cd.ir.Symbol.*; + +import java.util.List; + +/** + * Semantic analyzer for {@link Expr} nodes in the pattern of a visitor.
+ * All methods may throw {@link SemanticFailure} if an error is discovered, + * with the appropriate {@link Cause}.
+ * The current implementation returns the resulting {@link Symbol} for each expression and + * uses the {@link ClassDecl} argument to obtain the self-reference in the {@link ThisRef} node. + *
Some methods may throw a {@link RuntimeException} if they are in a + * illegal situation, given the grammar of Javali and current implementation. + * This signals an error in the implementation, not a user-caused error. + * @see cd.frontend.semantic.StmtAnalyzer + * @author Carlos Galindo + * @author Levin Moser + */ +public class ExprAnalyzer extends ExprVisitor { + /** Reference to the main semantic analyzer, used to access the type list via + * {@link SemanticAnalyzer#findType(String)} */ + private SemanticAnalyzer sem; + + ExprAnalyzer(SemanticAnalyzer sem) { + this.sem = sem; + } + + /** + * Checks the possible semantic errors that can appear in a {@link BinaryOp} node + * @param ast The node describing the binary operation + * @param arg The class and method in which the operation is performed + * @return A {@link PrimitiveTypeSymbol} of resulting type, depending on the operation + * performed (either {@code int} or {@code boolean}) + * @throws SemanticFailure If the types of both operands aren't equal + * @throws SemanticFailure With {@code ==} or {@code !=} operators, if no argument's type is + * a subtype of the other + * @throws SemanticFailure If the type of the operands doesn't match the type + * of the operation (either {@code int} or {@code boolean} + * @throws RuntimeException If the implementation has missed any {@link BinaryOp.BOp} type + */ + @Override + public TypeSymbol binaryOp(BinaryOp ast, SemanticLocation arg) { + TypeSymbol leftType = visit(ast.left(), arg); + TypeSymbol rightType = visit(ast.right(), arg); + TypeSymbol desiredType; + TypeSymbol returnType = PrimitiveTypeSymbol.booleanType; + switch (ast.operator) { + case B_AND: + case B_OR: + desiredType = PrimitiveTypeSymbol.booleanType; + break; + case B_PLUS: + case B_MINUS: + case B_TIMES: + case B_DIV: + case B_MOD: + desiredType = PrimitiveTypeSymbol.intType; + returnType = desiredType; + break; + case B_LESS_THAN: + case B_GREATER_THAN: + case B_LESS_OR_EQUAL: + case B_GREATER_OR_EQUAL: + desiredType = PrimitiveTypeSymbol.intType; + break; + case B_EQUAL: + case B_NOT_EQUAL: + // Can take any pair of types that are a subtype of each other + desiredType = null; + break; + default: + throw new RuntimeException("Missing BOp in implementation of ExprAnalyzer#binaryOp(...)"); + } + + if (desiredType == null) { + if (leftType.isSubtypeOf(rightType) || rightType.isSubtypeOf(leftType)) + return returnType; + else + throw new SemanticFailure(Cause.TYPE_ERROR, + "Operation \"%s\" operation with incompatible types %s and %s", + ast.operator.repr, leftType, rightType); + } else if (leftType == rightType) { + if (leftType == desiredType) + return returnType; + else + throw new SemanticFailure(Cause.TYPE_ERROR, + "Arguments of %s operation must be of %s type, found %s", + ast.operator.repr, desiredType, leftType); + } else { + throw new SemanticFailure(Cause.TYPE_ERROR, + "Arguments of %s operation must be of same type %s, found %s and %s", + ast.operator.repr, desiredType, leftType, rightType); + } + } + + /** + * Obtains the {@code boolean} type + * @param ast Node describing the constant + * @param arg Class and method in which the expression exists + * @return {@link PrimitiveTypeSymbol} representing the {@code boolean} type + */ + @Override + public TypeSymbol booleanConst(BooleanConst ast, SemanticLocation arg) { + return PrimitiveTypeSymbol.booleanType; + } + + /** + * Obtains the {@code int} type (all reads in Javali result in an integer) + * @param ast Node describing the expression + * @param arg Class and method in which the expression exists + * @return {@link PrimitiveTypeSymbol} representing the {@code int} type + */ + @Override + public TypeSymbol builtInRead(BuiltInRead ast, SemanticLocation arg) { + return PrimitiveTypeSymbol.intType; + } + + /** + * Checks possible semantic errors in a {@link Cast} node.
+ * Uses {@link TypeSymbol#isSubtypeOf(TypeSymbol)} to determine if the types are compatible. + * @return The resulting type after the cast + * @throws SemanticFailure If the destination type doesn't exist + * @throws SemanticFailure If the types are incompatible (none is a subtype of the other) + */ + @Override + public TypeSymbol cast(Cast ast, SemanticLocation arg) { + TypeSymbol castType = sem.findType(ast.typeName); + TypeSymbol exprType = visit(ast.arg(), arg); + if (exprType.isSubtypeOf(castType) || castType.isSubtypeOf(exprType)) + return castType; + else + throw new SemanticFailure(Cause.TYPE_ERROR, + "Type %s cannot be casted to %s, as they are unrelated", exprType, castType); + } + + /** + * Checks possible semantic errors in a {@link Field} node. + * @param ast Node describing the field access + * @param arg Class and method in which the expression exists + * @return Field accessed, as defined in the corresponding {@link ClassSymbol} + * @throws SemanticFailure If the field to access doesn't exist + * @throws SemanticFailure If the expression in whose field is accessed + * is not a {@link ClassSymbol} + */ + @Override + public TypeSymbol field(Field ast, SemanticLocation arg) { + TypeSymbol variableType = visit(ast.arg(), arg); + if (!(variableType instanceof ClassSymbol)) + throw new SemanticFailure(Cause.TYPE_ERROR, + "The field of a %s variable cannot be accessed, it is not a object type", variableType); + ClassSymbol classType = (ClassSymbol) variableType; + VariableSymbol field = classType.getField(ast.fieldName); + if (field == null) + throw new SemanticFailure(Cause.NO_SUCH_FIELD, + "The field %s doesn't exist in class %s", + ast.fieldName, variableType); + else + return field.type; + } + + /** + * Checks possible semantic errors in a {@link Index} node. + * @param ast Node describing the index operation + * @param arg Class and method in which the expression exists + * @return Type of the elements of the array indexed + * @throws SemanticFailure If the index is not an integer + * @throws SemanticFailure If the expression indexed is not an array + */ + @Override + public TypeSymbol index(Index ast, SemanticLocation arg) { + TypeSymbol arrayType = visit(ast.left(), arg); + TypeSymbol indexType = visit(ast.right(), arg); + + if (indexType != PrimitiveTypeSymbol.intType) + throw new SemanticFailure(Cause.TYPE_ERROR, "The index must be a int, found %s", indexType); + else if (!(arrayType instanceof ArrayTypeSymbol)) + throw new SemanticFailure(Cause.TYPE_ERROR, "Expecting array type, found %s", arrayType); + else + return ((ArrayTypeSymbol) arrayType).elementType; + } + + /** + * Obtains the {@code int} type + * @param ast Node describing the constant + * @param arg Class and method in which the expression exists + * @return A PrimitiveTypeSymbol for the type int + */ + @Override + public TypeSymbol intConst(IntConst ast, SemanticLocation arg) { + return PrimitiveTypeSymbol.intType; + } + + /** + * Checks that the method referenced exists in the current scope and the typing of + * the parameters. + * @param ast Node describing the method call + * @param arg Class and method in which the expression exists + * @return The return type for the method called + * @throws SemanticFailure If the number of parameters doesn't match the declaration + * @throws SemanticFailure If the parameters' types don't match the declaration + * @throws SemanticFailure If the method doesn't exist + * @throws SemanticFailure If the {@link MethodCallExpr#receiver()} is not + * a object type (methods cannot be called on PrimitiveTypes or Arrays) + */ + @Override + public TypeSymbol methodCall(MethodCallExpr ast, SemanticLocation arg) { + TypeSymbol receiverType = visit(ast.receiver(), arg); + // Check receiver validity + if (!(receiverType instanceof ClassSymbol)) + throw new SemanticFailure(Cause.TYPE_ERROR, "Expected object class, found %s", receiverType); + // Find method symbol + ast.sym = sem.findMethod(ast.methodName, (ClassSymbol) receiverType); + if (ast.sym == null) + throw new SemanticFailure(Cause.NO_SUCH_METHOD, "Method %s(...) doesn't exist", ast.methodName); + // Compare expected with available parameters + List realParams = ast.argumentsWithoutReceiver(); + List expectedParams = ast.sym.parameters; + if (realParams.size() != expectedParams.size()) + throw new SemanticFailure(Cause.WRONG_NUMBER_OF_ARGUMENTS, + "%s call has %d parameters, expected %d", + ast.sym, realParams.size(), expectedParams.size()); + for (int i = 0; i < realParams.size(); i++) { + TypeSymbol realType = visit(realParams.get(i), arg); + TypeSymbol expectedType = expectedParams.get(i).type; + if (!realType.isSubtypeOf(expectedType)) + throw new SemanticFailure(Cause.TYPE_ERROR, "Parameter %d of %s of type %s, expected %s", + i, ast.sym, realType, expectedType); + } + return ast.sym.returnType; + } + + /** + * Checks for semantic errors in the creation of a new object of the specified type + * @param ast Node describing the new object expression + * @param arg Class and method in which the expression exists + * @return {@link ClassSymbol} corresponding to the type of the new object + * @throws SemanticFailure If the type referenced doesn't exist + */ + @Override + public TypeSymbol newObject(NewObject ast, SemanticLocation arg) { + return sem.findType(ast.typeName); + } + + /** + * Checks for semantic errors in the creation of a new array of the specified type and size + * @param ast Node describing the new array expression + * @param arg Class and method in which the expression exists + * @return ArrayTypeSymbol of the corresponding type + * @throws SemanticFailure If the array type doesn't exist + * @throws SemanticFailure If the expression indicating the size of the array is not an {@code int} + */ + @Override + public TypeSymbol newArray(NewArray ast, SemanticLocation arg) { + // Type exists (if it does, it is guaranteed by the grammar to be a ArrayTypeSymbol) + ArrayTypeSymbol type = (ArrayTypeSymbol) sem.findType(ast.typeName); + // Array length must be of type int + TypeSymbol indexType = visit(ast.arg(), arg); + if (indexType != PrimitiveTypeSymbol.intType) + throw new SemanticFailure(Cause.TYPE_ERROR, "Array size must be of type int, found %s", indexType); + else + return type; + } + + /** + * Obtains the {@code null} type + * @param ast Node describing the new object instantiation expression + * @param arg Class and method in which the expression exists + * @return The ClassSymbol corresponding to {@code null} + */ + @Override + public TypeSymbol nullConst(NullConst ast, SemanticLocation arg) { + return ClassSymbol.nullType; + } + + /** + * Obtains the reference to {@code this} + * @param ast The AST node + * @param arg Class and method in which the class reference is accessed + * @return The VariableSymbol {@code this} from the class + */ + @Override + public TypeSymbol thisRef(ThisRef ast, SemanticLocation arg) { + return arg.classSymbol.thisSymbol.type; + } + + /** + * Checks whether a {@link UnaryOp} is valid semantically + * @param ast The node describing the operation + * @param arg Class and method in which the expression exists + * @return The resulting type of the operation + * @throws SemanticFailure With "{@code !}" operator, if the operand is not a {@code boolean} + * @throws SemanticFailure With "{@code +}" or "{@code -}" operators, if the operand is not an {@code int} + */ + @Override + public TypeSymbol unaryOp(UnaryOp ast, SemanticLocation arg) { + TypeSymbol argType = visit(ast.arg(), arg); + + TypeSymbol desiredType = PrimitiveTypeSymbol.intType; + if (ast.operator.equals(Ast.UnaryOp.UOp.U_BOOL_NOT)) + desiredType = PrimitiveTypeSymbol.booleanType; + + if (argType == desiredType) + return desiredType; + else + throw new SemanticFailure(Cause.TYPE_ERROR, + "Operator %s expected operand of type %s, found %s", + ast.operator.repr, desiredType, argType); + } + + /** + * Checks whether the variable referenced by the {@link Var} node exists + * in the current scope, either as local variable, method parameter or field + * (including inherited fields) + *
In the process, the {@link Var} node is linked to the + * {@link VariableSymbol} + * @param ast Node describing the variable access + * @param arg Class and method that define the current scope in which the + * variable is looked for + * @return The {@link VariableSymbol} corresponding to the variable + * @throws SemanticFailure If the variable doesn't exist in the current scope + */ + @Override + public TypeSymbol var(Var ast, SemanticLocation arg) { + // Local variable + ast.sym = arg.getMethod().locals.get(ast.name); + if (ast.sym != null) + return ast.sym.type; + // Method parameter + for(VariableSymbol var : arg.getMethod().parameters) + if (var.name.equals(ast.name)) + return (ast.sym = var).type; + // Class field (or field of a superclass) + ast.sym = arg.classSymbol.getField(ast.name); + if (ast.sym != null) + return ast.sym.type; + // The variable cannot be found in any known scope + throw new SemanticFailure(Cause.NO_SUCH_VARIABLE, "Variable %s not found", ast.name); + } +} diff --git a/src/cd/frontend/semantic/SemanticAnalyzer.java b/src/cd/frontend/semantic/SemanticAnalyzer.java new file mode 100644 index 0000000..0c66478 --- /dev/null +++ b/src/cd/frontend/semantic/SemanticAnalyzer.java @@ -0,0 +1,235 @@ +package cd.frontend.semantic; + +import cd.Main; +import cd.frontend.semantic.SemanticFailure.Cause; +import cd.ir.Ast; +import cd.ir.Ast.ClassDecl; +import cd.ir.Ast.MethodDecl; +import cd.ir.Symbol; +import cd.ir.Symbol.*; + +import java.util.*; + +public class SemanticAnalyzer { + /** Name of the main class of the program, containing the start point for its execution */ + public static final String MAIN_CLASS_NAME = "Main"; + /** Name of the start point method inside the main class, with signature {@code void MAIN_METHOD_NAME()} */ + public static final String MAIN_METHOD_NAME = "main"; + + /** Reference to main method, for main class and list of types */ + public final Main main; + /** Statement analyzer, entrypoint for the method body analysis */ + public final StmtAnalyzer sa = new StmtAnalyzer(this); + /** For analyzing expressions, used by the StmtAnalyzer when an expression is found */ + public final ExprAnalyzer ea = new ExprAnalyzer(this); + + private List classDecls; + + public SemanticAnalyzer(Main main) { + this.main = main; + } + + /** + * Entrypoint for semantic analysis, will check that a list of classes is correct semantically + * @param classDeclList List of classes that form the Javali program + * @throws SemanticFailure If any semantic error is found + */ + public void check(List classDeclList) throws SemanticFailure { + this.classDecls = classDeclList; + checkCircularInheritance(classDecls); + // Built-in type generation + main.allTypeSymbols = new ArrayList<>(); + addBuiltInTypes(main.allTypeSymbols); + // Main semantic analysis + for (ClassDecl classDecl : classDecls) + sa.visit(classDecl, null); + // Find entrypoint Main and Main.main(...) + findMainClass(); + findEntrypoint(main.mainType); + } + + /** + * Generates the basic types that exist in any Javali program by default + * @param list Type list to which the types must be added + */ + private void addBuiltInTypes(List list) { + // Add primitive types + list.add(PrimitiveTypeSymbol.booleanType); + list.add(PrimitiveTypeSymbol.intType); + list.add(PrimitiveTypeSymbol.voidType); + // Add basic class types + list.add(ClassSymbol.objectType); + list.add(ClassSymbol.nullType); + // Add arrays of primitive and class types + list.add(new ArrayTypeSymbol(PrimitiveTypeSymbol.intType)); + list.add(new ArrayTypeSymbol(PrimitiveTypeSymbol.booleanType)); + list.add(new ArrayTypeSymbol(ClassSymbol.objectType)); + } + + /** + * Finds the {@code Main} class in a Javali program + * @throws SemanticFailure If there is no such class + */ + private void findMainClass() { + for (TypeSymbol type : main.allTypeSymbols) + if (type.name.equals(MAIN_CLASS_NAME)) + main.mainType = (ClassSymbol) type; + if (main.mainType == null) + throw new SemanticFailure(Cause.INVALID_START_POINT, + "Can't find class called \"%s\"", MAIN_CLASS_NAME); + } + + /** + * Finds the entrypoint for the Javali program + * @param mainType {@code Main} class of the program, where the entrypoint should be. + * @throws SemanticFailure If there is no such entrypoint, of it has incorrect return + * value or parameters. + */ + private void findEntrypoint(ClassSymbol mainType) { + MethodSymbol mainMethod = mainType.getMethod(MAIN_METHOD_NAME); + if (mainMethod == null) + throw new SemanticFailure(Cause.INVALID_START_POINT, + "No method called \"%s\" in %s class", MAIN_METHOD_NAME, MAIN_CLASS_NAME); + else if (mainMethod.returnType != PrimitiveTypeSymbol.voidType) + throw new SemanticFailure(Cause.INVALID_START_POINT, + "Method %s.%s(...) returns %s, expected void", + MAIN_CLASS_NAME, MAIN_METHOD_NAME, mainMethod.returnType); + else if (!mainMethod.parameters.isEmpty()) + throw new SemanticFailure(Cause.INVALID_START_POINT, + "Method %s.%s(...) must have no arguments, found %d", + MAIN_CLASS_NAME, MAIN_METHOD_NAME, mainMethod.parameters.size()); + } + + /** + * Looks up the requested type in the list of types. If not found, will try to read the remaining + * {@link ClassDecl} nodes to find the desired type. + * @param type Name of the type. Can be built-in, user-declared, or an array type. + * @return The TypeSymbol object associated with the type (no new symbol is created, only looked up from + * the general list). + * @throws SemanticFailure If the type doesn't exist + */ + public TypeSymbol findType(String type) { + // Option 1: type already exists + for (TypeSymbol symbol : main.allTypeSymbols) + if (type.equals(symbol.name)) + return symbol; + // Option 2: type is declared by user but hasn't been visited yet + String noArrayType = type; + if (type.contains("[]")) // To find the type of an array, remove "[]" and search for the name + noArrayType = type.substring(0, type.indexOf("[]")); + for (ClassDecl classDecl : classDecls) + if (classDecl.name.equals(noArrayType)) { + sa.visit(classDecl, null); + return findType(type); // Will use option 1 + } + // Option 3: the type doesn't exist + throw new SemanticFailure(Cause.NO_SUCH_TYPE, "Type %s doesn't exist", type); + } + + /** + * Looks up the requested method in the corresponding class. If not found, will try to find it as + * {@link MethodDecl} inside the {@link ClassDecl}. Will also look in superclasses of {@code receiverType}. + * @param methodName Name of the method that is being looked up + * @param receiverType Class in which the method must be found + * @return The method symbol (not created, but looked up from the class' method list. + */ + public MethodSymbol findMethod(String methodName, ClassSymbol receiverType) { + // Option 0: looking for methods in Object or null class (that has no methods or associated ast) + if (receiverType == ClassSymbol.objectType || receiverType == ClassSymbol.nullType) + throw new SemanticFailure(Cause.NO_SUCH_METHOD, "Type %s has no methods", receiverType); + // Option 1: method has already been discovered + MethodSymbol res = receiverType.methods.get(methodName); + if (res != null) return res; + // Option 2: method exists but hasn't been read yet (look in superclasses) + assert receiverType.ast != null; + for (MethodDecl methodDecl : receiverType.ast.methods()) { + if (methodDecl.name.equals(methodName)) { + sa.visit(methodDecl, new SemanticLocation(receiverType)); + return findMethod(methodName, receiverType); // Will use Option 1 + } + } + // Option 3: method exists in superclass + res = findMethod(methodName, receiverType.superClass); + if (res != null) return res; + // Option 4: method doesn't exist + throw new SemanticFailure(Cause.NO_SUCH_METHOD, "Method %s of class %s doesn't exist", + methodName, receiverType.name); + } + + /** + * Recursively checks for circular inheritance
+ * This check is done with the Strings extracted from the list of class declarations, as to perform it + * before the type check (which can be difficult to deal with given undiscovered circular inheritance), in order + * to avoid methods such as {@link ClassSymbol#getMethod(String)} or {@link ClassSymbol#getField(String)}, which + * are recursive by nature, throw a {@link StackOverflowError}. + * @param classDecls List of class declarations to check against + * @throws SemanticFailure If circular inheritance is found + * @throws SemanticFailure If any type inherited by a class doesn't exist (guaranteed to be a class type by + * the language grammar). + */ + public void checkCircularInheritance(List classDecls) { + Map inherits = new HashMap<>(); + for (ClassDecl classDecl : classDecls) + inherits.put(classDecl.name, classDecl.superClass); + for (ClassDecl classDecl : classDecls) + checkCircularInheritance(classDecl.name, new HashSet<>(), inherits); + } + + private void checkCircularInheritance(String className, Set set, Map inherits) { + if (className.equals("Object")) return; + if (!set.add(className)) + throw new SemanticFailure(Cause.CIRCULAR_INHERITANCE, + "Class %s has itself as superclass", className); + if (inherits.get(className) != null) + checkCircularInheritance(inherits.get(className), set, inherits); + else + throw new SemanticFailure(Cause.NO_SUCH_TYPE, "Class %s doesn't exist", className); + } + + /** + * Helper class that stores the position of a statement or expression being visited, by providing a link + * to the method and class symbols. This is useful when visiting variable nodes, method calls + * and {@code this} references.
+ * When entering and existing the body of a method, {@link SemanticLocation#beginMethod(MethodSymbol)} and + * {@link SemanticLocation#endMethod()} are used to set and unset the methodSymbol field. + */ + public static class SemanticLocation { + private MethodSymbol methodSymbol; + public final ClassSymbol classSymbol; + + /** + * Creates a semantic location that points to the {@code classSymbol} + */ + SemanticLocation(ClassSymbol classSymbol) { + this(classSymbol, null); + } + + private SemanticLocation(ClassSymbol classSymbol, MethodSymbol methodSymbol) { + assert classSymbol != null; + this.methodSymbol = methodSymbol; + this.classSymbol = classSymbol; + } + + public MethodSymbol getMethod() { + return methodSymbol; + } + + public boolean isInMethod() { + return methodSymbol != null; + } + + /** + * Setter for methodSymbol + */ + public void beginMethod(MethodSymbol methodSymbol) { + this.methodSymbol = methodSymbol; + } + + /** + * Unsetter for methodSymbol + */ + public void endMethod() { + this.methodSymbol = null; + } + } +} diff --git a/src/cd/frontend/semantic/SemanticFailure.java b/src/cd/frontend/semantic/SemanticFailure.java new file mode 100644 index 0000000..c66fc75 --- /dev/null +++ b/src/cd/frontend/semantic/SemanticFailure.java @@ -0,0 +1,127 @@ +package cd.frontend.semantic; + +/** + * Thrown by the semantic checker when a semantic error is detected + * in the user's program. */ +public class SemanticFailure extends RuntimeException { + private static final long serialVersionUID = 5375946759285719123L; + + public enum Cause { + /** + * Caused by a nested method being found. Those are not + * supported. + */ + NESTED_METHODS_UNSUPPORTED, + + /** + * Caused by an assignment to either a final field, {@code this}, + * or some other kind of expression which cannot be assigned to. + * Not used for type errors in assignments, which fall + * under {@link #TYPE_ERROR}. */ + NOT_ASSIGNABLE, + + /** The value of a final field is not a compile-time constant */ + NOT_A_CONSTANT_EXPR, + + /** Two variables, fields, methods, or classes with the same name + * were declared in the same scope */ + DOUBLE_DECLARATION, + + /** A field was accessed that does not exist */ + NO_SUCH_FIELD, + + /** A method was called that does not exist */ + NO_SUCH_METHOD, + + /** + * A variable or other identifier was used in a method + * body which has no corresponding declaration */ + NO_SUCH_VARIABLE, + + /** + * A method with a return type is missing a return statement among one of its paths */ + MISSING_RETURN, + + /** + * Can occur in many contents: + *
    + *
  • Assignment to a variable from an expression of wrong type + *
  • A parameter in a method invocation had the wrong type + *
  • A condition of a while loop or if statement was not boolean + *
  • A non-array was indexed (i.e., a[i] where a is not an array) + *
  • The index was not an int (i.e., a[i] where i is not an int) + *
  • Arithmetic operators (+,-,etc) used with non-int type + *
  • Boolean operators (!,&&,||,etc) used with non-boolean type + *
  • Method or field accessed on non-object type + *
  • {@code write()} is used with non-int argument + *
  • An invalid cast was detected (i.e., a cast to a type that + * is not a super- or sub-type of the original type). + *
  • The size of an array in a new expression was not an + * int (i.e., new A[i] where i is not an int) + *
+ */ + TYPE_ERROR, + + /** + * A class is its own super class + */ + CIRCULAR_INHERITANCE, + + /** + * One of the following: + *
    + *
  • No class {@code Main} + *
  • Class {@code Main} does not have a method {@code main()} + *
  • The method {@code main} has > 0 parameters. + *
  • The method {@code main} has a non-void return type. + *
+ */ + INVALID_START_POINT, + + /** + * A class {@code Object} was defined. This class is implicitly + * defined and cannot be defined explicitly. + */ + OBJECT_CLASS_DEFINED, + + /** + * A type name was found for which no class declaration exists. + * This can occur in many contexts: + *
    + *
  • The extends clause on a class declaration. + *
  • A cast. + *
  • A new expression. + *
+ */ + NO_SUCH_TYPE, + + /** + * The parameters of an overridden method have different types + * from the base method, there is a different + * number of parameters, or the return value is different. + */ + INVALID_OVERRIDE, + + /** A method was called with the wrong number of arguments */ + WRONG_NUMBER_OF_ARGUMENTS, + + /** + * Indicates the use of a local variable that may not have been + * initialized (ACD only). + */ + POSSIBLY_UNINITIALIZED, + } + + public final Cause cause; + + public SemanticFailure(Cause cause) { + super(cause.name()); + this.cause = cause; + } + + public SemanticFailure(Cause cause, String format, Object... args) { + super(String.format(format, args)); + this.cause = cause; + } + +} diff --git a/src/cd/frontend/semantic/StmtAnalyzer.java b/src/cd/frontend/semantic/StmtAnalyzer.java new file mode 100644 index 0000000..5808735 --- /dev/null +++ b/src/cd/frontend/semantic/StmtAnalyzer.java @@ -0,0 +1,353 @@ +package cd.frontend.semantic; + +import cd.frontend.semantic.SemanticAnalyzer.SemanticLocation; +import cd.frontend.semantic.SemanticFailure.Cause; +import cd.ir.Ast; +import cd.ir.Ast.*; +import cd.ir.AstVisitor; +import cd.ir.Symbol; +import cd.ir.Symbol.*; +import cd.ir.Symbol.VariableSymbol.Kind; + +/** + * Semantic analyzer for {@link Ast} nodes in the pattern of a visitor.
+ * All methods may throw {@link SemanticFailure} if an error is discovered, + * with the appropriate {@link Cause} and a short explanation to give some context + * to the user.
+ * The current implementation employs the {@link Symbol} returned to signal a + * statement, or group of them that contain a unconditional return (or return in both + * branches of a {@link IfElse} node. The type is checked by + * {@link StmtAnalyzer#returnStmt(ReturnStmt, SemanticLocation)} and the existence, by + * {@link StmtAnalyzer#methodDecl(MethodDecl, SemanticLocation)}
+ * Uses the {@link SemanticLocation} argument to give context to each statement and + * expression visited, so that they may access variables, fields and methods. + * @see ExprAnalyzer + * @author Carlos Galindo + * @author Levin Moser + */ +public class StmtAnalyzer extends AstVisitor { + /** + * Reference to the main semantic analyzer
+ * Needed to access {@link SemanticAnalyzer#findType(String)} and the + * {@link ExprAnalyzer} + */ + private SemanticAnalyzer sa; + + StmtAnalyzer(SemanticAnalyzer sa) { + this.sa = sa; + } + + /** + * Checks semantic errors in a {@link Assign} node + * @param ast The node containing all the information + * @param arg The class and method in which the statement takes place + * @return {@code null} (No return can occur in an assigment statement) + * @throws SemanticFailure If the right-hand side is not a subtype of the left-hand side + * @throws SemanticFailure If the left-hand side is a method call or a {@code this} reference + */ + @Override + public Symbol assign(Assign ast, SemanticLocation arg) { + TypeSymbol right = sa.ea.visit(ast.right(), arg); + TypeSymbol left = sa.ea.visit(ast.left(), arg); + if (!right.isSubtypeOf(left)) + throw new SemanticFailure(Cause.TYPE_ERROR, + "In assignment, %s is not a subtype of %s", right, left); + // Only variables, fields and array dereferences are valid as left-hand side + if (ast.left() instanceof Var) + return null; + if (ast.left() instanceof Field) + return null; + if (ast.left() instanceof Index) + return null; + String leftExprType; + if (ast.left() instanceof MethodCallExpr) + leftExprType = "method call"; + else if (ast.left() instanceof ThisRef) + leftExprType = "this reference"; + else + throw new RuntimeException("Missing valid or invalid left-hand side of assignment, check grammar"); + throw new SemanticFailure(Cause.NOT_ASSIGNABLE, + "Left-hand side of assignment must be field, var or index, found %s", leftExprType); + } + + /** + * Checks a possible error in a {@link BuiltInWrite} AST node. + * @param ast The node containing all the information + * @param arg The class and method in which the statement takes place + * @return {@code null} (No return statement can happen inside a write) + * @throws SemanticFailure If the type of the expression to write is not integer + */ + @Override + public Symbol builtInWrite(BuiltInWrite ast, SemanticLocation arg) { + TypeSymbol type = sa.ea.visit(ast.arg(), arg); + if (type != PrimitiveTypeSymbol.intType) + throw new SemanticFailure(Cause.TYPE_ERROR, + "Argument of write function must be an int, found %s", type); + else + return null; + } + + /** + * Checks a class declaration and all contained fields and methods for semantic errors.
+ * Will add itself and its corresponding array type to the types list. + * @param ast The node describing the class declaration + * @param arg {@code null}, as nested classes aren't permitted by the Javali grammar + * @return {@code null} (no need to check return types) + * @throws SemanticFailure If the type of the class already exists + * @throws SemanticFailure If the name of the class is Object (base class) + * @throws SemanticFailure If the superclass is not defined in the Javali program + */ + @Override + public Symbol classDecl(ClassDecl ast, SemanticLocation arg) { + if (ast.sym != null) return null; // Class already visited + + // Generate first the symbol and link it to the ast node + ast.sym = new ClassSymbol(ast); + + // No class can be named Object + if (ast.name.equals(ClassSymbol.objectType.name)) + throw new SemanticFailure(Cause.OBJECT_CLASS_DEFINED, "The %s class cannot be redefined", ast.name); + + // All classes have unique names + for (TypeSymbol type : sa.main.allTypeSymbols) + if (type.name.equals(ast.sym.name)) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, "Another class exists with the name %s", type); + + // Add basic and array type to typeList (this is the only method that generates + // a ClassSymbol or ArrayTypeSymbol) + sa.main.allTypeSymbols.add(ast.sym); + sa.main.allTypeSymbols.add(new ArrayTypeSymbol(ast.sym)); + + // The superclass exists (will visit other classes to look it up) + ast.sym.superClass = (ClassSymbol) sa.findType(ast.superClass); + + // Visit children (fields and methods) + SemanticLocation thisClass = new SemanticLocation(ast.sym); + for (VarDecl varDecl : ast.fields()) + ast.sym.fields.put(varDecl.name, (VariableSymbol) visit(varDecl, thisClass)); + for (MethodDecl methodDecl : ast.methods()) + visit(methodDecl, thisClass); + + return ast.sym; + } + + /** + * Checks for semantic correctness of a {@link MethodDecl} node, regarding both the method's + * signature and its body.
+ * For the declaration of local variables of the method, the underlying + * {@link Seq} node is not visited, as to keep the logic in + * {@link StmtAnalyzer#seq(Seq, SemanticLocation)} simpler, and only related to + * the accumulation of the return paths. + * @param ast The node describing the method declaration + * @param arg The class the method is being declared in + * @return {@code null} (no need to check return types) + * @throws SemanticFailure If multiple local variables share the same name + * @throws SemanticFailure If there is a return type but no return statement in all paths + * @throws SemanticFailure If the method is overloaded + * @throws SemanticFailure If the method overrides another incorrectly + * (mismatched parameter number, type or return type) + * @throws SemanticFailure If the return type doesn't exist + */ + @Override + public Symbol methodDecl(MethodDecl ast, SemanticLocation arg) { + if (ast.sym != null) return null; // Already visited + ast.sym = new MethodSymbol(ast); + arg.beginMethod(ast.sym); // Modify the location to include the method symbol + + // Check overloading (none is permitted) + if (arg.classSymbol.methods.get(ast.name) != null) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, + "Another method exists with the name %s in class %s, overloading is not permitted", + ast.name, arg); + + // Check return type + ast.sym.returnType = sa.findType(ast.returnType); + + // Check params type and generate VariableSymbols + assert ast.argumentNames.size() == ast.argumentTypes.size(); // This should be guaranteed by parser + for (int i = 0; i < ast.argumentNames.size(); i++) { + // check for repeated param name + for (VariableSymbol var : ast.sym.parameters) + if (var.name.equals(ast.argumentNames.get(i))) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, + "There are two parameters named %s in method %s", var, ast.sym); + // add to sym param list + ast.sym.parameters.add(new VariableSymbol( + ast.argumentNames.get(i), + sa.findType(ast.argumentTypes.get(i)), + Kind.PARAM)); + } + + // Check override (only possible if parameters and return type match) + MethodSymbol overridden = arg.classSymbol.getMethod(ast.name); + if (overridden != null) { + // Return value must be the same + if (overridden.returnType != ast.sym.returnType) + throw new SemanticFailure(Cause.INVALID_OVERRIDE, + "Overridden methods must share return type, expected %s, found %s", + overridden.returnType, ast.sym.returnType); + // Number of parameters must be the same + if (overridden.parameters.size() != ast.sym.parameters.size()) + throw new SemanticFailure(Cause.INVALID_OVERRIDE, + "Overridden methods must have the same number of parameters, expected %d, found %d", + overridden.parameters.size(), ast.sym.parameters.size()); + // Types must match for all parameters + for (int i = 0; i < ast.sym.parameters.size(); i++) + if (overridden.parameters.get(i).type != ast.sym.parameters.get(i).type) + throw new SemanticFailure(Cause.INVALID_OVERRIDE, + "Overridden methods must match parameters type, expected %s, found %s for parameter %d", + overridden.parameters.get(i).type, ast.sym.parameters.get(i).type, i); + } + + // Check all local variables + for (Ast decl : ast.decls().children()) { + VarDecl varDecl = (VarDecl) decl; + VariableSymbol varSymbol = (VariableSymbol) visit(varDecl, arg); + ast.sym.locals.put(varDecl.name, varSymbol); + } + // Check statements and return type + Symbol returnSymbol = visit(ast.body(), arg); + if (returnSymbol == null && ast.sym.returnType != PrimitiveTypeSymbol.voidType) { + throw new SemanticFailure(Cause.MISSING_RETURN, + "Method %s missing return statement", ast.sym); + } + + // Add method to class Symbol node + arg.classSymbol.methods.put(ast.name, ast.sym); + + arg.endMethod(); + return ast.sym; + } + + /** + * Checks for semantic errors in a {@link VarDecl} node. It can either receive a local variable + * or a class field. + * @param ast Node containing the type and name for the variable + * @param arg Class [and method] in which the variable is being declared + * @return {@link VariableSymbol} representing the variable + * @throws SemanticFailure If the variable has already been declared in this class + * (hiding a field from a superclass is allowed) + * @throws SemanticFailure If the type of the variable doesn't exist + * @throws SemanticFailure If the local variable has already been declared + */ + @Override + public Symbol varDecl(VarDecl ast, SemanticLocation arg) { + if (arg.isInMethod()) { // Checks for local variable + if (arg.getMethod().locals.get(ast.name) != null) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, + "Variable %s is already declared as a variable", ast.name); + for (VariableSymbol var : arg.getMethod().parameters) + if (var.name.equals(ast.name)) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, + "Variable %s is already declared as a parameter", ast.name); + } else { // Checks for field variable + if (arg.classSymbol.fields.get(ast.name) != null) + throw new SemanticFailure(Cause.DOUBLE_DECLARATION, + "Class %s cannot have more than one variable with the same name (%s)", arg, ast.name); + } + ast.sym = new VariableSymbol( + ast.name, + sa.findType(ast.type), // Type check included here + arg.isInMethod() ? Kind.FIELD : Kind.LOCAL); + return ast.sym; + } + + /** + * Checks for semantic errors in a {@link IfElse} node + * @param ast Contains all the information regarding the condition and if/else bodies + * @param arg The class and method in whose body the if statement exists + * @return The return value if both branches have one, or {@code null} otherwise + * @throws SemanticFailure If the condition is not of boolean type + */ + @Override + public Symbol ifElse(IfElse ast, SemanticLocation arg) { + TypeSymbol condType = sa.ea.visit(ast.condition(), arg); + if (condType != PrimitiveTypeSymbol.booleanType) + throw new SemanticFailure(Cause.TYPE_ERROR, "Condition of if must be int, found %s", condType); + Symbol then = visit(ast.then(), arg); + Symbol otherwise = visit(ast.otherwise(), arg); + + if (then != null && otherwise != null) + return then; + else + return null; + } + + /** + * Checks for semantic errors in a {@link ReturnStmt} node + * @param ast Contains all information about the return statement + * @param arg The class and method in which this statement takes place + * @return Type of the underlying expression, to be returned by the method + * @throws SemanticFailure If the return type is not a subtype of the method signature's return type + * @throws SemanticFailure If the method does return a non-void but the return statement has no + * expression to return + */ + @Override + public Symbol returnStmt(ReturnStmt ast, SemanticLocation arg) { + if (ast.arg() != null) { + TypeSymbol returnType = sa.ea.visit(ast.arg(), arg); + if (returnType.isSubtypeOf(arg.getMethod().returnType)) + return returnType; + throw new SemanticFailure(Cause.TYPE_ERROR, + "Return type of %s must be a subtype of %s, found %s", + arg.getMethod(), arg.getMethod().returnType, returnType); + } else { + if (arg.getMethod().returnType != PrimitiveTypeSymbol.voidType) + throw new SemanticFailure(Cause.TYPE_ERROR, + "Empty return, expecting type %s or subtype", arg.getMethod().returnType); + return null; + } + } + + /** + * Checks for semantic errors in a method call + * @see ExprAnalyzer#methodCall(MethodCallExpr, SemanticLocation) + * @return {@code null} (No return statement in this node) + */ + @Override + public Symbol methodCall(MethodCall ast, SemanticLocation arg) { + sa.ea.visit(ast.getMethodCallExpr(), arg); + return null; + } + + /** + * Checks that all members of the {@link Seq} node are valid.
+ * This method will only visit sequences of statements, as the + * sequences of variables are checked in + * {@link StmtAnalyzer#methodDecl(MethodDecl, SemanticLocation)}, therefore + * the logic is simpler and separated for unrelated elements of the method + * body (all local variable declaration must come before the statements) + * @param ast The node with the sequence of statements + * @param arg Class and method in which this sequence exists, to be passed + * down to visited statements + * @return The first type returned by one of the underlying statements + */ + @Override + public Symbol seq(Seq ast, SemanticLocation arg) { + Symbol firstReturn = null; + for (Ast aChildren : ast.children()) { + Symbol sym = visit(aChildren, arg); + if (sym != null && firstReturn == null) + firstReturn = sym; + } + return firstReturn; + } + + /** + * Checks semantic errors in a while loop + * @param ast Node containing all the information about the {@code while} loop + * @param arg The class and method in which the loop exists + * @return {@code null} (condition of the loop is not check to determine if + * it is always accessed, therefore it cannot be treated as an unconditional return) + * @throws SemanticFailure If the condition for the loop is not a boolean type + */ + @Override + public Symbol whileLoop(WhileLoop ast, SemanticLocation arg) { + TypeSymbol condType = sa.ea.visit(ast.condition(), arg); + if (condType != PrimitiveTypeSymbol.booleanType) + throw new SemanticFailure(Cause.TYPE_ERROR, + "Condition of while loop must be int, found %s", condType); + visit(ast.body(), arg); + return null; + } +} diff --git a/src/cd/ir/Ast.java b/src/cd/ir/Ast.java index 5bf1a26..1b3c6e6 100644 --- a/src/cd/ir/Ast.java +++ b/src/cd/ir/Ast.java @@ -5,6 +5,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import cd.ir.Symbol.ClassSymbol; +import cd.ir.Symbol.MethodSymbol; +import cd.ir.Symbol.TypeSymbol; +import cd.ir.Symbol.VariableSymbol; import cd.util.Pair; import cd.util.debug.AstOneLine; @@ -56,7 +60,7 @@ public abstract class Ast { /** Convenient debugging printout */ @Override - public String toString() { + public String toString() { return String.format( "(%s)@%x", AstOneLine.toString(this), @@ -73,14 +77,20 @@ public abstract class Ast { super(fixedCount); } + /** Type that this expression will evaluate to (computed in semantic phase). */ + public TypeSymbol type; + @Override - public R accept(AstVisitor visitor, A arg) { + public R accept(AstVisitor visitor, A arg) { return this.accept((ExprVisitor)visitor, arg); } public abstract R accept(ExprVisitor visitor, A arg); /** Copies any non-AST fields. */ protected E postCopy(E item) { + { + item.type = type; + } return item; } } @@ -140,23 +150,23 @@ public abstract class Ast { * such as "1+2" or "3*4" */ public static class BinaryOp extends LeftRightExpr { - public static enum BOp { - - B_TIMES("*"), - B_DIV("/"), - B_MOD("%"), - B_PLUS("+"), - B_MINUS("-"), - B_AND("&&"), - B_OR("||"), - B_EQUAL("=="), - B_NOT_EQUAL("!="), - B_LESS_THAN("<"), - B_LESS_OR_EQUAL("<="), - B_GREATER_THAN(">"), - B_GREATER_OR_EQUAL(">="); - - public String repr; + public static enum BOp { + + B_TIMES("*"), + B_DIV("/"), + B_MOD("%"), + B_PLUS("+"), + B_MINUS("-"), + B_AND("&&"), + B_OR("||"), + B_EQUAL("=="), + B_NOT_EQUAL("!="), + B_LESS_THAN("<"), + B_LESS_OR_EQUAL("<="), + B_GREATER_THAN(">"), + B_GREATER_OR_EQUAL(">="); + + public String repr; private BOp(String repr) { this.repr = repr; } /** @@ -167,26 +177,26 @@ public abstract class Ast { * operator. */ public boolean isCommutative() { - switch(this) { - case B_PLUS: - case B_TIMES: - case B_AND: - case B_OR: - case B_EQUAL: - case B_NOT_EQUAL: - return true; - default: - return false; - } + switch(this) { + case B_PLUS: + case B_TIMES: + case B_AND: + case B_OR: + case B_EQUAL: + case B_NOT_EQUAL: + return true; + default: + return false; + } } - }; - - public BOp operator; - - public BinaryOp(Expr left, BOp operator, Expr right) { - super(left, right); - this.operator = operator; - } + }; + + public BOp operator; + + public BinaryOp(Expr left, BOp operator, Expr right) { + super(left, right); + this.operator = operator; + } @Override public R accept(ExprVisitor visitor, A arg) { @@ -210,6 +220,12 @@ public abstract class Ast { return visitor.cast(this, arg); } + @Override + protected E postCopy(E item) { + ((Cast)item).type = type; + return super.postCopy(item); + } + } public static class IntConst extends LeafExpr { @@ -253,6 +269,8 @@ public abstract class Ast { public final String fieldName; + public VariableSymbol sym; + public Field(Expr arg, String fieldName) { super(arg); assert arg != null && fieldName != null; @@ -264,6 +282,12 @@ public abstract class Ast { return visitor.field(this, arg); } + @Override + protected E postCopy(E item) { + ((Field)item).sym = sym; + return super.postCopy(item); + } + } public static class Index extends LeftRightExpr { @@ -314,21 +338,21 @@ public abstract class Ast { public static class UnaryOp extends ArgExpr { - public static enum UOp { - U_PLUS("+"), - U_MINUS("-"), - U_BOOL_NOT("!"); - public String repr; + public static enum UOp { + U_PLUS("+"), + U_MINUS("-"), + U_BOOL_NOT("!"); + public String repr; private UOp(String repr) { this.repr = repr; } - }; - - public final UOp operator; - - public UnaryOp(UOp operator, Expr arg) { + }; + + public final UOp operator; + + public UnaryOp(UOp operator, Expr arg) { super(arg); this.operator = operator; } - + @Override public R accept(ExprVisitor visitor, A arg) { return visitor.unaryOp(this, arg); @@ -340,6 +364,8 @@ public abstract class Ast { public String name; + public VariableSymbol sym; + /** * Use this constructor to build an instance of this AST * in the parser. @@ -351,6 +377,29 @@ public abstract class Ast { public R accept(ExprVisitor visitor, A arg) { return visitor.var(this, arg); } + + /** + * Use this static function to build an instance after the + * semantic phase; it fills in the {@link #type} and {@link #sym} + * fields. + */ + public static Var withSym(VariableSymbol sym) { + Var v = new Var(sym.name); + v.sym = sym; + v.type = sym.type; + return v; + } + + @Override + protected E postCopy(E item) { + ((Var)item).sym = sym; + return super.postCopy(item); + } + + public void setSymbol(VariableSymbol variableSymbol) { + sym = variableSymbol; + name = sym.toString(); + } } @@ -367,6 +416,8 @@ public abstract class Ast { public String methodName; + public MethodSymbol sym; + public MethodCallExpr(Expr rcvr, String methodName, List arguments) { super(-1); assert rcvr != null && methodName != null && arguments != null; @@ -588,6 +639,8 @@ public abstract class Ast { public String type; public String name; + public VariableSymbol sym; + public VarDecl(String type, String name) { this(0, type, name); } @@ -631,6 +684,7 @@ public abstract class Ast { public String name; public List argumentTypes; public List argumentNames; + public MethodSymbol sym; public MethodDecl( String returnType, String name, @@ -672,6 +726,8 @@ public abstract class Ast { public String name; public String superClass; + public ClassSymbol sym; + public ClassDecl( String name, String superClass, diff --git a/src/cd/ir/AstVisitor.java b/src/cd/ir/AstVisitor.java index 8d334d6..0576c24 100644 --- a/src/cd/ir/AstVisitor.java +++ b/src/cd/ir/AstVisitor.java @@ -16,17 +16,6 @@ public class AstVisitor extends ExprVisitor { return ast.accept(this, arg); } - /** - * Overrides {@link ExprVisitor#visitChildren(Expr, Object)} and - * delegates to the more general {@link #visitChildren(Ast, Object)} - * with {@link Ast} parameter. This method is final to prevent - * overriding only one of the two versions. - */ - @Override - public final R visitChildren(Expr ast, A arg) { - return visitChildren((Ast) ast, arg); - } - /** * A handy function which visits the children of {@code ast}, * providing "arg" to each of them. It returns the result of @@ -56,7 +45,6 @@ public class AstVisitor extends ExprVisitor { /** * The default action for expressions is to call this */ - @Override protected R dfltExpr(Expr ast, A arg) { return dflt(ast, arg); } diff --git a/src/cd/ir/Symbol.java b/src/cd/ir/Symbol.java new file mode 100644 index 0000000..0d84cf5 --- /dev/null +++ b/src/cd/ir/Symbol.java @@ -0,0 +1,172 @@ +package cd.ir; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class Symbol { + + public final String name; + + public static abstract class TypeSymbol extends Symbol { + + public TypeSymbol(String name) { + super(name); + } + + public abstract boolean isReferenceType(); + + public String toString() { + return name; + } + + /** + * Determine if the TypeSymbol is a subtype of the parameter + *
The conditions are the following + *
    + *
  • Any type is a subtype of itself
  • + *
  • Primitive types have no subtypes
  • + *
  • Reference types are a subtype of {@code Object}
  • + *
  • Reference types are a supertype of {@code null}
  • + *
  • Classes can only be subtypes of other classes
  • + *
  • Classes that inherit another are its subtypes (recursively)
  • + *
+ */ + public boolean isSubtypeOf(TypeSymbol sym) { + // Any type is a subtype of itself + if (sym == this) return true; + // A PrimitiveType doesn't have subtypes + if (this instanceof PrimitiveTypeSymbol || sym instanceof PrimitiveTypeSymbol) + return false; + // Any reference type is a subtype of Object + if (this.isReferenceType() && sym == ClassSymbol.objectType) + return true; + // null is a subtype of any reference type + if (sym.isReferenceType() && this == ClassSymbol.nullType) + return true; + // Class types can only be subtypes of other Class types + // A class type is subtype of another if has inherited it + if (sym instanceof ClassSymbol && this instanceof ClassSymbol) + for (ClassSymbol c = (ClassSymbol) this; c != ClassSymbol.objectType; c = c.superClass) + if (c == sym) return true; + return false; + } + } + + public static class PrimitiveTypeSymbol extends TypeSymbol { + + /** Symbols for the built-in primitive types */ + public static final PrimitiveTypeSymbol intType = new PrimitiveTypeSymbol("int"); + public static final PrimitiveTypeSymbol voidType = new PrimitiveTypeSymbol("void"); + public static final PrimitiveTypeSymbol booleanType = new PrimitiveTypeSymbol("boolean"); + + public PrimitiveTypeSymbol(String name) { + super(name); + } + + public boolean isReferenceType() { + return false; + } + } + + public static class ArrayTypeSymbol extends TypeSymbol { + public final TypeSymbol elementType; + + public ArrayTypeSymbol(TypeSymbol elementType) { + super(elementType.name+"[]"); + this.elementType = elementType; + } + + public boolean isReferenceType() { + return true; + } + + } + + public static class ClassSymbol extends TypeSymbol { + public final Ast.ClassDecl ast; + public ClassSymbol superClass; + public final VariableSymbol thisSymbol = + new VariableSymbol("this", this); + public final Map fields = new HashMap<>(); + public final Map methods = new HashMap<>(); + + /** Symbols for the built-in Object and null types */ + public static final ClassSymbol nullType = new ClassSymbol(""); + public static final ClassSymbol objectType = new ClassSymbol("Object"); + + public ClassSymbol(Ast.ClassDecl ast) { + super(ast.name); + this.ast = ast; + } + + /** Used to create the default {@code Object} + * and {@code } types */ + public ClassSymbol(String name) { + super(name); + this.ast = null; + } + + public boolean isReferenceType() { + return true; + } + + public VariableSymbol getField(String name) { + VariableSymbol fsym = fields.get(name); + if (fsym == null && superClass != null) + return superClass.getField(name); + return fsym; + } + + public MethodSymbol getMethod(String name) { + MethodSymbol msym = methods.get(name); + if (msym == null && superClass != null) + return superClass.getMethod(name); + return msym; + } + } + + public static class MethodSymbol extends Symbol { + + public final Ast.MethodDecl ast; + public final Map locals = new HashMap<>(); + public final List parameters = new ArrayList<>(); + + public TypeSymbol returnType; + + public MethodSymbol(Ast.MethodDecl ast) { + super(ast.name); + this.ast = ast; + } + + public String toString() { + return name + "(...)"; + } + } + + public static class VariableSymbol extends Symbol { + + public enum Kind { PARAM, LOCAL, FIELD } + public final TypeSymbol type; + public final Kind kind; + + public VariableSymbol(String name, TypeSymbol type) { + this(name, type, Kind.PARAM); + } + + public VariableSymbol(String name, TypeSymbol type, Kind kind) { + super(name); + this.type = type; + this.kind = kind; + } + + public String toString() { + return name; + } + } + + protected Symbol(String name) { + this.name = name; + } +} diff --git a/src/cd/util/debug/AstOneLine.java b/src/cd/util/debug/AstOneLine.java index 1557010..7c0a768 100644 --- a/src/cd/util/debug/AstOneLine.java +++ b/src/cd/util/debug/AstOneLine.java @@ -160,7 +160,15 @@ public class AstOneLine { @Override public String var(Var ast, Void arg) { { - return ast.name; + if (ast.sym != null) { + String symName = ast.sym.toString(); + if (ast.name == null || ast.name.equals(symName)) + return symName; + + // Return something strange to warn about the mismatch here: + return String.format("(%s!=%s)", symName, ast.name); + } else + return ast.name; } } diff --git a/src/cd/util/debug/DumpUtils.java b/src/cd/util/debug/DumpUtils.java deleted file mode 100644 index 52a2c48..0000000 --- a/src/cd/util/debug/DumpUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package cd.util.debug; - -import static java.util.Collections.sort; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - -import cd.ir.Ast.ClassDecl; -import cd.ir.Ast.MethodDecl; - -class DumpUtils { - - static final Comparator classComparator = new Comparator() { - public int compare(ClassDecl left, ClassDecl right) { - return left.name.compareTo(right.name); - } - }; - - static final Comparator methodComparator = new Comparator() { - public int compare(MethodDecl left, MethodDecl right) { - return left.name.compareTo(right.name); - } - }; - - static List sortedStrings(Set set) { - List strings = new ArrayList(); - for(Object element : set) - strings.add(element.toString()); - sort(strings); - return strings; - } -} diff --git a/test/cd/AbstractTestAgainstFrozenReference.java b/test/cd/test/AbstractTestAgainstFrozenReference.java similarity index 64% rename from test/cd/AbstractTestAgainstFrozenReference.java rename to test/cd/test/AbstractTestAgainstFrozenReference.java index ef9eea1..2ce2faa 100644 --- a/test/cd/AbstractTestAgainstFrozenReference.java +++ b/test/cd/test/AbstractTestAgainstFrozenReference.java @@ -1,4 +1,4 @@ -package cd; +package cd.test; import java.io.File; import java.io.FileNotFoundException; @@ -7,16 +7,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.List; -import java.util.concurrent.TimeUnit; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; +import cd.Config; +import cd.Main; import cd.frontend.parser.ParseFailure; +import cd.frontend.semantic.SemanticFailure; import cd.ir.Ast.ClassDecl; import cd.util.FileUtil; import cd.util.debug.AstDump; @@ -27,17 +25,13 @@ abstract public class AbstractTestAgainstFrozenReference { public static final String PARSE_FAILURE = "ParseFailure"; public File file, sfile, binfile, infile; - public File parserreffile, semanticreffile, execreffile, cfgreffile, rdreffile, - nnreffile, optreffile; + public File parserreffile, semanticreffile, execreffile, cfgreffile, optreffile; public File errfile; public Main main; public static int counter = 0; - @Rule - public TestRule timeout = new DisableOnDebug(new Timeout(15, TimeUnit.SECONDS)); - - @Test + @Test(timeout=10000) public void test() throws Throwable { System.err.println("[" + counter++ + " = " + file + "]"); @@ -52,6 +46,9 @@ abstract public class AbstractTestAgainstFrozenReference { List astRoots = testParser(); if (astRoots != null) { + { + boolean passedSemanticAnalysis = testSemanticAnalyzer(astRoots); + } } } catch (org.junit.ComparisonFailure cf) { throw cf; @@ -80,7 +77,7 @@ abstract public class AbstractTestAgainstFrozenReference { ProcessBuilder pb = new ProcessBuilder( javaExe, "-Dcd.meta_hidden.Version=" + referenceVersion(), - "-cp", "lib/frozenReferenceObf.jar" + colon + " lib/junit-4.12.jar" + colon + "lib/antlr-4.7.1-complete.jar", + "-cp", "lib/frozenReferenceObf.jar" + colon + " lib/junit-4.12.jar" + colon + "lib/antlr-4.4-complete.jar", "cd.FrozenReferenceMain", file.getAbsolutePath()); Process proc = pb.start(); @@ -96,24 +93,13 @@ abstract public class AbstractTestAgainstFrozenReference { private static String referenceVersion() { { - return "CD_HW_PARSER_SOL"; + return "CD_HW_SEMANTIC_SOL"; } } - private String tryReadRefFile(File fileToFind) { - if (fileToFind.exists() && fileToFind.lastModified() >= file.lastModified()) { - try { - return FileUtil.read(fileToFind); - } catch (IOException e) { - throw new RuntimeException("ERROR: could not read file " + fileToFind.getPath()); - } - } - throw new RuntimeException("ERROR: could not find file " + fileToFind.getPath()); - } - /** Run the parser and compare the output against the reference results */ private List testParser() throws Exception { - String parserRef = tryReadRefFile(parserreffile); + String parserRef = findParserRef(); List astRoots = null; String parserOut; @@ -132,11 +118,68 @@ abstract public class AbstractTestAgainstFrozenReference { } { - assertEquals("parser", parserRef, parserOut); + // Now that the 2nd assignment is over, we don't + // do a detailed comparison of the AST, just check + // whether the parse succeeded or failed. + if (parserOut.equals(PARSE_FAILURE) || parserRef.equals(PARSE_FAILURE)) + assertEquals("parser", parserRef, parserOut); } return astRoots; } + private String findParserRef() throws IOException { + // Check for a .ref file + if (parserreffile.exists() && parserreffile.lastModified() >= file.lastModified()) { + return FileUtil.read(parserreffile); + } + throw new RuntimeException("ERROR: could not find parser .ref"); + } + + private boolean testSemanticAnalyzer(List astRoots) + throws IOException { + String semanticRef = findSemanticRef(); + + boolean passed; + String result; + try { + main.semanticCheck(astRoots); + result = SEMANTIC_OK; + passed = true; + } catch (SemanticFailure sf) { + result = sf.cause.name(); + main.debug("Error message: %s", sf.getLocalizedMessage()); + passed = false; + } + + assertEquals("semantic", semanticRef, result); + return passed; + } + + private String findSemanticRef() throws IOException { + // Semantic ref file is a little different. It consists + // of 2 lines, but only the first line is significant. + // The second one contains additional information that we log + // to the debug file. + + // Read in the result + String res; + if (semanticreffile.exists() && semanticreffile.lastModified() > file.lastModified()) + res = FileUtil.read(semanticreffile); + else + throw new RuntimeException("ERROR: could not find semantic .ref"); + + // Extract the first line: there should always be multiple lines, + // but someone may have tinkered with the file or something + if (res.contains("\n")) { + int newline = res.indexOf("\n"); + String info = res.substring(newline + 1); + if (!info.equals("") && !info.equals("\n")) + main.debug("Error message from reference is: %s", info); + return res.substring(0, newline); // 1st line + } else { + return res; + } + } private void assertEquals(String phase, String exp, String act_) { String act = act_.replace("\r\n", "\n"); // for windows machines @@ -144,7 +187,7 @@ abstract public class AbstractTestAgainstFrozenReference { warnAboutDiff(phase, exp, act); } } - + private void warnAboutDiff(String phase, String exp, String act) { try { try (PrintStream err = new PrintStream(errfile)) { diff --git a/test/cd/Diff.java b/test/cd/test/Diff.java similarity index 99% rename from test/cd/Diff.java rename to test/cd/test/Diff.java index 148c1bd..a86b5ee 100644 --- a/test/cd/Diff.java +++ b/test/cd/test/Diff.java @@ -1,4 +1,4 @@ -package cd; +package cd.test; // NOTE: This code was adapted from the code found at // http://www.cs.princeton.edu/introcs/96optimization/Diff.java.html diff --git a/test/cd/TestSamplePrograms.java b/test/cd/test/TestSamplePrograms.java similarity index 92% rename from test/cd/TestSamplePrograms.java rename to test/cd/test/TestSamplePrograms.java index 4448587..311c5dd 100644 --- a/test/cd/TestSamplePrograms.java +++ b/test/cd/test/TestSamplePrograms.java @@ -1,9 +1,4 @@ -package cd; - -import cd.util.FileUtil; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +package cd.test; import java.io.File; import java.io.StringWriter; @@ -11,6 +6,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import cd.Config; +import cd.Main; +import cd.util.FileUtil; + @RunWith(Parameterized.class) public class TestSamplePrograms extends AbstractTestAgainstFrozenReference { @@ -28,7 +31,7 @@ public class TestSamplePrograms extends AbstractTestAgainstFrozenReference { * particular directory, use sth. like: * {@code testDir = new File("javali_tests/HW2/")}. */ - public static final File testDir = new File("javali_tests/HW2_nop90"); + public static final File testDir = new File("javali_tests/HW3_nop90"); // public static final File testDir = new File("javali_tests"); @Parameters(name="{index}:{0}") @@ -61,8 +64,6 @@ public class TestSamplePrograms extends AbstractTestAgainstFrozenReference { this.semanticreffile = new File(file.getPath() + ".semantic.ref"); this.execreffile = new File(file.getPath() + ".exec.ref"); this.cfgreffile = new File(file.getPath() + ".cfg.dot.ref"); - this.rdreffile = new File(file.getPath() + ".rd.ref"); - this.nnreffile = new File(file.getPath() + ".nn.ref"); this.optreffile = new File(file.getPath() + ".opt.ref"); this.errfile = new File(String.format("%s.err", file.getPath())); this.main = new Main();