Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let G = ({I}, {s, d}, P, I) be the context-free grammar with rules I rightarrow sI |sIdI| elementof. Let T be the language of
Let G = ({I}, {s, d}, P, I) be the context-free grammar with rules I rightarrow sI |sIdI| elementof. Let T be the language of strings r over {s, d} such that for every prefix y of x, #s(y) greaterthanorequalto #d(y). For a fact, L(G) = T-you are not asked to prove this. For further interpretation, note that if you interpret s = "spear" and d = "dragon, " then T specifies the strings in which you "survive if you can hold arbitrarily many spears." More prosaically, if you interpret s as a left-paren and d as a right-paren, then T becomes the language of strings that might not yet be balanced, but can be closed out to be balanced by appending some number of ')' parens. (a) Give both a parse tree and a leftmost derivation for each of the following strings in T (i) x_1 = sdssd (ii) x_2 = sssddsdd (iii) x_3 = ssdssdssdd. (b) Show that G is ambiguous, by finding an ambiguous string in T and giving two distinct derivation trees or two distinct leftmost derivations-your choice. (There are even shorter strings than the above.)
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