Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(30pt) Consider the following SLR(1) grammar, G, for boolean expressions containing operands (id), operators (and, or), and parentheses: P B$$ B B or D B
(30pt) Consider the following SLR(1) grammar, G, for boolean expressions containing operands (id), operators (and, or), and parentheses: P B$$ B B or D B D D D and C D (B) id (a) (20pt) Construct an attribute grammar, based on G, that evaluates the value, val, of a boolean expression by avoiding unnecessary computations; e.g., if A is true, then A or B is true, so there is no need to evaluate B; similarly, if A is false, then A and B is false, so, again, there is no need to evaluate B. Each id has a known attribute val that is true or false. The attribute grammar must be designed such that the value of any expression can be computed by a single traversal of the parse tree. (b) (10pt) Using this attribute grammar, draw a decorated tree for the following boolean expression: (u or v) and (x or y) or z $$, where u,v,x,y,z are id's such that u.val = v.val y.val = = false, x.val z.val = true. (30pt) Consider the following SLR(1) grammar, G, for boolean expressions containing operands (id), operators (and, or), and parentheses: P B$$ B B or D B D D D and C D (B) id (a) (20pt) Construct an attribute grammar, based on G, that evaluates the value, val, of a boolean expression by avoiding unnecessary computations; e.g., if A is true, then A or B is true, so there is no need to evaluate B; similarly, if A is false, then A and B is false, so, again, there is no need to evaluate B. Each id has a known attribute val that is true or false. The attribute grammar must be designed such that the value of any expression can be computed by a single traversal of the parse tree. (b) (10pt) Using this attribute grammar, draw a decorated tree for the following boolean expression: (u or v) and (x or y) or z $$, where u,v,x,y,z are id's such that u.val = v.val y.val = = false, x.val z.val = true
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