Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4 (110 points). Consider the following CFG with the eight terminals: true, false, A, V, !, ==, (, and ). erpr + true false

image text in transcribed

Problem 4 (110 points). Consider the following CFG with the eight terminals: true, false, A, V, !, ==, (, and ). erpr + true false exprerprerpr Verpr !erprexpr == expr (erpr) Indeed, the starting symbol is erpr. 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 Vtrue == true (g) Using G', give the derivation for the same expression as you did previously, i.e., !true false Vtrue == true Note that since G' is disambiguated, there must be a unique parse tree for this expression. (5 points) (h) Give the corresponding parse tree for the derivation in the previous question. (5 points) (i) Give the corresponding AST for the parse tree in the previous question. (5 points) () If you pass this AST to an evaluator, what would be the final result? (5 points) (k) Redefine G' using EBNF. Let's call this version of grammar G". (10 points) (1) Give the pseudo-code for the recursive-descent parser that implements G". The parser needs to generate the AST (so it is not a recognizer!). (20 points) Problem 4 (110 points). Consider the following CFG with the eight terminals: true, false, A, V, !, ==, (, and ). erpr + true false exprerprerpr Verpr !erprexpr == expr (erpr) Indeed, the starting symbol is erpr. 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 Vtrue == true (g) Using G', give the derivation for the same expression as you did previously, i.e., !true false Vtrue == true Note that since G' is disambiguated, there must be a unique parse tree for this expression. (5 points) (h) Give the corresponding parse tree for the derivation in the previous question. (5 points) (i) Give the corresponding AST for the parse tree in the previous question. (5 points) () If you pass this AST to an evaluator, what would be the final result? (5 points) (k) Redefine G' using EBNF. Let's call this version of grammar G". (10 points) (1) Give the pseudo-code for the recursive-descent parser that implements G". The parser needs to generate the AST (so it is not a recognizer!). (20 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

explain the need for human resource strategies in organisations

Answered: 1 week ago

Question

describe the stages involved in human resource planning

Answered: 1 week ago