Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Project 3 - Semantic Analysis Skip navigation COMP3710: Compiler Design and Implementation Research School of Computer Science Search query Search ANU web, staff & maps Search current site content Search Menu Search query Search COMP3710 Lectures Labs Deliverables Resources Search ANU web, staff & maps Search current site content Lectures Labs Deliverables Resources menu Search query Search COMP3710 Search query Labs Week 1 - Introduction Project 1 - Scanning Project 2 - Parsing Project 3 - Semantic Analysis Project 4 - Translation Project 5 - Instruction selection Related sites CS Homepage GitLab Streams Current students You are here » Labs » Project 3 - Semantic Analysis Description Implement the semantic analysis phase for the MiniJava+S language using the provided framework. Getting Started Before starting this project, familiarize yourself with Chapter 5 of the textbook and review the lecture notes on semantic analysis. To get started coding, fork the Project 3 repo on GitLab. This project includes new source code that implements scaffolding for the semantic analysis phase of the compiler. Remember that the link between the Project 2 and Project 3 is the correct construction of AST nodes from Absyn.java. The framework for building the AST and printing out the results is the same as before, in src/mj/Absyn.java, with slight modifications to add fields for the types of expressions. You do not need to edit src/mj/Absyn.java. Provided Parser Solution The Project repo also includes a binary that implements a complete parser in lib/mj/*.class. You may choose to base your Project 3 work on the provided parser, or continue using your own parser. It is expected that you do not try to reverse engineer the class files of the provided parser to improve your score on Project 2, although you may run them to understand why your parser might be broken. You can use your own parser by copying your files from Project 2 into src/mj. You will have to modify the Makefile to make JavaCC regenerate your parser source if you modify your .jj file while working on this project. The grading script will work with either parser as long as you put its source in the proper place. Where to Add Your Code All the action in this project is in src/mj/Semant.java. It is the driver for running semantic analysis. You should only need to edit src/mj/Semant.java to complete this project. This file will not compile until you implement the visit() methods that are required by the Absyn.Visitor interface. This is to guide you on what functionality you need to implement. After you get it to compile, you can run the driver with: % java -cp bin:lib mj.Semant Running the driver outputs a dump of the symbol table (i.e. all scopes in the program). If there are errors, they will be written to standard error. There is Lots of Code to Help You Here The provided framework provides utilities that implement a representation of the symbol table (i.e. scopes), as well as types (i.e. classes, primitives, arrays, etc.). You should use these classes and not write your own. They contain all the functionality that you need to complete this project. Types A set of classes representing semantic types is provided. These are different than syntactic types that are in the AST. Semantic types are how the compiler reasons about primitives, arrays, classes, etc. Type.Primitive Represents int, boolean, null, and void Type.RECORD A utility which is like a “symbol table” that maps from strings to type T. Basically, it is a hashmap from string -> T. Type.FUN Represents function types, i.e. a function from parameter types to return type. You should use this to represent the types of methods. Type.INSTANCE Represents the type of instances of objects. Instances have both fields and methods. An INSTANCE type internally uses RECORD as a symbol table for fields and RECORD as a symbol table for methods. Type.CLASS Represents the type of classes. Classes have (static) fields and methods. A CLASS type internally uses a RECORD as a symbol table for (static) fields and RECORD for (static) methods. Type.ARRAY Represents an array type. Internally has an element type. Symbol Tables and Scopes A symbol table is provided in src/Symbol/Table.java. You will use one to keep track of parameters and local variables when checking the body of a method. Internally, it has a stack of src/Symbol/Scope.java scopes. Errors A huge hint for this project is that there is an ErrorGen class defined in src/mj/Seman.java. It has one method for each type of error that your semantic analyzer should generate. A completed project should use all of the methods in this class. It also takes care of standardizing the message that is output to the user for every error, so that it is easier to automatically check your analyzer is correct. Use these methods and prosper! All of these methods accept an appropriate AST node that is used for reporting the error location. Make sure to provided the proper AST node so that errors are reported for the correct line. If there is a method you haven’t used yet, they you are probably missing a check for something! Expected Output The class mj.Semant contains a main method that loads files, invokes the parser and runs the semantic analysis phase. Unlike previous projects, the grading script checks both standard out and standard error, i.e. it checks that your semantic analyzer builds the proper scopes and also generates appropriate error messages. Make sure your program does not add any extraneous output to standard output. Make sure to run against the provided tests. You can still add debugging output to standard error. The grading script just greps for any expected semantic error in standard error. Make sure to use the provided error methods, as they give good error messages, and the script actually checks their text! FAQ, Tips, and Tricks Q: How can I implement semantic analysis with only pass over the AST? It seems impossible. A: For Java, it is, in fact, impossible. Your semantic analyzer may need to make multiple passes over the AST in order to check all possible errors. Turn in and Grading Like previous projects, you should fork the project repo to get started. Like before, you don’t need to turn anything in. We will pull from your repo’s master branch at the deadline. We will rebuild your submission from source with your Makefile. We will run the grading script on your code with additional test inputs that are not included in the repo. We will provide the additional test inputs along with your score after the deadline. Make sure your program doesn’t print anything extra to stdout! Updated:    09 Jul 2020 / Responsible Officer:    Director, RSCS / Page Contact:    Course Convenor Contact ANU Copyright Disclaimer Privacy Freedom of Information +61 2 6125 5111 The Australian National University, Canberra CRICOS Provider : 00120C ABN : 52 234 063 906 You appear to be using Internet Explorer 7, or have compatibility view turned on. Your browser is not supported by ANU web styles. » Learn how to fix this » Ignore this warning in future home