chomsky normal form cnf i
play

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


  1. 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

  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

  3. Example to convert CFG to CNF I The original CFG S → ASA | aB A → B | S B → b | ǫ September 27, 2020 3 / 10

  4. Example to convert CFG to CNF II Add S 0 → S because the start variable cannot be on the right S 0 → S S → ASA | aB A → B | S B → b | ǫ September 27, 2020 4 / 10

  5. Example to convert CFG to CNF III Remove B → ǫ because ǫ cannot be on the right S 0 → S S → ASA | aB | a A → B | ǫ | S B → b September 27, 2020 5 / 10

  6. Example to convert CFG to CNF IV Remove A → ǫ S 0 → 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

  7. Example to convert CFG to CNF V Remove S → S because the right-hand side cannot be a single variable S 0 → S S → ASA | aB | a | AS | SA A → B | S B → b September 27, 2020 7 / 10

  8. Example to convert CFG to CNF VI Remove S 0 → S S 0 → ASA | aB | a | AS | SA S → ASA | aB | a | AS | SA A → B | S B → b September 27, 2020 8 / 10

  9. Example to convert CFG to CNF VII Remove A → B , A → S S 0 → 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

  10. Example to convert CFG to CNF VIII Finally S 0 → AA 1 | UB | a | AS | SA S → AA 1 | UB | a | AS | SA A → b | AA 1 | UB | a | AS | SA A 1 → SA U → a B → b September 27, 2020 10 / 10

Recommend


More recommend