Fill This Form To Receive Instant Help
Homework answers / question archive / CMSC 430 Project 4 The fourth project involves modifying the semantic analyzer for the attached compiler by adding checks for semantic errors
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:
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 |
|
? |
Variable Initialization Mismatch |
|
? |
Undeclared Variable |
|
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 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
Semantic Error, If Expression Must Be Boolean
Semantic Error, Undeclared f
Semantic Error, Case Types Mismatch
Lexical Errors 0
Syntax Errors 0
Semantic Errors 3
You are to submit two files.
Criteria |
Meets |
Does Not Meet |
Functionality |
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 noninteger 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) |
|
Documentation |
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) |
Please download the answer file using this link
https://drive.google.com/file/d/1DpHvEgQNRcfUT44sXSM3FhkfVvFedJPY/view?usp=sharing