Compiler…. LInux …. C++


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:

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 correspondence 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 narrowing 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 returns.

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

· Narrowing Variable Initialization

· Variable Initialization Mismatch

· Undeclared Variable

· Duplicate Variable

· Narrowing Function Return


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 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 error 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 errors, the compiler should display the semantic errors in the compilation listing, after the line in which they occur. An example of compilation listing output containing semantic errors is shown below:

1 — Test of Multiple Semantic Errors 2

3 function test a: integer returns integer;

4 b: integer is

5 if a + 5 then 6 2;

7 else

8 5;

9 endif;

Semantic Error, If Expression Must Be Boolean 10 c: real is 9.8 – 2 + 8;

11 d: boolean is 7 = f; Semantic Error, Undeclared f

12 begin

13 case b is

14 when 1 => 4.5 + c;

15 when 2 => b; Semantic Error, Case Types Mismatch

16 others => c;

17 endcase;

18 end;

Lexical Errors 0

Syntax Errors 0

Semantic Errors 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 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

Grading Rubric




Does Not Meet



70 points

0 points



Generates semantic error when a   remainder operator has non-integer operands (10)

Does not generate   semantic error when a remainder operator has non- integer operands (0)


Generates   semantic error when if and then types don’t match (10)

Does   not generate semantic error when if and then types don’t match (0)


Generates semantic error when   case types don’t match (10)

Does not generate semantic error   when case types don’t match (0)


Generates semantic error when   if condition is not Boolean (10)

Does not generates semantic   error when if condition is not Boolean (0)


Generates semantic error when   case expression is not integer (10)

Does not generate semantic error   when case expression is not integer (0)


Generates semantic error on   narrowing initialization (10)

Does not generate   semantic error on narrowing initialization (0)


Generates semantic error for   duplicate variables (10)

Does not generate   semantic error for duplicate variables (0)


Test Cases

15 points

0 points



Includes test cases that test   all type checking errors (10)

Does not Include test cases that   test all type checking errors (0)


Includes test   cases that test all symbol table errors (3)

Does not include test cases that   test all symbol table errors (0)


Includes test case with   multiple errors (2)

Does not include   test case with multiple errors (0)



15 points

0 points



Discussion of approach included (5)

Discussion of approach not included (0)


Lessons learned included (5)

Lessons learned not included (0)


Comment blocks   with student name, project, date and code description included in each file   (5)

Comment blocks with student   name, project, date and code description not included in each file (0)

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Answers Market
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Thank you. I will forward critique once I receive it.
Customer 452467, July 25th, 2020
I requested a revision and it was returned in less than 24 hours. Great job!
Customer 452467, November 15th, 2020
Thank you for your help. I made a few minor adjustments to the paper but overall it was good.
Customer 452591, November 11th, 2021
Thank you very much!! I should definitely pass my class now. I appreciate you!!
Customer 452591, June 18th, 2022
Political science
Thank you!
Customer 452701, February 12th, 2023
Political science
I like the way it is organized, summarizes the main point, and compare the two articles. Thank you!
Customer 452701, February 12th, 2023
Business Studies
Great paper thanks!
Customer 452543, January 23rd, 2023
Thank you so much, Reaserch writer. you are so helpfull. I appreciate all the hard works. See you.
Customer 452701, February 12th, 2023
Thank you for your work
Customer 452551, October 22nd, 2021
Customer reviews in total
Current satisfaction rate
3 pages
Average paper length
Customers referred by a friend
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat