Question

In: Computer Science

Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = {...

Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = { S -> aaSb | aab }.

Construct a NPDA M that such that L(M) = L(G).

I would like the transition graph for this NPDA please.

Solutions

Expert Solution

Given CFG is

G = ( {S}, {a, b}, S, P) where P = { S -> aaSb | aab }

Here {S} are the non terminals

{a,b} are the terminals

S is start symbol

P contains the set of productions or rules

From the productions we get the idea that the language contains set of strings of a and b which even number of a's concatenated with half the number of b's as of a's

L(G)=a2nbn

For constructing a NPDA we can push b's for every 2 a's read and we can construct accept condition using empty stack condition

so, using the abode idea the NPDA formed can be represented by the below diagram

Here the NPDA is represented by

M = ({Q0,Q1,Q2,Q3}, {a,b}, {b,z}, ,Q0, z, Q3)

Where {Q0,Q1,Q2,Q3} are the set of states

{a,b} are the set of terminals

{b,z} are the set of stack alphabets

Q0 is start state

z is the initial stack alphabet

Q3 is the final state

is the transition function given by the following table

a b
Q0 (a,z/z),(a,b/bb)
Q1 (a,z/bz),(a,b/b) (b,b/)
Q2 (b,b/)
Q3 (,z/z) (,z/z)

Where a,z/z means on seeing input a and top of the stack is z then keep the top of the stack as it is

and a,b/bb means on seeing input a and top of the stack is b then push b onto the stack.

b,b/ means we pop the stack on seeing input b and top of the stack is also b.

In the above NPDA we push b onto the stack whenever we read 2 a's and keep popping b's until the stack is empty

Note:if the top of the stack is z then it is considered to be empty


Related Solutions

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.
For a grammar G with the productions where G = ( {S, A, B}, {a, b},...
For a grammar G with the productions where G = ( {S, A, B}, {a, b}, S, P ) with productions                                              S --> AB | bbbB,              A --> b | Ab,       B --> a.. 1.Show that the grammar G is ambiguous. 2.Give language L that is generated by G, L = L(G), in a formal expression (including a regular expression). 3.Can you construct an unambiguous grammar that is equivalent to G? Otherwise, show that G is inherently ambiguous.
Prove that if G is a context-free grammar in which every variable occurs on the left...
Prove that if G is a context-free grammar in which every variable occurs on the left side of at most one production, then G is unambiguous.
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)...
Give a context-free grammar for {w ∈ {b, c}∗| #c(w) = #b(w)}.
Give a context-free grammar for {w ∈ {b, c}∗| #c(w) = #b(w)}.
Given a grammar G, G = (Ν, Σ, Π, S), where Ν = { ... }...
Given a grammar G, G = (Ν, Σ, Π, S), where Ν = { ... } Σ = { ... } Π = { ... } S is ... For a string ... write (a) A leftmost derivation (b) A rightmost derivation
What makes a deterministic context free grammar deterministic?
What makes a deterministic context free grammar deterministic?
Simplify the grammar G. Does L(G) contain ε ? S -> A B C | B...
Simplify the grammar G. Does L(G) contain ε ? S -> A B C | B a B A -> a A | B a C | a a a B -> b B b | a | D C -> C A | A C D -> ε
1. Consider the regular grammar G given below: S → aS|aA|bB|λ A → aA|bS B →...
1. Consider the regular grammar G given below: S → aS|aA|bB|λ A → aA|bS B → bB|aS (a) Give a derivation for the strings aabbba and baaba (b) Give an infinite language L such that L is not a subset of L(G) (c) Give a regular expression that describes the language L(G).
Consider the reaction: 2X(g) + Y (S) --- 2Z (g) + P (g) At equilibrum a...
Consider the reaction: 2X(g) + Y (S) --- 2Z (g) + P (g) At equilibrum a 5 L reaction vessel is found to contain: .20 mol of X, .40 mol of Y, .30 mol of Z, and .25 mol of P. What is the value of equilibrium constant?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT