Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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