Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3: (20 points) Attached is the BNF basis of Example 3.6 in the book that requires (1) expression's data type will be int only

image text in transcribed

Question 3: (20 points) Attached is the BNF basis of Example 3.6 in the book that requires (1) expression's data type will be int only when both operands are int, and (2) the data types on both sides of the assignment operator "=" must be the same. Now change/add/remove the semantic rules/predicates (i.e., you are not going to change the Syntax rules) so that 1) If there is only one operand on the right side of the assignment, i.e., syntax rule #3, then a. either both sides have same data type, or b. left side is real and right side is int 2) If there are two operands on the right side of the assignment, i.e., syntax rule #2, then a. Data types of the two operands must be the same, and b. (either both sides have same data type) or (left side is real and both operands on right side are int) In other words, the following are legal: int=int+int; real=real+real; or real=int+int; But "int=real+real" is illegal. 1. Syntax rule: = Semantic rule: .expected_type + .actual_type 12. Syntax rule: [2] + svar>[3] Semantic rule: .actual_type if (svar>[2].actual_type = int) and ([3].actual_type = int) then int else real end if Predicate: .actual_type == .expected_type 3. Syntax rule: Semantic rule: .actual_type .actual_type Predicate: .actual_type == .expected_type 4. Syntax rule: svar> + A B C Semantic rule: .actual_typelook-up ( string) Question 3: (20 points) Attached is the BNF basis of Example 3.6 in the book that requires (1) expression's data type will be int only when both operands are int, and (2) the data types on both sides of the assignment operator "=" must be the same. Now change/add/remove the semantic rules/predicates (i.e., you are not going to change the Syntax rules) so that 1) If there is only one operand on the right side of the assignment, i.e., syntax rule #3, then a. either both sides have same data type, or b. left side is real and right side is int 2) If there are two operands on the right side of the assignment, i.e., syntax rule #2, then a. Data types of the two operands must be the same, and b. (either both sides have same data type) or (left side is real and both operands on right side are int) In other words, the following are legal: int=int+int; real=real+real; or real=int+int; But "int=real+real" is illegal. 1. Syntax rule: = Semantic rule: .expected_type + .actual_type 12. Syntax rule: [2] + svar>[3] Semantic rule: .actual_type if (svar>[2].actual_type = int) and ([3].actual_type = int) then int else real end if Predicate: .actual_type == .expected_type 3. Syntax rule: Semantic rule: .actual_type .actual_type Predicate: .actual_type == .expected_type 4. Syntax rule: svar> + A B C Semantic rule: .actual_typelook-up ( string)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions