Convertion of Grammar to Chomsky Normal Form and Greibach Normal Form, Assignments of Discrete Structures and Graph Theory

Solutions for converting given grammars to chomsky normal form and greibach normal form. It includes step-by-step explanations and justifications for each transformation. The document also discusses the elimination of left-recursion and the importance of eliminating recursion on a given non-terminal.

Typology: Assignments

Pre 2010

Uploaded on 02/24/2010

koofers-user-8hw
koofers-user-8hw 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Central Florida
School of Computer Science
COT 4210 Spring 2004
Prof. Rene Peralta
Extra credit HW: answers to selected problems
1. Consider the following grammar over Σ = {a, b}:
SAB;
AAS +Sb +a;
BBS +aA +λ;
Convert the grammar to Chomsky Normal Form (please use rules U
aand Vb). answer: Besides some simpler transformations, we
must remove unallowed λ-productions and chain rules. The general
technique I taught in class is
to remove a given production P, add redundant productions
until Pitself becomes redundant. Then remove P.
First deal with the mixed (terminals and variables) terms using Ua
and Vb:
SAB;
AAS +SV +a;
BBS +U A +λ;
To make Bλredundant, add SAand BS:
SAB +A;
AAS +SV +a;
BBS +U A +S.
To make SAredundant, add SAS +SV +a. Reasoning: when
the rule SAis used in a derivation, the variable Amust at some
point later be substituted for AS or SV or a.
1
pf3
pf4

Partial preview of the text

Download Convertion of Grammar to Chomsky Normal Form and Greibach Normal Form and more Assignments Discrete Structures and Graph Theory in PDF only on Docsity!

University of Central Florida

School of Computer Science

COT 4210 Spring 2004

Prof. Rene Peralta

Extra credit HW: answers to selected problems

  1. Consider the following grammar over Σ = {a, b}:
    • S → AB;
    • A → AS + Sb + a;
    • B → BS + aA + λ;

Convert the grammar to Chomsky Normal Form (please use rules U → a and V → b). answer: Besides some simpler transformations, we must remove unallowed λ-productions and chain rules. The general technique I taught in class is

to remove a given production P , add redundant productions until P itself becomes redundant. Then remove P.

First deal with the mixed (terminals and variables) terms using U → a and V → b:

  • S → AB;
  • A → AS + SV + a;
  • B → BS + U A + λ;

To make B → λ redundant, add S → A and B → S:

  • S → AB + A;
  • A → AS + SV + a;
  • B → BS + U A + S.

To make S → A redundant, add S → AS + SV + a. Reasoning: when the rule S → A is used in a derivation, the variable A must at some point later be substituted for AS or SV or a.

  • S → AB + AS + SV + a;
  • A → AS + SV + a;
  • B → BS + U A + S.

Now we could remove B → S in the same way we removed S → A. Instead, and to show you that there is more than one way to do this, consider the step in a derivation where a new variable B is produced. This can only happen when the production S → AB is used.^1 The only place where B → S can later play a role is in changing this B into an S. So adding the rule A → AS makes B → S redundant. But this rule is already there, so we can simply remove the rule B → S:

  • S → AB + AS + SV + a;
  • A → AS + SV + a;
  • B → BS + U A.

Eliminating recursion on S is simple. The final grammar is

  • S → AB + AT + T V + a;
  • T → AB + AT + T V + a;
  • A → AT + T V + a;
  • B → BT + U A;
  • U → a;
  • V → b.

(^1) Why can we ignore the production B → BS here?

Greibach Normal Form requires expressions on the right-hand side of productions to begin with non-terminals. Simple substitution can be used to obtain

  • S → a + aT ;
  • T → (b + bR)ST + (b + bR)S;
  • A → b + bR;
  • R → (a + aT )R + a + aT.

The text does not allow S in the right-hand side of productions in Greibach Normal Form. However, it was noted in class that there appears to be no good reason for this requirement. So the above is good enough.