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...

1 answer below »
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
Answered Same DayAug 10, 2022

Answer To: The fourth project involves modifying the semantic analyzer for the attached compiler by adding...

Aditi answered on Aug 10 2022
66 Votes
CMSC430
Approach:
Semantic Analyzers are discussed in a four-part video series that I viewed befo
re commencing this project. After that, I read Mogensen's Textbook, Chapter 7. I began by importing the project 2 code into the particular project skeleton program after finishing all of the required reading. Following the project's specifications, I made the required adjustments to types.h and types.cc; scanner.l and parser.y; as well as to the components assessed from the bottom of a parse tree. I used a distinct test strategy for each modification I made to the code and double-checked my work after each one. As a result, the case statement was...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here