Semantic analyzer for the attached compiler

Assignment Help Theory of Computation
Reference no: EM133400024 , Length: 7 pages

Design and Implementation of Programming Languages

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

Reference no: EM133400024

Questions Cloud

What is the main advantage of a 64-bit version of windows : In terms of system hardware, what is the main advantage of a 64-bit version of Windows? You are advising a business that needs to provision video-editing
Which wi-fi standards work in this band : You are assessing standards compatibility for a Wi-Fi network. Most employees have mobile devices with single-band 2.4 GHz radios. Which Wi-Fi standards work
Show that a graph g can contain an all-edge cycle only : An all-edge cycle in an undirected graph is a cycle that uses each edge in the graph exactly once. It may visit the same node multiple times.
How can i make an application using proper ui : how can i make an application using proper ui and with a perfect outcome of the app to publish it in the market in what language should i code as well as which
Semantic analyzer for the attached compiler : Design and Implementation of Programming Languages - analyzer for the attached compiler by adding checks for semantic errors
Total asset turnover tells us the number of interest rate : Total asset turnover tells us the number of interest rate rotations on the asset.
How do the models compare with each model : How do the models compare with each model? What are the pros and cons of reach model? What is your selected model? Why did you select that specific model?
Identify the stakeholders for your scenario : Make a list of questions that you would ask about these forms and reports given to you for review. Identify the stakeholders for your scenario.
Economics of organizational architecture : From The Economics of Organizational Architecture- When assigning...decision rights...top management must also ensure that the company's performance evaluation

Reviews

len3400024

4/25/2023 10:02:35 PM

Discussion of approach included (10) Lessons learned included Comment blocks with student name (RCook, project 4, date and code description included in each file username for school nees to be on screenshots.

Write a Review

Theory of Computation Questions & Answers

  Find a regular expression for the language

Theory of Computation – UE17CS254 - Show that the language of binary strings of even length having the same number of 0s in its two halves is not regular

  Productions of nonterminals as right regular grammars

Rewrite the productions for each of the following nonterminals as right regular grammars: Identifier, Float. Show the moves made using the DFSA for identifiers in accepting.

  Show language consisting bit strings that are palindromes

Suppose that L is a subset of I * and for some positive integer n there are n strings in I * such that every two of these strings are distinguishable.

  Find a phrase-structure grammar

Find a phrase-structure grammar that generates each of these languages.

  Benefits that can arise from from the inclusion of ai

Managing a Successful Computing Project - Potential benefits and challenges that can arise from the inclusion of AI into a system

  Construct a finite-state automaton

Construct a finite-state automaton that recognizes the set of bit strings consisting of a 0 followed by a string with an odd number of 1s.

  Construct unambiguous context free grammars

Construct unambiguous context-free grammars for each of the following languages. In each case show that your grammar is correct.

  What is a succinct non-membership witness for these language

CS 600 Theory of Computation, George Mason University Define the languages (3-COLOR)?, (HAMPATH)? and explain what is a succinct non-membership witness

  APM 3430 Theory of Computation Assignment

APM 3430 Theory of Computation Assignment Help and Solution, Oakland University - Assessment Writing Service - Find a recursive definition for the language

  Design 64 fft using vhdl step by step

What is FFT? Design 64 FFT using VHDL, step by step.

  The latest entry into the snack food industry

The latest entry into the snack food industry is a health-conscious offering named Hooks, Wheels, and Ladders. Each box mixes several flavors, such as ranch, cheddar, and salsa. The snack is designed to appeal to kids based on the snack shapes

  Create a program that makes an object

Create a class named Pet, after creating the class, create a program that makes an object of the class and prompts the user to enter the name, type, and age of his pet.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd