Question

In: Computer Science

Find Consider the following context-free grammar G: S --> T#T T --> C A --> aA...

Find Consider the following context-free grammar G:
S --> T#T
T --> C
A --> aA | epsilon
B --> bB | epsilon
C --> cC
C --> c
a) Give the set of unproductive symbols in G?
b) Give an equivalent grammar without useless symbols.

Solutions

Expert Solution

Given grammar G:

S --> T#T
T --> C
A --> aA | epsilon
B --> bB | epsilon
C --> cC
C --> c

Question a) Give the set of unproductive symbols in G?

Answer: Unproductive symbols in a grammar are the symbols that cannot be generated by any means from the start symbol. It is similar to useless symbols. It is also said that a symbol is productive if the right hand side of its production rule contains productive symbols. In the given grammar, non-terminal A and B is not present in the right hand side of any of the rules except they can generate themselves only. Thus, A and B are not productive symbols, i.e. they cannot be used to generate any string in the given grammar. Also, only non-terminals can be unproductive only.

Thus, the set of unproductive symbols in G is: {A, B}

Question b) Give an equivalent grammar without useless symbols.

Answer: In a grammar, a symbol is called useless if it does not appear in the Right hand side of any production rule of the grammar, that can be reached from the start symbol. In other words, the useless symbols does not contribute in production of any string.

In the given grammar, the start symbol is S. Which generates non-terminal T and non-terminal T generates non-terminal C. Non-terminal C can recusrively generates itself. Thus, non-terminals A and B are unreachable from the start symbol S. Thus, A and B are useless symbols.

Now, the grammar containing any production rule(s) from these useless symbols can be removed without any issue, since they does not contribute in any production. So, the production rules, A --> aA | epsilon and B --> bB | epsilon has to be removed.

The revised grammar without any useless symbols:

S --> T#T
T --> C
C --> cC
C --> c


NOTE: The two production rules from C can be merged into a single one, which will reduce the number of rules but maintaining the grammar unchanged. The grammar is given below:

S --> T#T
T --> C
C --> cC | c


Related Solutions

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.
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)...
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.
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 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...
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.
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)}.
Let G be any context-free grammar. Show that the number of strings that have a derivation...
Let G be any context-free grammar. Show that the number of strings that have a derivation in G of length n or less, for any n > 0, is finite. Could you please answer with clear explanation. The question is from Elaine Rich's Automata, Computability and Complexity Chapter 11 Exercise 14.
For each of the following grammars, first classify the grammar as Regular, Linear, Context-Free or Context-Sensitive,...
For each of the following grammars, first classify the grammar as Regular, Linear, Context-Free or Context-Sensitive, and then precisely describe the language generated by the grammar. (1) S → aRa R → aR | bR | є (2) S → A | B A → aaaA | є B → Bbb | b (3) S → RbR R → aRb | bRa | RR | bR | є (4)   S → aSbSaS | aSaSbS | bSaSaS | є    (5)...
What makes a deterministic context free grammar deterministic?
What makes a deterministic context free grammar deterministic?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT