Implement a third component of the compiler

Assignment Help JAVA Programming
Reference no: EM13317335

You will implement a third component of the compiler that checks the static semantics of the program being compiled. You will use the visitor design pattern to walk the AST to check anything that can be verified (statically) at compile-time.

Note that this is the third component for the VC compiler since the recogniser, once extended into a parser, will no longer be used.

Revision Log

1. Specification

You are to implement a semantic or contextual analyser that checks that the program conforms to the source language's context-sensitive constraints (i.e., static semantics) according to the VC Language Definition. This part of the compilation process is referred to as the semantic or contextual analysis.

There are two types of context-sensitive constraints:

• Scope rules: These are the rules governing declarations (defined occurrences of identifiers) and applied occurrences of identifiers.
• Type rules: These are the rules that allow us to infer the types of language constructs and to decide whether each construct has a valid type.

Therefore, the semantic analysis consists of two subphases:
• Identification: applying the scope rules to relate each applied occurrence of an identifier to its declaration, if any.
• Type checking: applying the type rules to infer the type of each construct and comparing that type with the expected type in the context.

This assignment involves developing a visitor class (named Checker) that implements the set of visitor methods in the interface VC.ASTs.Visitor.java. Your semantic analyser will be a visitor object that performs both identification and type checking in one pass by visiting the AST for the program being compiled in the depth-first traversal.

In the case of ill-typed constructs, appropriate error messages as specified below must be reported.

As before, if no lexical, syntactic or semantic error is found, your compiler should announce success by printing:

Compilation was successful.

Otherwise, the following message should be printed:

Compilation was unsuccessful.

2. Identification

This subphase of the semantic analyser has been implemented for you. Identification relates each applied occurrence of an identifier to its declaration, if any, by applying the VC's scope rules. The standard method of implementing this subphase is to employ a symbol table that associates identifiers with their attributes. In the VC compiler, the attribute for an identifier is represented by a pointer (an inherited attribute) to the subtree that represents the declaration (GlobalVarDecl, LocalVarDecl or FuncDecl) of the identifier. This attribute is represented by the instance variable decl in VC.ASTs.Ident.java:

package VC.ASTs;
importVC.Scanner.SourcePosition;
public class Ident extends Terminal {
public AST decl;
publicIdent(String value , SourcePosition position) {
super (value, position);
decl = null;
}
public Object visit(Visitor v, Object o) {
returnv.visitIdent(this, o);
}
}

There is only one symbol table organised as a stack for storing the identifiers in all scopes. Two classes are used:
• VC.Checker.IdEntry.java: defining what a symbol table entry looks like.
• VC.Checker.SymbolTable.java: defining all methods required for symbol table management.

The symbol table methods are called at the following visitor methods of the classChecker:

• visitGlobalVarDecl, visitLocalVarDecland andvisitFuncDecl:whenever the semantic analyser visits the declaration at a subtree, it will callinsertto enter the identifier, its scope level and a pointer to the subtree into the symbol table.

To detect duplicate declarations using the same identifier, you call the method retrieveOneLevel. This method returns a pointer to the identifier entry if the identifier was declared before in the current scope and null otherwise.

• visitIdent:whenever the semantic analyser visits an applied occurrence of an identifierI, it will callretrieve with the identifierIand thus retrieves the pointer to the subtree representing its declaration. It will then decorate the identifier node for Iby establishing a link to this declaration. This link is null if no declaration is found. This fact will be used by you to detect undeclared variables.

• visitCompoundStmt:whenever the semantic analyser visits a block, it calls openScopeat the start of the block to open a new scope andcloseScopeat the end of the block to close the current scope.


Attachment:- ASSIGNMENT.rar

Reference no: EM13317335

Questions Cloud

Determine the specific heat of the metal : 0.45 kg of a metal at 90degreesC is added to 0.40 kg of whater at 20.0degreesC. If the final temp of the mixture is 26.0degreesC, what is the specific heat of the metal
Employees take responsibility for operating : For wages to increase, what must grow at least at the same rate? Employees take responsibility for operating which of the following, in addition to bargaining with the employer?
Determine the magnetic energy density in the field : The magnetic fild inside a superconducting solenoid is 4.50 T. The solenoid has an inner diameter of 6.20 cm and a length of 26.0 cm. Determind the magnetic energy density in the field
Implement a third component of the compiler : To detect duplicate declarations using the same identifier, you call the method retrieveOneLevel. This method returns a pointer to the identifier entry if the identifier was declared before in the current scope and null otherwise.
Find the rms amplitude of the magnetic field : An electromagnetic wave produced by a dipole antenna is traveling in free space and has an rms electric field amplitude of 17 N/C. find the rms amplitude of the magnetic field
Find the wavelength of the same electromagnetic wave : he wavelength of an electromagnetic wave inside water (nwater = 1.33) is ? = 660 nm. find the wavelength of the same electromagnetic wave
What is the index of refraction of the material : The frequency of an electromagnetic wave is f = 3.75 x 1014 Hz, What is the index of refraction n of the material
Railway labor act? : What is the third purpose of the Railway Labor Act? Eliminating any restrictions on joining a union Guaranteeing the freedom of employees in any matter of self-organization Avoiding service interruptions Providing for prompt dispute settlement

Reviews

Write a Review

JAVA Programming Questions & Answers

  Distance traveled modification

Distance Traveled Modification

  Dijikstra for undirected graph using simple scheme

Dijikstra for undirected graph using simple scheme with array and fibonacci heap and compare the performance/results, preferably in java.

  Instance methods

instance methods: setWidth(double w), setHeight(double h), double getWidth(), double getHeight() and double getArea() * A triangle's area is calculated by width*height*0.5  * all variables are private and methods public.

  Tic-tac-toe game assignment

Assignment 1(Java): Tic-Tac-Toe Game (Assignment 1 is attached),  Use the concepts and scenario from Assignment 1 and continue with the tic-tac-toe game design and development.  Section 1: Java Program File, The following method, numPaths, is suppos..

  Using a link list implementation

Using a link list implementation, simulate the war car game. The program should read an input of several line of card values and output the winner and the number of rounds it takes.

  A java program that reads the records

A java program that reads the records from the golf.dat file and displays them. It also displays the name of the player with the best (lowest) golf score.

  Question superclass and provide a different implementa

Add a method addText to the Question superclass and provide a different implementa- tion of ChoiceQuestion that calls addText rather than storing an array list of choices.

  Chat monitoring system

The name of the project is chat monitoring system. in the file you will see the screenshot diagram 2A are my design, You need to upgrade, to look professional like the diagram 2B. Java, netbeans and GUI.

  Develop a program that will handle a golfer and his scores

develop a program that will handle a Golfer and his scores. The program will be comprised of two classes: a Golfer class that will manage all the golfer's scores and a Score class.This is a class designed to represent a golfer including his name, hom..

  Using your musicalinstrument class

Finally, create a Java test class that simulates using your MusicalInstrument class.  In your test class you should at a minimum: a) Construct 4 instances of your instrument, b) tune your instruments, c) print the name of your instrument d) print ..

  The reference to the abstract class

Explain what happens when the reference to the abstract class X is used to execute method M1( ). X obj = new Y( ); obj.M1( );

  Represent one book in java

Represent one book in java

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd