CSC 341: February 12, 2007

From CSWiki

Jump to: navigation, search

Previous Lecture Next Lecture

Contents

Instructor's notes for the class session

Ambiguity

Leftmost derivations; the bijection between leftmost derivations and derivation trees

Ambiguity: a property of grammars

Inherent ambiguity. Show that \{\texttt{a}^i \texttt{b}^j \texttt{c}^k \mid i = j \vee j = k\} is inherently ambiguous.

Chomsky normal form

Constraining the form of rules still further.

Theorem 2.9: Every context-free language is generated by some context-free grammar in Chomsky normal form.

The algorithm for reducing a context-free grammar to Chomsky normal form.

  1. Add a new start symbol.
  2. Remove \varepsilon-rules.
  3. Remove unit rules.
  4. Remove rules with three or more symbols on the right-hand side.
  5. Rewrite rules with two terminals or a terminal and a variable on the right-hand side.

As an example, do Exercise 2.14 on page 129 of Sipser's book.

Demonstrate the Chomsky-normal-form module.

Study questions

  1. Why is it necessary to allow the rule S \rightarrow \varepsilon in a grammar in Chomsky normal form? Why is it sufficient to allow the start symbol, and no other, to be nullable?
  2. If a context-free grammar containing the (superfluous) rule A \rightarrow A is put into Chomsky normal form, this rule will be eliminated atstep 3, since it is a unit rule. But doesn't the same step simply reintroduce exactly the same rule again (since it is of the form B \rightarrow u)? Doesn't this lead to an infinite loop?
  3. Prove that, in a grammar in Chomsky normal form, every derivation of a string of terminals has an odd number of steps.

Proposed Solutions

  1. Any production with \varepsilon on its right-hand side can be eliminated (described in Sipser's proof of Theorem 2.9) without affecting the language that the grammar generates. Therefore, it is sufficient to allow the start symbol to be nullable.
  2. This will not lead to an infinite loop because a new production is added only when it is not a duplicate of a unit rule that is previously removed.
  3. Every rule in a CNF grammar either increases the length of the current string by 1 or replaces a variable with a terminal, but not both. To derive a string of positive length k, then, requires k-1 steps that increase the length of the current string and k steps to replace variables with terminals. Hence, the total number of steps are odd. (Taken from Prof. Stone's comments)

Previous Lecture Next Lecture

Front Door

Personal tools