Question

In: Computer Science

Problem 3. Let G be the grammar we saw in homework 3: E -> E +...

Problem 3.

Let G be the grammar we saw in homework 3:

E -> E + T | E - T | T

T -> T * F | F

F -> ( E ) | x | y

Let w be (x + y) * x - y

a) Show the leftmost derivation for w in G. Number the rules for G and show the corresponding rule number under each substitution arrow in the derivation.

Hint: it may be easier to create a parse tree first, as you did in homework 3

b) Convert G to a string-pushing PDA, call it DG; show a transition diagram for DG. There will be one reduce transition for each terminal symbol in G and one shift transition for each rule in G.

Label all transitions in DG as follows:

  • Ti and Tf for the initial and final transitions

  • Rc for a reduce transition that reads terminal symbol c

  • Sk for a shift transition that corresponds to rule numbered k in G

c) Show an accepting computation for w in DG as a table. This table will one row per transition, and 4 columns: remaining input, current state, stack contents, and next transition. For example, the first row in your table will be (w, q0, e, Ti)

Hint: use your derivation from part (a) to help you choose the shift transitions

Solutions

Expert Solution

the shift reduce parsing of the given string has been done in the figure above. In that figure initially this content is dollar which represent the bottom of the stack. The input string initially is the given string in the question. In step by step process we first take the imput string contents to the stack and as and when the string in the stack becomes eligible for the reduced operation through the given grammar, we reduce it immediately in a reduced step as shown in the figure above. This procedure goes on until we pass the whole of input string and finally the the string is reduced to a single start symbol. Here we got the start symbol as E. And now the stack is empty and the passing is over and hence we accept the string.

To easily create the table for stack contents and action performed, we will make a purse tree in which we will do left hand derivation starting from the start symbol to get to the given input string in a step by step use of the given grammar.


Related Solutions

Let G be connected, and let e be an edge of G. Prove that e is...
Let G be connected, and let e be an edge of G. Prove that e is a bridge if and only if it is in every spanning tree of G.
Can someone please answer these 3 by Friday? Problem 2 Let D, E, F, G, and...
Can someone please answer these 3 by Friday? Problem 2 Let D, E, F, G, and H be events such that P(D) = 0.7, P(E) = 0.6, P(F) = 0.8, P(G) = 0.9, and P(H) = 0.5. Suppose that Dc, E, Fc, Gc, and H are independent. (a) Find the probability that all of the events D, E, F, G, and H occur. (b) Find the probability that at least one of the events D, E, F, G, and H...
Consider the following grammar G: E -> E + T | T T -> T F...
Consider the following grammar G: E -> E + T | T T -> T F | F F -> F* | a | b This grammar can be used to generate regular expressions over the alphabet {a,b} with standard precedence rules. Show your solution for each of the following 5 points:     1. Remove left recursion and write the resulting grammar G1.     2. For the grammar G1, compute and write the sets FIRST for every right hand side...
Let G be a connected graph and let e be a cut edge in G. Let...
Let G be a connected graph and let e be a cut edge in G. Let K be the subgraph of G defined by: V(K) = V(G) and E(K) = E(G) - {e} Prove that K has exactly two connected components. First prove that e cannot be a loop. Thus the endpoint set of e is of the form {v,w}, where v ≠ w. If ṽ∈V(K), prove that either there is a path in K from v to ṽ, or...
Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal...
Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal form. Prove that if there exists a word w ∈ L(G) generated by a derivation that uses more than |P| + |AT | steps, then L(G) is infinite.
Problem 3. Let F ⊆ E be a field extension. (i) Suppose α ∈ E is...
Problem 3. Let F ⊆ E be a field extension. (i) Suppose α ∈ E is algebraic of odd degree over F. Prove that F(α) = F(α^2 ). Hints: look at the tower of extensions F ⊆ F(α^2 ) ⊆ F(α) and their degrees. (ii) Let S be a (possibly infinite) subset of E. Assume that every element of S is algebraic over F. Prove that F(S) = F[S]
Consider the following context-free grammar G: E ® T + E ® * T i E...
Consider the following context-free grammar G: E ® T + E ® * T i E ® f i E ® * f + T ® + Questions: (5 points) Compute the Canonical LR(1) Closure set for state I0 for grammar G. (10 points) Compute (draw) the DFA that recognizes the Canonical LR(1) sets of items for grammar G. (5 points) Construct the corresponding Canonical LR(1) parsing table. (10 points) Compute (draw) the DFA for LALR(1). (5 points) Construct LALR(1)...
This question set will use the following scenario that we saw on last week’s homework assignment:...
This question set will use the following scenario that we saw on last week’s homework assignment: Scores on the Wechsler Adult Intelligence Scale- Third Edition (WAIS-III) are nationally standardized to be normally distributed with a mean of 100 and standard deviation of 15. A psychologist has a dataset containing the WAIS-III scores from a random sample of 50 adults who are members of a specific organization. They want to know if there is evidence that the mean WAIS-III score in...
If G = (V, E) is a graph and x ∈ V , let G \...
If G = (V, E) is a graph and x ∈ V , let G \ x be the graph whose vertex set is V \ {x} and whose edges are those edges of G that don’t contain x. Show that every connected finite graph G = (V, E) with at least two vertices has at least two vertices x1, x2 ∈ V such that G \ xi is connected.
#1 We are given the grammar rules A ➝ F B E B ➝ A C...
#1 We are given the grammar rules A ➝ F B E B ➝ A C These rules are only some of the rules of a larger grammar G, but we are not given the remaining rules of G. We are told that A is the start symbol of G and that the following holds: {ε, c, d} ⊆ FIRST(C) {ε, e} ⊆ FIRST(E) {ε, f, g} ⊆ FIRST(F) Recall that end of file is denoted EOF. The symbol ⊆...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT