Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me in question G , H , i Problem 4 (110 points). Consider the following CFG with the eight terminals: true, false, A, V,

image text in transcribed

Help me in question G , H , i

Problem 4 (110 points). Consider the following CFG with the eight terminals: true, false, A, V, !, ==, (, and ). expr true false expr A exprecpr V expr ! exprexpr == 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 = 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) (c) Give the corresponding two ASTs. (10 points) (Hint: Note that operators A. V, -- and I 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) (e) Now, let's disambiguate G. We want to impose the following precedence cascade among operators: The highest precedence is for parentheses, the second highest precedence is for !. the third highest precedence is for A, the fourth highest precedence is for V, and finally the least precedence is for Define the disambiguated version of the grammar in BNF You are free to define the operators A and V to be left-associative or right-associative. Let's call your disambiguated grammar G'. (10 points) left-associative or right-associative? What about operator V? (10 (f) In your defined G', is operator points) (g) Using G', give the derivation for the same expression as you did previously, i.e.. !true false V true == 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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago