Question: Part - 4 1 . Consider the following grammar: ass v = exp exp v exp exp + v exp | v id | num

Part-4
1. Consider the following grammar:
ass v= exp
exp v exp
exp+ v exp|
v id | num | num.num
Write an attribute grammar that:
a. Determines the type of the expression (exp) according to the following rule if the two operands of the addition operator (+) are of integer type, the type of the result is integer else the type of the result is real
(Hint: It is not required to check the types of the operands in this grammar for simplicity in this problem, and you can assume that there is a semantic function called Determine-Type (Op1, Op2) that takes two operands as inputs and return the appropriate type according to the above rule}
b. Checks that the two sides of the assignment statement have the same type. If they are not of the same type a semantic error should be signaled.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!