Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following CFG with the eight terminals: true, false, ^, V, !, (, and ). expr true | false expr A erpr |

Consider the following CFG with the eight terminals: true, false, A, V, !, (, and ). expr  true false | erpr

Consider the following CFG with the eight terminals: true, false, ^, V, !, (, and ). expr true | false expr A erpr | erpr V expr | ! expr | expr= expr | (expr) Indeed, the starting symbol is expr. Let's call this grammar G. This grammar is ambiguous, i.e., there exist at least two parse trees for some expression. For example, consider the following expression: !true ^ false V true (a) Give two different derivations for this expression such that the corresponding parse trees are differ- ent from each other. (10 points) (b) Give the corresponding parse trees for each derivation in the previous question. (10 points) true (c) Give the corresponding two ASTs. (10 points) (Hint: Note that operators A, V, ==, and ! can appear as interior nodes in AST. You may remove the nonterminal expr from ASTs as it does not convey any computational information.) (d) If you pass the ASTs from the previous question to an evaluator, what would be the final value in each case? (10 points)

Step by Step Solution

3.34 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

As the Grammer G is ambiguous so we generate a Grammer G given in the question where precedence is g... 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_2

Step: 3

blur-text-image_3

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

Programming Language Pragmatics

Authors: Michael L. Scott

4th Edition

0124104096, 978-0124104099

More Books

Students also viewed these Programming questions

Question

Identify six common problems with goal setting.

Answered: 1 week ago

Question

explain the main theories of concentration effects,

Answered: 1 week ago

Question

discuss the sources of sport confidence,

Answered: 1 week ago