Compiler Theory

CMSC 430 Project 4
The fourth project involves modifying the semantic analyzer for the attached compiler by adding
checks for semantic errors. The static semantic rules of this language are the following:
Variable 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 correspondence rules are
as follows:
 Both expressions in the when statement must be the same type
 The type of the switch expression must be Integer.
 All the case statements in a switch statement must match in type. No coercion is
performed.
 Arithmetic operators can only be used with numeric types.
 All list elements must be of the same type.
 In a list variable declaration, the type of the list must match the type of the elements.
 List subscripts must be integer expressions.
 Character literals can be compared to one another but they cannot be compared to
numeric expressions.
 Only integer operands can be used with the remainder operator.
 All the statements in an if statement must match in type. No coercion is performed.
 In a fold statement, the list must be a numeric type.
 A narrowing variable initialization or function return error occurs when a real value is
being forced into integer. Widening is permitted. In all other cases, the type must match.
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, relational and logical operators.
 Type Mismatch on Variable Initialization
 When Types Mismatch
 Switch Expression Not Integer
 Case Types Mismatch
 Arithmetic Operator Requires Numeric Types
 Undeclared Scalar
 Undeclared List
 List Element Types Do Not Match
 List Type Does Not Match Element Types
 List Subscript Must Be Integer
 Character Literals Cannot be Compared to Numeric Expressions
 Remainder Operator Requires Integer Operands

 If-Elsif-Else Type Mismatch
 Fold Requires A Numeric List
 Illegal Narrowing Variable Initialization
 Illegal Narrowing Function Return
 Type Mismatch on Function Return
 Duplicate Scalar
 Duplicate List
This project requires modification to the bison input file, so that it defines the additional
semantic checks necessary to produce these errors and addition of functions to the library 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 nonnumeric 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.
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 errors, the compiler should display the semantic errors in the
compilation listing, after the line in which they occur. An example of a compilation listing output
containing semantic errors is shown below:
1 // Multiple Semantic Errors
2
3 function main returns integer;
4 value: integer is 4.5;
Semantic Error, Illegal Narrowing Variable Initialization
5 numbers: list of real is (1, 2, 3);
Semantic Error, List Type Does Not Match Element Types
6 one: integer is ‘1’;
Semantic Error, Type Mismatch on Variable Initialization
7 begin
8 if value > 0 then
9 fold left + (‘a’, ‘b’) endfold;
Semantic Error, Fold Requires A Numeric List
10 elsif name = ‘N’ then
Semantic Error, Undeclared Scalar name
11 fold right * (1, 2.5) endfold;
Semantic Error, List Element Types Do Not Match
12 else
13 when value < 10, 1 : 1.5;
Semantic Error, When Types Mismatch
14 endif;
15 end;
Lexical Errors 0
Syntax Errors 0
Semantic Errors 7
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
be 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
b. 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
be made

QUALITY: 100% ORIGINAL PAPER NO ChatGPT.NO PLAGIARISMCUSTOM PAPER

Best Custom Essay Writing Services

Looking for unparalleled custom paper writing services? Our team of experienced professionals at AcademicWritersBay.com is here to provide you with top-notch assistance that caters to your unique needs.

We understand the importance of producing original, high-quality papers that reflect your personal voice and meet the rigorous standards of academia. That’s why we assure you that our work is completely plagiarism-free—we craft bespoke solutions tailored exclusively for you.

Why Choose AcademicWritersBay.com?

  • Our papers are 100% original, custom-written from scratch.
  • We’re here to support you around the clock, any day of the year.
  • You’ll find our prices competitive and reasonable.
  • We handle papers across all subjects, regardless of urgency or difficulty.
  • Need a paper urgently? We can deliver within 6 hours!
  • Relax with our on-time delivery commitment.
  • We offer money-back and privacy guarantees to ensure your satisfaction and confidentiality.
  • Benefit from unlimited amendments upon request to get the paper you envisioned.
  • We pledge our dedication to meeting your expectations and achieving the grade you deserve.

Our Process: Getting started with us is as simple as can be. Here’s how to do it:

  • Click on the “Place Your Order” tab at the top or the “Order Now” button at the bottom. You’ll be directed to our order form.
  • Provide the specifics of your paper in the “PAPER DETAILS” section.
  • Select your academic level, the deadline, and the required number of pages.
  • Click on “CREATE ACCOUNT & SIGN IN” to provide your registration details, then “PROCEED TO CHECKOUT.”
  • Follow the simple payment instructions and soon, our writers will be hard at work on your paper.

AcademicWritersBay.com is dedicated to expediting the writing process without compromising on quality. Our roster of writers boasts individuals with advanced degrees—Masters and PhDs—in a myriad of disciplines, ensuring that no matter the complexity or field of your assignment, we have the expertise to tackle it with finesse. Our quick turnover doesn’t mean rushed work; it means efficiency and priority handling, ensuring your deadlines are met with the excellence your academics demand.

ORDER NOW and experience the difference with AcademicWritersBay.com, where excellence meets timely delivery.

NO PLAGIARISM