Due: .
Do "Chapter 4: Abstract Syntax", page 101, and "Chapter 5: Type-Checking", page 114. Find as many semantic errors as you can. Detecting uninitialized local variables requires a third visitor and may be omitted for the sake of time.The jar file support.jar contains the revised abstract syntax tree for use with MiniJava as Java package syntax. The jar file contains the class files and the source. You will need to understand the source in order to build and traverse the abstract syntax tree of a MiniJava program. The jar file contains several useful packages, some important in later stages:
syntax tree canon assem graphDo not use these Java packages for your files or modify anything in these packages.
In order to avoid turning in the shared file support.jar, we need to agree where it will found when you translate your compiler from source and when your script runs the compiler. Let us agree that the path to the support.jar is given by the makefile variable SUPPORT. In other words, your makefile will be used to translate your compiler with the following command:
make SUPPORT=</absolute/path/dir/support.jar>This jar file will be the same as the one on the WWW at the link above. namely this one:
https://cs.fit.edu/cse4251/support.jar.
It is your responsibility to put support.jar in the class path of the Java system. This is necessary twice: during complication and during execution. Your makefile might contain a command like this:
javac -classspath .:$SUPPORT *.java(Note that a URL cannot be used in this classpath.)
Since your are required to create an executable jar file to be your program and your program needs the support packages, you need to create a manifest file in your jar file that knows the location of support.jar. (Note the command-line classpath is ignored when a jar file is executed.) This can be done by generating the manifest file on the fly using the information in the makefile variable SUPPORT. But it is easier to use a fixed path.
Main-Class: semantics.Main Class-Path: support.jarThe first line is
The synatx of manifest files is unforgiving and they are difficult to debug. So take note:
Futhermore, be sure to test thoroughly.
Running make should create an executable compile script as usual.
But for my convenience running make should produce an executable jar named
check.jar in the top-level directory (i.e., in the same directory as
the make file.
So testing can proceed simply as follows:
make jar -jar check.jar path1/TestCase1.java jar -jar check.jar path2/TestCase2.java # And possibly ... ./compile path3/TestCase3.java ./compile path4/TestCase4.java
As always, in all cases there must be a single line of output to the standard output stream of the following form:
filename=path1/TestCase1.java, errors=0It is important that your compiler does not fail for any reason. By "not failing" I mean the compiler always runs to completion, terminates normally, and returns an exit status of zero.
If the number of errors is zero, then nothing should be printed to the standard error stream. However, if the number of errors is greater than zero, then there must be an error message printed for each error. Error messages must have the form:
path2/TestCase2:149.23: Error ..... path2/TestCase2:171.18: Error .....Error messages contain the file name, the line number, the character position, and an informative error message. An error message may be longer than one line.
No debug output should be created by default.
But you are encouraged to write debug output to a file upon demand;
I recommend a Java system property like -Dverbose.
syntax is given below.
package syntax
abstract class AST
class Program (MainClass, List<ClassDecl>)
class MainClass (Identifier, Identifier, Statement)
abstract class ClassDecl
class SimpleClassDecl (Identifier, List<FieldDecl>, List<MethodDecl>)
class ExtendingClassDecl (Identifier, Identifier, List<FieldDecl>, List<MethodDecl>)
class VarDecl (Type, Identifier)
class MethodDecl (Type, Identifier, List<Formal>, List<VarDecl>, List<Statement>, Expression)
class Formal (Type, Identifier)
abstract class Type
public final static IntegerType THE_INTEGER_TYPE
public final static BooleanType THE_BOOLEAN_TYPE
public final static IntArrayType THE_INT_ARRAY_TYPE
class IdentifierType (String)
abstract class Statement
class Block (List <Statement>)
class If (Expression, Statement, Statement)
class While (Expression, Statement)
class Print (Expression)
class Assign (Identifier, Expression)
class ArrayAssign (Identifier, Expression, Expression)
abstract class Expression
class And (Expression, Expression)
class LessThan (Expression, Expression)
class Plus (Expression, Expression)
class Minus (Expression, Expression)
class Times (Expression, Expression)
class ArrayLookup (Expression, Expression)
class ArrayLength (Expression)
class Call (Expression, Identifier, List<Expression>)
class IntegerLiteral (int)
class True ()
class False ()
class IdentifierExp (String)
class This ()
class NewArray (Expression)
class NewObject (Identifier)
class Not (Expression)
class Identifier (String)
The command
make SUPPORT=</absolute/path/dir/support.jar>must produce an executable Java jar program named check.jar.
Include all the following targets in your makefile.
.PHONY default compiler # First, and hence, default, target default : compiler compiler : check.jar check.jar : ...In this way there are several equivalent ways to initiate the creation of the compiler from the source code:
make # I'll use this one make default make compiler make check.jar
Turn in the source code for the project using the
submission server.
The submit project tag for this assignment is
.
For your convenience, here is a submission form for this assignment.