You should complete the front-end processing for the extended MiniJava language, checking any legality constraints not handled earlier in the scanning or parsing phases. These include the following additions to the hierarchies in the SymbolTable package:
- Extend the ResolvedType hierarchy to support the double type.
- Extend the ResolvedType hierarchy to support the array type constructor, which stores its element type. The array type constructor follows structural type equivalence rules. MiniJava restricts Java by defining one array type to be a subtype of another array type only when the two array types are equivalent.
- Extend the VarInterface hierarchy to support static class variable declarations.
You should implement typechecking for the new and/or modified AST node classes, including the following:
- Allow static class variables to be declared, so that they may be legally referenced in variable reads and assignments.
- Allow if statements to omit their else clause.
- Check that a for statements loop index variable was previously declared to be an int, that its initialization and update expressions return ints, and that its test expression returns a boolean.
- Check that a break statement only appears in the body of a while or for loop.
(You may change the interface of the Stmt.typecheck operation to do this.) Check that an or (||) expression has boolean operands.
- Check that an array new expression has a size subexpression of type int.
- Check that an array length expression has an array subexpression thats an array. Check that an array lookup expression has an array subexpression thats an array and an index subexpression thats an int.
- Check that an array assignment statement has an array subexpression thats an array, an index subexpression thats an int, and a right-hand-side expression whose type is assignable to the arrays element type.
- Allow ints to be assignable to doubles, including in regular assignments, in array assignments, in parameter passing into a method, and in returning from a method.
- Allow the +, -, *, /, <, <=, >=, >, ==, and != operations to also be applied to doubles, and, for binary operations, to mixes of ints and doubles.
- Allow the System.out.println operation to also be applied to a double.
In all cases, as long as the MiniJava restrictions are satisfied, a MiniJava expression should have the same result type as the equivalent Java expression.
You only need to get the compiler front-end to work. You do not need to implement any back-end lowering or code generation.
Do the following:
- Add and/or modify classes in the AST and SymbolTable subdirectories to typecheck the extended language.
- Develop test cases that demonstrate that your extended typechecker works, both in cases that should now be legal and in cases that should be syntactically legal but semantically illegal. (Since the typechecker quits at the first error, youll likely need several illegal test case files to test the different illegal cases.) You do not need to check for lexical or syntactic errors, just semantic errors. The SamplePrograms directory contains some files that should typecheck after you make your changes; some of the files should typecheck successfully with the initial version of the MiniJava compiler.
You can use the -typecheck -printSymbolTables options to the MiniJava compiler to just run the typechecking phase and print out the top-level symbol tables that it builds. See the test_typechecker target in the Makefile for an example, and feel free to make your own target(s) to make running the tests you like easier and more mechanical. Submit to VLE the following:
- Your new and/or modified AST/*.java and SymbolTable/*.java files. Clearly identify any modifications to existing files using comments.
- Your test cases, with names of the form name.legal.java for test cases that should typecheck successfully and name.illegal.java for test cases that should trigger typechecking errors.
- A transcript of running your typechecker and printing out the resulting symbol tables on each of your test cases.

![[Solved] UU-COM-4003 Compiler Design Assignment 2](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] UU-COM-4003 Compiler Design Assignment 1](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.