Chomsky normal form (CNF) I Purpose: a simplified form of grammars - - PowerPoint PPT Presentation

chomsky normal form cnf i
SMART_READER_LITE
LIVE PREVIEW

Chomsky normal form (CNF) I Purpose: a simplified form of grammars - - PowerPoint PPT Presentation

Chomsky normal form (CNF) I Purpose: a simplified form of grammars Every rule must be either A BC or A a B , C are not start variables a so A is not allowed. September 27, 2020 1 / 10 Chomsky normal form (CNF) II


slide-1
SLIDE 1

Chomsky normal form (CNF) I

Purpose: a simplified form of grammars Every rule must be either A → BC

  • r

A → a B, C are not start variables a ∈ Σ so A → ǫ is not allowed.

September 27, 2020 1 / 10

slide-2
SLIDE 2

Chomsky normal form (CNF) II

However, S → ǫ is allowed, where S is the start variable This form is useful later (but not in this chapter) To convert a CFG to a CNF, let’s show an example first

September 27, 2020 2 / 10

slide-3
SLIDE 3

Example to convert CFG to CNF I

The original CFG S → ASA | aB A → B | S B → b | ǫ

September 27, 2020 3 / 10

slide-4
SLIDE 4

Example to convert CFG to CNF II

Add S0 → S because the start variable cannot be on the right S0 → S S → ASA | aB A → B | S B → b | ǫ

September 27, 2020 4 / 10

slide-5
SLIDE 5

Example to convert CFG to CNF III

Remove B → ǫ because ǫ cannot be on the right S0 → S S → ASA | aB|a A → B | ǫ | S B → b

September 27, 2020 5 / 10

slide-6
SLIDE 6

Example to convert CFG to CNF IV

Remove A → ǫ S0 → S S → ASA | aB | a | AS | SA | S A → B | S B → b What if B → ǫ appears again? An infinite loop? We will discuss this issue later

September 27, 2020 6 / 10

slide-7
SLIDE 7

Example to convert CFG to CNF V

Remove S → S because the right-hand side cannot be a single variable S0 → S S → ASA | aB | a | AS | SA A → B | S B → b

September 27, 2020 7 / 10

slide-8
SLIDE 8

Example to convert CFG to CNF VI

Remove S0 → S S0 → ASA | aB | a | AS | SA S → ASA | aB | a | AS | SA A → B | S B → b

September 27, 2020 8 / 10

slide-9
SLIDE 9

Example to convert CFG to CNF VII

Remove A → B, A → S S0 → ASA | aB | a | AS | SA S → ASA | aB | a | AS | SA A → b | ASA | aB | a | AS | SA B → b

September 27, 2020 9 / 10

slide-10
SLIDE 10

Example to convert CFG to CNF VIII

Finally S0 → AA1 | UB | a | AS | SA S → AA1 | UB | a | AS | SA A → b | AA1 | UB | a | AS | SA A1 → SA U → a B → b

September 27, 2020 10 / 10