New version page

UT Arlington CSE 5317 - Programming Assignment 1

Upgrade to remove ads
Upgrade to remove ads
Unformatted text preview:

CSE 5317 Spring 2010: Programming Assignment 1Type-checking MiniJavaAssigned: 9 Feb 2010Due: 25 Feb 2010, 2:00pmMiniJava is a subset of Java. The meaning of a MiniJava program is given by its meaning as a Java program. Somekey differences between Java and MiniJava are:• All code resides in a single file which must contain a class that provides a main method.• The main method is the only static method.• There are no static fields.• The only types are int, int[], and classes.• There are no nested or inner classes.• Method overloading is not allowed.• The MiniJava statement System.out.println(...); is built-in and can only print integers.• The formal parameters of main cannot be used (since String is not a type).• The MiniJava expression e.length only applies to expressions of type int[].See the project web page at:http://ranger.uta.edu/~nystrom/courses/5317/projectThere you will find the MiniJava grammar, including a JavaCC file minijava.jj.In this project, you will use JTB and JavaCC, and write code in Java, to type check a MiniJava program. Your mainclass should be called pa1.Typecheck.If P.java contains a program to type, then running:java pa1.Typecheck < P.javashould print either “Program ok” or “Type error”.You can download JavaCC from:https://javacc.dev.java.net/You can download JTB from:http://compilers.cs.ucla.edu/jtb/1Steps(a) Create a directory named minijava and change into it.$ mkdir minijava$ cd minijava(b) In that directory (and assuming minijava.jj and all the files you downloaded are in the parent directory),generate the AST and visitors classes using JTB:$ java -jar ../jtb132.jar -jd -printer -p minijava ../minijava.jjThis will generate jtb.out.jj as well as files in the syntaxtree and visitor directories.(c) Still in the minijava directory, generate the MiniJava parser.$ ../javacc-5.0/bin/javacc -OUTPUT DIRECTORY=parser jtb.out.jjThis will generate a parser in the parser directory.(d) All the automatically generate source code should now be generated.$ cd ..$ ls minijavajtb.out.jj parser syntaxtree visitorYou should now be able to compile all of these classes.$ javac minijava/*/*.javaYou are welcome to use Eclipse or any other development tools to implement the remainder of this project.(e) Now, in a package named pa1, implement a class named Typecheck that contains a main method. You cangrab a template from:http://ranger.uta.edu/~nystrom/courses/5317/project/Typecheck.javaThis class should:(a) Read a MiniJava file from System.in,(b) Parse the file using the generated MiniJavaParser,(c) Create an empty class table,(d) Create an empty type map,(e) Create an empty typing environment,(f) Use a visitor to traverse the AST building the class table,(g) Use a visitor to traverse the AST computing types and checking them, reporting any errors, and storingtypes in the type map.(h) If the compiler detects an error, it can report and exit immediately; your compiler need not attempt torecover from errors.These visitors use the following data structures implementing the symbol table:(a) The class table, a map from class names to information about the class.(b) The type map, a map from AST nodes to type descriptors. The type map will be used by later passes.(c) The type descriptors, objects which represent types.(d) The typing environment, objects that contains a map from variable names to types, and keep track of thecurrent class, current method return type, and other information needed during type


View Full Document
Download Programming Assignment 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming Assignment 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming Assignment 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?