Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. (20pt) Consider the following SLR(1) grammar G for arithmetic expressions: E EAT E T T TMF T F F -F F (E) A +
5. (20pt) Consider the following SLR(1) grammar G for arithmetic expressions: E EAT E T T TMF T F F -F F (E) A + - M */ F id (1) (15pt) Construct an attributed grammar, based on G, that computes the type and value of an expression assuming that id's have, form the scanner, two attributes: type, which can be int or float and val, which is a number. In any operation, if one operand is a float, then both operands are converted to float using the operation n = float(n); e.g., float(2) = 2.0; the operation can be performed only between operands of the same type. The grammar does not have to be L-attributed. (2) (5pt) Using this attributed grammar, draw a decorated parse tree for the following expres- sion: (4 + -2.0) * 3. Show all attributes and arrows indicated what attributes are used to compute each value
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