Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now
CMSC 430 Project 4
The fourth project involves modifying the semantic analyzer for the attached compiler by adding
checks for semantic e
ors. The static semantic rules of this language are the following:
Variables and parameter names have local scope. The scope rules require that all names be
declared and prohibit duplicate names within the same scope. The type co
espondence rules are
as follows:
ï‚· Boolean expressions cannot be used with arithmetic or relational operators.
ï‚· Arithmetic expressions cannot be used with logical operators.
ï‚· Reductions can only contain numeric types.
ï‚· Only integer operands can be used with the remainder operator.
ï‚· The two statements in an if statement must match in type. No coercion is performed.
ï‚· All the statements in a case statement must match in type. No coercion is performed.
ï‚· The type of the if expression must be Boolean.
ï‚· The type of the case expression must be Integer
ï‚· A na
owing variable initialization or function return occurs when a real value is being
forced into integer. Widening is permitted.
ï‚· Boolean types cannot be mixed with numeric types in variable initializations or function
eturns.
Type coercion from an integer to a real type is performed within arithmetic expressions.
You must make the following semantic checks. Those highlighted in yellow are already
performed by the code that you have been provided, although you are must make minor
modifications to account for the addition of real types and the need to perform type coercion and
to handle the additional arithmetic and logical operators.
ï‚· Using Boolean Expressions with Arithmetic Operator
ï‚· Using Boolean Expressions with Relational Operator
ï‚· Using Arithmetic Expressions with Logical Operator
ï‚· Reductions containing nonnumeric types
ï‚· Remainder Operator Requires Integer Operands
ï‚· If-Then Type Mismatch
ï‚· Case Types Mismatch
ï‚· If Condition Not Boolean
ï‚· Case Expression Not Integer
ï‚· Na
owing Variable Initialization
ï‚· Variable Initialization Mismatch
ï‚· Undeclared Variable
ï‚· Duplicate Variable
ï‚· Na
owing Function Return
This project requires modification to the bison input file, so that it defines the additional
semantic checks necessary to produce these e
ors and addition of functions to the li
ary of type
checking functions already provided in types.cc. You must also make some modifications to
the functions provided. You need to add a check to the checkAssignment function for
mismatched types in the case that Boolean and numeric types are mixed. You need to also add
code to the checkArithmetic function to coerce integers to reals when the types are mixed and
the e
or message must be modified to indicate that numeric rather than only integer types are
permitted.
The provided code includes a template class Symbols that defines the symbol table. It already
includes a check for undeclared identifiers. You need to add a check for duplicate identifiers.
Like the lexical and syntax e
ors, the compiler should display the semantic e
ors in the
compilation listing, after the line in which they occur. An example of compilation listing output
containing semantic e
ors is shown below:
XXXXXXXXXXTest of Multiple Semantic E
ors
2
3 function test a: integer returns integer;
XXXXXXXXXXb: integer is
XXXXXXXXXXif a + 5 then
XXXXXXXXXX;
XXXXXXXXXXelse
XXXXXXXXXX;
XXXXXXXXXXendif;
Semantic E
or, If Expression Must Be Boolean
XXXXXXXXXXc: real is XXXXXXXXXX;
XXXXXXXXXXd: boolean is 7 = f;
Semantic E
or, Undeclared f
12 begin
XXXXXXXXXXcase b is
XXXXXXXXXXwhen 1 => 4.5 + c;
XXXXXXXXXXwhen 2 => b;
Semantic E
or, Case Types Mismatch
XXXXXXXXXXothers => c;
XXXXXXXXXXendcase;
18 end;
Lexical E
ors 0
Syntax E
ors 0
Semantic E
ors 3
You are to submit two files.
1. The first is a .zip file that contains all the source code for the project. The .zip file
should contain the flex input file, which should be a .l file, the bison file, which should
e a .y file, all .cc and .h files and a makefile that builds the project.
2. The second is a Word document (PDF or RTF is also acceptable) that contains the
documentation for the project, which should include the following:
a. A discussion of how you approached the project
. A test plan that includes test cases that you have created indicating what aspects
of the program each one is testing and a screen shot of your compiler run on that
test case
c. A discussion of lessons learned from the project and any improvements that could
e made
Answered Same Day Aug 07, 2023

Solution

Ajay answered on Aug 08 2023
24 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here