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

 Problem 4 (110 points). Consider the following CFG with the eight

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!