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

  Java application prompt user to put in integer from keyboard

Write a java application that performs the following task: prompt user to put in an integer from the keyboard, search for the user input from the array created in step 1.

  Own file to test your program

Create your own file to test your program. Your job is to set up the input and output files to have the program read from a file and write to a file. Here is a basic program that will accomplish what is desired

  Length of the string in order to reserve space

To determine the length of the string in order to reserve space for the new string use the library routine strlen. Register a1 contains a pointer to the string to measure and on return register a1 has the number of characters in the string. You..

  Determine product a inferior or normal good

Research illustrates that prices of related goods are given by Py = $5,900 and ; Pz = $90, while average income of individuals consuming this product is M = $55,000. Is X inferior or normal good?

  Create a deque class based on the discussion of deques

Create a Deque class based on the discussion of deques (double-ended queues) in this chapter. It should include insertLeft(), insertRight(), removeLeft(), removeRight(), isEmpty(), and isFull() methods.

  Return a reverse queue

represent my queue object as a parameter, what the program should be doing. It should return a reverse queue

  An api for a library that provides for all these operations

Quaternions can be represented with four (4) real numbers (a,b,c,d). They can be added, subtracted, multiplied and divided. You can multiply a quaternion by a scalar (which produces a quaternion as a result)

  Write program in java for total amount of customer-s order

Write down program in Java which would ask for clerk to enter total amount of customer's order. Program will then compute seven percent (7%) sales tax.

  Public float usefulload()

public float usefulLoad() // this is the grossWeight - emptyWeight public float usefulLoadWithFuel( in gallons ) // this is the useful load - gallons x 6. The programmer user will pass in the number of gallons on board.

  Elliptic curve encryption

write a program to implement Elliptic Curve encryption/decryption and program will read parameters, plaintext and ciphertextfrom a file named "input.txt" (under the same directory).

  Given a sequence of 10 integers

Write a program given that given a sequence of 10 integers, find out and delete the maximum and minimum number, then compute the average of the rest.

  Shows the users name and program name

Java program, the program has a page that shows the users name and program name. a second jpanel that shows 4 buttons (circle square rectangle and oval) the problem i am having is that my program is not dropping where i click and the shapes are not s..

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