Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started