Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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: intrint+int; real=real+real; or real=int+int; But "int=real+real" is illegal. 1. Syntax rule: = Semantic rule: .actual_type 2. Syntax rule: [2] + [3] Semantic rule: [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: + A B C Semantic rule: .actual_type look-up (.string) 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: intrint+int; real=real+real; or real=int+int; But "int=real+real" is illegal. 1. Syntax rule: = Semantic rule: .actual_type 2. Syntax rule: [2] + [3] Semantic rule: [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: + A B C Semantic rule: .actual_type look-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

More Books

Students also viewed these Databases questions

Question

2. Are my sources up to date?

Answered: 1 week ago