Fundamentele Informatica 1 (I&E) najaar 2011 - - PowerPoint PPT Presentation

fundamentele informatica 1 i e
SMART_READER_LITE
LIVE PREVIEW

Fundamentele Informatica 1 (I&E) najaar 2011 - - PowerPoint PPT Presentation

Fundamentele Informatica 1 (I&E) najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 9, 21 november 2011 4. Context-Free Languages 4.5. Simplified Forms and Normal Forms 5. Pushdown Automata


slide-1
SLIDE 1

Fundamentele Informatica 1 (I&E)

najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 9, 21 november 2011

  • 4. Context-Free Languages

4.5. Simplified Forms and Normal Forms

  • 5. Pushdown Automata

5.1. Definitions and Examples

1

slide-2
SLIDE 2

4.5. Simplified Forms and Normal Forms

2

slide-3
SLIDE 3

Definition 4.13. Regular Grammars. A context-free grammar G = (V, Σ, S, P) is regular if every production is of the form A → σB

  • r

A → Λ, where A, B ∈ V and σ ∈ Σ.

3

slide-4
SLIDE 4

Definition 4.29. Chomsky Normal Form A context-free grammar is said to be in Chomsky normal form if every production is of one of these two types: A → BC (where B and C are variables) A → σ (were σ is a terminal symbol)

4

slide-5
SLIDE 5

Exercise. For each grammar G below, try to find a grammar G′ in Chomsky normal form which generates the same language.

  • a. S → TB

T → aTb | ab B → bB | b

  • b. S → aSb | B

B → bB | b

  • c. S → aSb | aBb

B → bB | Λ

  • d. S → aSb | B

B → bB | Λ

5

slide-6
SLIDE 6

Theorem 4.30 For every context-free grammar G, there is another CFG G1 in Chomsky normal form such that L(G1) = L(G) − {Λ}. The proof of this result does not have to be known for the exam. What if Λ / ∈ L(G) ?

6

slide-7
SLIDE 7
  • reg. languages
  • reg. grammar

FA

  • reg. expression
  • cf. languages
  • cf. grammar

PDA

7

slide-8
SLIDE 8
  • 5. Pushdown Automata

8

slide-9
SLIDE 9

just like FA, PDA accepts strings / language just like FA, PDA has states just like FA, PDA reads input one letter at a time unlike FA, PDA has auxiliary memory: a stack unlike FA, by default PDA is nondeterministic unlike FA, by default Λ-transitions are allowed in PDA

9

slide-10
SLIDE 10

Stack in PDA contains symbols from certain alphabet. Usual stack operations: pop, top, push Extra possiblity: replace top element X by string α α = Λ pop α = X top α = Y X push α = βX push∗ α = . . . Top element X is required to do a move!

10

slide-11
SLIDE 11

Example 5.3. A PDA Accepting the Language AnBn

11

slide-12
SLIDE 12

Definition 5.1. A Pushdown Automaton A pushdown automaton (PDA) is a 7-tuple M = (Q, Σ, Γ, q0, Z0, A, δ), where Q is a finite set of states. Σ and Γ are finite sets, the input and stack alphabet. q0, the initial state, is an element of Q. Z0, the initial stack symbol, is an element of Γ. A, the set of accepting states, is a subset of Q. δ, the transition function, is a function from . . . to . . .

12

slide-13
SLIDE 13

Definition 5.1. A Pushdown Automaton A pushdown automaton (PDA) is a 7-tuple M = (Q, Σ, Γ, q0, Z0, A, δ), where Q is a finite set of states. Σ and Γ are finite sets, the input and stack alphabet. q0, the initial state, is an element of Q. Z0, the initial stack symbol, is an element of Γ. A, the set of accepting states, is a subset of Q. δ, the transition function, is a function from Q × (Σ∪{Λ}) × Γ to the set of finite subsets of Q × Γ∗. In principle, Z0 may be removed from the stack, but often it isn’t.

13

slide-14
SLIDE 14

Example 5.3. A PDA Accepting the Language AnBn

14

slide-15
SLIDE 15

Notation: configuration (q, x, α) (p, x, α) ⊢M (q, y, β) (p, x, α) ⊢n

M (q, y, β)

(p, x, α) ⊢∗

M (q, y, β)

(p, x, α) ⊢ (q, y, β) (p, x, α) ⊢n (q, y, β) (p, x, α) ⊢∗ (q, y, β)

15

slide-16
SLIDE 16

Definition 5.2. Acceptance by a PDA If M = (Q, Σ, Γ, q0, Z0, A, δ) and x ∈ Σ∗, the string x is accepted by M if (q0, x, Z0) ⊢∗

M (q, Λ, α)

for some α ∈ Γ∗ and some q ∈ A. A language L ⊆ Σ∗ is said to be accepted by M, if L is precisely the set of strings accepted by M; in this case, we write L = L(M). Sometimes a string accepted by M, or a language accepted by M, is said to be accepted by final state.

16

slide-17
SLIDE 17

Example 5.3. PDAs Accepting the Languages AnBn and SimplePal

17

slide-18
SLIDE 18

Example 5.7. A Pushdown Automaton Accepting Pal

18

slide-19
SLIDE 19

Exercise 5.4. Consider the PDA in Table 5.8, and for each of the following languages over {a, b}∗, modify it to obtain a PDA accepting the language.

  • a. The language of even-length palindromes.
  • b. The language of odd-length palindromes.

19

slide-20
SLIDE 20

Exercise 5.5. Give transition diagrams for PDAs accepting each of the follow- ing languages.

  • a. The language of all odd-length strings over {a, b} with middle

symbol a.

  • b. {anx | n ≥ 0, x ∈ {a, b}∗ and |x| ≤ n}.
  • c. {aibjck | i, j, k ≥ 0 and j = i or j = k}.

20

slide-21
SLIDE 21

Exercise 5.6. In both cases below (on the whiteboard), a transition diagram is given for a PDA with intial state q0 and accepting state q2. Describe in each case the language that is accepted. (first case treated)

21

slide-22
SLIDE 22

Exercise 5.10. Show that every regular language can be accepted by a (deterministic) PDA M with only two states in which there are no Λ-transitions and no symbols are ever removed from the stack.

22