Week 8 Lecture 1 - Simplifying Grammars and Chomsky and Greibach Normal Forms

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

When is a non-terminal A nullable?

if 𝐴 ⇒* 𝜆

2
New cards

In the production, B → CAD, A is nullable.

Therefore, in a derivation, A may or may not derive 𝜆

How is this fixed?

Making 2 versions of the production:

B → CAD
B → CD

Then we can forget A derives 𝜆

3
New cards

What is the algorithm for elimination of 𝜆-productions

  1. First compute the nullable symbols:
    Basic: Productions of the form 𝐴 → 𝜆 tells us that A is nullable.
    Induction: Given a production B → C1C2…Ck, if every Ci is nullable, then B is nullable.

  2. Delete all 𝜆-productions

  3. For each production 𝐴 → 𝑋1𝑋2 … 𝑋𝑘 with k ≥ 1, replace the new productions, where the nullable Xi’s in all possible combinations are present or absent.
    → If m of one of the Xi’s are nullable, then the production will be replaced by 2^m productions.
    Exception! If all symbols are nullable, then we would exclude the case where all Xi’s are absent (would give 𝐴 → 𝜆)

4
New cards

Consider the CFG:

S → AB
A → aAA | λ
B → bBB | λ

Remove the nullable symbols (A, B and S)

  • 𝑆 → 𝐴𝐵 becomes 𝑆 → 𝐴𝐵 | 𝐴 | 𝐵

  • 𝐴 → 𝑎𝐴𝐴 becomes 𝐴 → 𝑎𝐴𝐴 | 𝑎𝐴 | 𝑎

  • 𝐵 → 𝑏𝐵𝐵 becomes 𝐵 → 𝑏𝐵𝐵 | 𝑏𝐵| 𝑏

  • Hence, the new 𝜆-production free grammar: 𝑆 → 𝐴𝐵 | 𝐴 | 𝐵 𝐴 → 𝑎𝐴𝐴 | 𝑎𝐴 | 𝑎 𝐵 → 𝑏𝐵𝐵 | 𝑏𝐵 | 𝑏

5
New cards

What are unit pairs?

  1. Find all unit pairs of the original grammar

  2. Construct a set of productions: for all unit pairs (A,B), add all the productions A → a, where B → a is a production of the original grammar but not a unit production

6
New cards

When are symbols generating and reachable?

A symbol X is generating if there is a derivation X ⇒* w for some terminal string w.

A symbol X is reachable if there is a derivation S ⇒* 𝛼X𝛽 for some 𝛼 and 𝛽

7
New cards

Useless and Useful symbols

A symbol is useful if it is both generating and reachable, otherwise it is useless.

8
New cards

Consider the grammar:

S → AB | a
A → b

What symbol is not generating?

→ b. If we eliminate B, we must eliminate S → AB:

S → a
A → b

9
New cards

In

S → a
A → b

What symbol isn’t reachable?

A → b

eliminate to leave only S → a

10
New cards

Algorithm for eliminating useless symbols

  1. Compute generating symbols:
    Basis: Every terminal is generating
    Induction: Given a production A → a, if every symbol in a is generating, then A is too generating.

  2. Eliminate all productions involving non-generating symbols.

  3. Compute reachable symbols:

  4. Basis: S is reachable
    Induction: Suppose that non-terminal A is reachable. Then for every production A → a, every symbol in a is also reachable.

  5. Eliminate all productions involving symbols that are not reachable

11
New cards

What is normal form used for?

Simplifying CFGs.

This makes it easier to prove facts about CFLs, since we know their grammar can be made to conform to the restrictions of this normal form.

12
New cards

When is a CFG said to be in Chomsky Normal Form?

If every production is of the form:

A → BC (non-terminal on the left hand side, generating 2 terminals)

A → a (non-terminal generating exactly 1 terminal)

13
New cards

What is the safe order to execute the methods to reach CNF?

  1. Eliminate λ-productions

  2. Eliminate unit productions

  3. Eliminate useless symbols

And then ensure that the productions are of the form A → BC or A → a

14
New cards

Ensuring CNF when there are more than 2 non-terminals on one side

knowt flashcard image
15
New cards

What is greibach normal form?

All rules are of the form

A → aA1A2…An

where a is a single non-terminal and aA1A2…An is 0 or more non-terminals

16
New cards

Derivations with Greibach Normal Form

The right-hand side of each production begins with a single terminal.

This means that a string of length n will be derived by a grammar in Greibach Normal Form using exactly n derivations - the i’th derivation will result in the terminal at the i’th position in the string being generated.

A parse tree for a string of length n will have a maximum depth of n.