Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen - - PowerPoint PPT Presentation

formal languages grammars and automata lecture 6
SMART_READER_LITE
LIVE PREVIEW

Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen - - PowerPoint PPT Presentation

Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen helle@cs.ru.nl http://www.cs.ru.nl/~helle/ Foundations


slide-1
SLIDE 1

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Formal Languages, Grammars and Automata Lecture 6

Helle Hvid Hansen

helle@cs.ru.nl http://www.cs.ru.nl/~helle/

Foundations Group – Intelligent Systems Section Institute for Computing and Information Sciences Radboud University Nijmegen

13 June 2014

Helle Hvid Hansen 13 June 2014 FLGA 1 / 24

slide-2
SLIDE 2

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Overview

Last lecture:

  • Context-free grammars and context-free languages.
  • Regular grammars.
  • CYK-algorithm (parsing: w ∈ L?)

Helle Hvid Hansen 13 June 2014 FLGA 2 / 24

slide-3
SLIDE 3

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Overview

Last lecture:

  • Context-free grammars and context-free languages.
  • Regular grammars.
  • CYK-algorithm (parsing: w ∈ L?)

Today:

  • Pushdown automata (NL: stapelautomaten)
  • Closure properties of context-free languages
  • Beyond context-free languages

Helle Hvid Hansen 13 June 2014 FLGA 2 / 24

slide-4
SLIDE 4

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Automata for Context-Free Languages

Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA-λ regular grammar

Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

slide-5
SLIDE 5

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Automata for Context-Free Languages

Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA-λ regular grammar

  • DFA, NFA, NFA-λ: finite memory (states can encode only

finite amount of information), for example (for Σ = {a, b}),

  • even or odd number of a’s read: two states even, odd
  • the last 2 letters read: four states for aa, ab, ba, bb.

Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

slide-6
SLIDE 6

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Automata for Context-Free Languages

Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA-λ regular grammar

  • DFA, NFA, NFA-λ: finite memory (states can encode only

finite amount of information), for example (for Σ = {a, b}),

  • even or odd number of a’s read: two states even, odd
  • the last 2 letters read: four states for aa, ab, ba, bb.
  • For example: {anbn | n ≥ 0} not regular. We would need to

remember how many a’s we have seen. A DFA with k states can only “count to k”.

Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

slide-7
SLIDE 7

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Automata for Context-Free Languages

Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA-λ regular grammar

  • DFA, NFA, NFA-λ: finite memory (states can encode only

finite amount of information), for example (for Σ = {a, b}),

  • even or odd number of a’s read: two states even, odd
  • the last 2 letters read: four states for aa, ab, ba, bb.
  • For example: {anbn | n ≥ 0} not regular. We would need to

remember how many a’s we have seen. A DFA with k states can only “count to k”. We need some form of unbounded memory.

Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

slide-8
SLIDE 8

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Stack Memory

Stack of data elements (“stapel”) Note:

  • nly top of stack is visible.

Helle Hvid Hansen 13 June 2014 FLGA 4 / 24

slide-9
SLIDE 9

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Stack Memory

Stack of data elements (“stapel”) Note:

  • nly top of stack is visible.

Stack operations: push a new element

  • nto stack

pop the top element from stack Stack is a Last-In-First-Out (LIFO) data structure.

Helle Hvid Hansen 13 June 2014 FLGA 4 / 24

slide-10
SLIDE 10

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Stack Memory: Formal Notation

  • Stack content described as word over a stack alphabet

Γ = {A, B, C, ..., X, Y , ...}. Last-in = Left-most: A B C = ABC

  • The empty stack is λ ∈ Γ∗.

Helle Hvid Hansen 13 June 2014 FLGA 5 / 24

slide-11
SLIDE 11

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Stack Memory: Formal Notation

  • Stack content described as word over a stack alphabet

Γ = {A, B, C, ..., X, Y , ...}. Last-in = Left-most: A B C = ABC

  • The empty stack is λ ∈ Γ∗.
  • Stack operations:

push(X, A B C ) = X A B C pop( A B C ) = B C push(X, ABC) = XABC pop(ABC) = BC

  • Note: The empty stack has no top.

Helle Hvid Hansen 13 June 2014 FLGA 5 / 24

slide-12
SLIDE 12

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton

A pushdown automaton is an NFA-λ equipped with a stack.

Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

slide-13
SLIDE 13

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton

A pushdown automaton is an NFA-λ equipped with a stack.

  • Def. A pushdown automaton (PDA) M = (Q, Σ, Γ, δ, q0, F)

consists of

  • a finite set of (control) states Q
  • an input alphabet Σ
  • an initial state q0 ∈ Q
  • a set of final states F ⊆ Q

Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

slide-14
SLIDE 14

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton

A pushdown automaton is an NFA-λ equipped with a stack.

  • Def. A pushdown automaton (PDA) M = (Q, Σ, Γ, δ, q0, F)

consists of

  • a finite set of (control) states Q
  • an input alphabet Σ
  • an initial state q0 ∈ Q
  • a set of final states F ⊆ Q
  • a stack alphabet Γ
  • a transition function δ: Q × Σλ × Γλ → P(Q × Γλ)

where Σλ = Σ ∪ {λ} and Γλ = Γ ∪ {λ}. That is, for p ∈ Q, a ∈ Σλ, A ∈ Γλ, δ(p, a, A) is a set of pairs (q, B) where q ∈ Q, B ∈ Γλ (nondeterministic).

Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

slide-15
SLIDE 15

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Computation

A computation of a PDA M on input word w:

Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

slide-16
SLIDE 16

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Computation

A computation of a PDA M on input word w:

  • Start configuration (q0, w, λ)

(start in initial state with empty stack)

Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

slide-17
SLIDE 17

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Computation

A computation of a PDA M on input word w:

  • Start configuration (q0, w, λ)

(start in initial state with empty stack)

  • Transitions are taken (nondeterministically) depending on

– the next input symbol (as in DFA, NFA) and – the stack top symbol. (Details next slide.) Changes configuration (p, u, α) → (q, v, β) according to transition function (where p, q ∈ Q, ; u, v ∈ Σ∗, α, β ∈ Γ∗).

Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

slide-18
SLIDE 18

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Computation

A computation of a PDA M on input word w:

  • Start configuration (q0, w, λ)

(start in initial state with empty stack)

  • Transitions are taken (nondeterministically) depending on

– the next input symbol (as in DFA, NFA) and – the stack top symbol. (Details next slide.) Changes configuration (p, u, α) → (q, v, β) according to transition function (where p, q ∈ Q, ; u, v ∈ Σ∗, α, β ∈ Γ∗).

  • Computation is successful if it ends in a configuration

(q, λ, λ) where q ∈ F. (Acceptance by final state and empty stack)

Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

slide-19
SLIDE 19

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions

(q, B) ∈ δ(p, a, A) i.e. p

a, A/B q :

  • can be taken if: next input symbol is a, stack top is A
  • actions: read/consume a, pop A from stack, push B.

Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

slide-20
SLIDE 20

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions

(q, B) ∈ δ(p, a, A) i.e. p

a, A/B q :

  • can be taken if: next input symbol is a, stack top is A
  • actions: read/consume a, pop A from stack, push B.

(q, B) ∈ δ(p, λ, A) i.e. p

λ, A/B q

(input λ-transition):

  • can be taken if: stack top is A (regardless of next input)
  • actions: pop A from stack, push B.

Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

slide-21
SLIDE 21

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions

(q, B) ∈ δ(p, a, A) i.e. p

a, A/B q :

  • can be taken if: next input symbol is a, stack top is A
  • actions: read/consume a, pop A from stack, push B.

(q, B) ∈ δ(p, λ, A) i.e. p

λ, A/B q

(input λ-transition):

  • can be taken if: stack top is A (regardless of next input)
  • actions: pop A from stack, push B.

(q, B) ∈ δ(p, a, λ) i.e. p

a, λ/B q :

  • can be taken if: next input is a (regardless of stack top)
  • actions: read/consume a, push B.

Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

slide-22
SLIDE 22

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions

(q, B) ∈ δ(p, a, A) i.e. p

a, A/B q :

  • can be taken if: next input symbol is a, stack top is A
  • actions: read/consume a, pop A from stack, push B.

(q, B) ∈ δ(p, λ, A) i.e. p

λ, A/B q

(input λ-transition):

  • can be taken if: stack top is A (regardless of next input)
  • actions: pop A from stack, push B.

(q, B) ∈ δ(p, a, λ) i.e. p

a, λ/B q :

  • can be taken if: next input is a (regardless of stack top)
  • actions: read/consume a, push B.

(q, B) ∈ δ(p, λ, λ) i.e. p

λ, λ/B q :

  • can be taken: always (regardless of next input and stack top)
  • actions: push B.

Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

slide-23
SLIDE 23

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions II

Transitions of the form (q, λ) ∈ δ(p, −, −) i.e. p

−, −/λ q :

  • can be taken if: as before.
  • actions: as before, except nothing is pushed onto stack.

Helle Hvid Hansen 13 June 2014 FLGA 9 / 24

slide-24
SLIDE 24

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Pushdown Automaton Transitions II

Transitions of the form (q, λ) ∈ δ(p, −, −) i.e. p

−, −/λ q :

  • can be taken if: as before.
  • actions: as before, except nothing is pushed onto stack.

For example: (q, λ) ∈ δ(p, a, λ) i.e. p

a, λ/λ q

(DFA-transition)

  • can be taken if: next input symbol is a
  • actions: read/consume a.

(q, λ) ∈ δ(p, λ, λ) i.e. p

λ, λ/λ q :

  • Can be taken: always
  • Actions: nothing.

Helle Hvid Hansen 13 June 2014 FLGA 9 / 24

slide-25
SLIDE 25

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Remarks on PDA Transitions

  • Note:

p

a, λ/B q

does NOT mean that the stack must be empty to take the transition.

Helle Hvid Hansen 13 June 2014 FLGA 10 / 24

slide-26
SLIDE 26

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Remarks on PDA Transitions

  • Note:

p

a, λ/B q

does NOT mean that the stack must be empty to take the transition.

  • Note:

p

a, A/λ q

does NOT mean that the stack is empty after the transition.

Helle Hvid Hansen 13 June 2014 FLGA 10 / 24

slide-27
SLIDE 27

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Remarks on PDA Transitions

  • Note:

p

a, λ/B q

does NOT mean that the stack must be empty to take the transition.

  • Note:

p

a, A/λ q

does NOT mean that the stack is empty after the transition.

  • Shorthand notation (multiple push):

p

a,A/BC q

= p

a, A/C p′ λ, λ/B q

Helle Hvid Hansen 13 June 2014 FLGA 10 / 24

slide-28
SLIDE 28

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Language Accepted by a PDA

Let M = (Q, Σ, Γ, δ, q0, F) be a PDA, and let p, q ∈ Q, u, v ∈ Σ∗, α, β ∈ Γ∗. Notation: We write: (p, u, α) ⇒ (q, v, β) if there exists a sequence of transitions that change (p, u, α) into (q, v, β).

Helle Hvid Hansen 13 June 2014 FLGA 11 / 24

slide-29
SLIDE 29

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Language Accepted by a PDA

Let M = (Q, Σ, Γ, δ, q0, F) be a PDA, and let p, q ∈ Q, u, v ∈ Σ∗, α, β ∈ Γ∗. Notation: We write: (p, u, α) ⇒ (q, v, β) if there exists a sequence of transitions that change (p, u, α) into (q, v, β).

  • Def. The language accepted by M is:

L(M) = {w ∈ Σ∗ | (q0, w, λ) ⇒ (q, λ, λ), q ∈ F}.

Helle Hvid Hansen 13 June 2014 FLGA 11 / 24

slide-30
SLIDE 30

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . .

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-31
SLIDE 31

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s.

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-32
SLIDE 32

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-33
SLIDE 33

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-34
SLIDE 34

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-35
SLIDE 35

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-36
SLIDE 36

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-37
SLIDE 37

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-38
SLIDE 38

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-39
SLIDE 39

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-40
SLIDE 40

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-41
SLIDE 41

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-42
SLIDE 42

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-43
SLIDE 43

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-44
SLIDE 44

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-45
SLIDE 45

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)
  • (q0, abb, λ) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-46
SLIDE 46

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)
  • (q0, abb, λ) → (q0, abb, A) →

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-47
SLIDE 47

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)
  • (q0, abb, λ) → (q0, abb, A) → (q1, abb, λ)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-48
SLIDE 48

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)
  • (q0, abb, λ) → (q0, abb, A) → (q1, abb, λ) (STUCK)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-49
SLIDE 49

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 1

L = {anbn | n ≥ 0} ∋ λ, ab, aabb, . . . Idea: count the a’s. Take Σ = {a, b}, Γ = {A} and q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • Example computations:
  • (q0, λ, λ) (SUCCESS)
  • (q0, aabb, λ) → (q0, aabb, A) → (q0, aabb, AA) →

(q1, aabb, A) → (q1, aabbλ, λ) (SUCCESS)

  • (q0, aba, λ) → (q0, aba, A) → (q1, aba, λ) (STUCK)
  • (q0, abb, λ) → (q0, abb, A) → (q1, abb, λ) (STUCK)

Helle Hvid Hansen 13 June 2014 FLGA 12 / 24

slide-50
SLIDE 50

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L?

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-51
SLIDE 51

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR.

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-52
SLIDE 52

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Helle Hvid Hansen

13 June 2014 FLGA 13 / 24

slide-53
SLIDE 53

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-54
SLIDE 54

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-55
SLIDE 55

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-56
SLIDE 56

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-57
SLIDE 57

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) → (q1, abcba, A) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-58
SLIDE 58

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) → (q1, abcba, A) → (q1, abcbaλ, λ) (SUCCESS)

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-59
SLIDE 59

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) → (q1, abcba, A) → (q1, abcbaλ, λ) (SUCCESS)

  • (q0, acb, λ) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-60
SLIDE 60

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) → (q1, abcba, A) → (q1, abcbaλ, λ) (SUCCESS)

  • (q0, acb, λ) → (q0, acb, A) →

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-61
SLIDE 61

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

PDA Example 2

L = {wcwR ∈ {a, b, c}∗ | w ∈ {a, b}∗} ∋ c, abcba, bbcbb. Can we find a PDA that accepts L? Idea: Memorise w-part using the stack, and use it to check for wR. Take: Σ = {a, b, c} and Γ = {A, B}, and Q, δ, F as follows: q0

b,λ/B

  • a,λ/A
  • c,λ/λ q1

b,B/λ

  • a,A/λ
  • Example computations:
  • (q0, abcba, λ) → (q0, abcba, A) → (q0, abcba, BA) →

(q1, abcba, BA) → (q1, abcba, A) → (q1, abcbaλ, λ) (SUCCESS)

  • (q0, acb, λ) → (q0, acb, A) → (q1, acb, A)

(STUCK)

Helle Hvid Hansen 13 June 2014 FLGA 13 / 24

slide-62
SLIDE 62

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and PDAs

Helle Hvid Hansen 13 June 2014 FLGA 14 / 24

slide-63
SLIDE 63

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and PDAs

Last lecture: From regular grammar G to NFA-λ MG. Now: From context-free grammar G to PDA MG. Requires G to be in Greibach normal form.

Helle Hvid Hansen 13 June 2014 FLGA 14 / 24

slide-64
SLIDE 64

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and PDAs

Last lecture: From regular grammar G to NFA-λ MG. Now: From context-free grammar G to PDA MG. Requires G to be in Greibach normal form.

  • Def. A CFG G is in Greibach normal form if all its production

rules are of one of the following forms: A → aA1 · · · An A → a S → λ In leftmost derivation, the prefix of terminals increases in each step. where a ∈ Σ, Ai ∈ V , Ai = S, i = 1, . . . , n.

Helle Hvid Hansen 13 June 2014 FLGA 14 / 24

slide-65
SLIDE 65

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and PDAs

Last lecture: From regular grammar G to NFA-λ MG. Now: From context-free grammar G to PDA MG. Requires G to be in Greibach normal form.

  • Def. A CFG G is in Greibach normal form if all its production

rules are of one of the following forms: A → aA1 · · · An A → a S → λ In leftmost derivation, the prefix of terminals increases in each step. where a ∈ Σ, Ai ∈ V , Ai = S, i = 1, . . . , n. Lemma: Every CFG G can be transformed into an equivalent CFG in Greibach normal form (see e.g. Sudkamp 4.7-4.8).

Helle Hvid Hansen 13 June 2014 FLGA 14 / 24

slide-66
SLIDE 66

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

From Greibach CFG to two-state PDA

Let G = (V , Σ, S, P) be a Greibach CFG. Define M = (Q, Σ, Γ, δ, q0, F0) where Q = {q0, q1}, Γ = V − {S}, F = {q1} and transitions in δ are defined from P by:

Helle Hvid Hansen 13 June 2014 FLGA 15 / 24

slide-67
SLIDE 67

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

From Greibach CFG to two-state PDA

Let G = (V , Σ, S, P) be a Greibach CFG. Define M = (Q, Σ, Γ, δ, q0, F0) where Q = {q0, q1}, Γ = V − {S}, F = {q1} and transitions in δ are defined from P by:

  • S → aw ∈ P

⇒ q0

a, λ/w

q1

  • S → λ ∈ P

⇒ q0

λ, λ/λ

q1

  • A → aw ∈ P

⇒ q1

a, A/w

q1

where a ∈ Σ, A ∈ Γ, w ∈ Γ∗. Example: on blackboard.

Helle Hvid Hansen 13 June 2014 FLGA 15 / 24

slide-68
SLIDE 68

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and Pushdown Automata

Theorem: L is context-free ⇐ ⇒ L is accepted by some PDA.

  • Proof. (⇒): Use previous construction.

(⇐): Ingenious, but more involved, see Sudkamp 7.3.

Helle Hvid Hansen 13 June 2014 FLGA 16 / 24

slide-69
SLIDE 69

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Context-Free Languages and Pushdown Automata

Theorem: L is context-free ⇐ ⇒ L is accepted by some PDA.

  • Proof. (⇒): Use previous construction.

(⇐): Ingenious, but more involved, see Sudkamp 7.3. Language class Syntax/Grammar Automata Context-free context-free grammar PDA Regular regular expressions, DFA, NFA, NFA-λ regular grammar

Helle Hvid Hansen 13 June 2014 FLGA 16 / 24

slide-70
SLIDE 70

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Variations on PDAs

  • Acceptance criteria:
  • Acceptance by final state and empty stack (our def.)
  • Acceptance by final state (only)
  • Acceptance by empty stack (only)

All are equivalent (accept same class of languages).

Helle Hvid Hansen 13 June 2014 FLGA 17 / 24

slide-71
SLIDE 71

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Variations on PDAs

  • Acceptance criteria:
  • Acceptance by final state and empty stack (our def.)
  • Acceptance by final state (only)
  • Acceptance by empty stack (only)

All are equivalent (accept same class of languages).

  • A PDA is deterministic if for any combination of state, input

symbol and stack top, there is at most one transition possible.

Helle Hvid Hansen 13 June 2014 FLGA 17 / 24

slide-72
SLIDE 72

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Variations on PDAs

  • Acceptance criteria:
  • Acceptance by final state and empty stack (our def.)
  • Acceptance by final state (only)
  • Acceptance by empty stack (only)

All are equivalent (accept same class of languages).

  • A PDA is deterministic if for any combination of state, input

symbol and stack top, there is at most one transition possible. q0

a, λ/A

  • b, A/λ q1

b, A/λ

  • q0

b, λ/B

  • a, λ/A
  • λ, λ/λ q1

b, B/λ

  • a, A/λ
  • deterministic

nondeterministic (guess middle of string)

Helle Hvid Hansen 13 June 2014 FLGA 17 / 24

slide-73
SLIDE 73

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Deterministic Context-Free Languages

  • Def. A language is called deterministic context-free if there exists

a deterministic PDA M with L = L(M). Examples of deterministic CFLs:

  • {anbn | n ≥ 0}
  • {wcwR | w ∈ {a, b}∗}

Helle Hvid Hansen 13 June 2014 FLGA 18 / 24

slide-74
SLIDE 74

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Deterministic Context-Free Languages

  • Def. A language is called deterministic context-free if there exists

a deterministic PDA M with L = L(M). Examples of deterministic CFLs:

  • {anbn | n ≥ 0}
  • {wcwR | w ∈ {a, b}∗}

Examples of CFLS that are not deterministic:

  • {wwR | w ∈ {a, b}∗}
  • {w ∈ {a, b}∗ | w = wr, |w|} (palindromes)

Helle Hvid Hansen 13 June 2014 FLGA 18 / 24

slide-75
SLIDE 75

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Deterministic Context-Free Languages

  • Def. A language is called deterministic context-free if there exists

a deterministic PDA M with L = L(M). Examples of deterministic CFLs:

  • {anbn | n ≥ 0}
  • {wcwR | w ∈ {a, b}∗}

Examples of CFLS that are not deterministic:

  • {wwR | w ∈ {a, b}∗}
  • {w ∈ {a, b}∗ | w = wr, |w|} (palindromes)

Note: L is deterministic CFL ⇒ L is unambiguous, but there are unambiguous CFLs that are not deterministic (e.g., palindromes).

Helle Hvid Hansen 13 June 2014 FLGA 18 / 24

slide-76
SLIDE 76

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Beyond Context-Free Languages

Examples of languages that are not context-free:

  • {anbncn | n ≥ 0}
  • {anbmanbm | n, m ≥ 0}
  • {w ∈ {a, b}∗ | |w| is prime number}

(Prove using pumping lemma for CFLs, Sudkamp 7.4)

Helle Hvid Hansen 13 June 2014 FLGA 19 / 24

slide-77
SLIDE 77

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-78
SLIDE 78

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-79
SLIDE 79

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-80
SLIDE 80

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S:

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-81
SLIDE 81

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S: union: S → S1 | S2,

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-82
SLIDE 82

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S: union: S → S1 | S2, concatenation: S → S1S2

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-83
SLIDE 83

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S: union: S → S1 | S2, concatenation: S → S1S2 star: S → S1S | λ,

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-84
SLIDE 84

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S: union: S → S1 | S2, concatenation: S → S1S2 star: S → S1S | λ, reversal: (exercise)

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-85
SLIDE 85

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Closure Properties of Context-Free Languages

If L1 and L2 are context-free languages, then so are:

  • L1 ∪ L2 (union),
  • L1L2 (concatenation),
  • L∗

1 (star),

  • LR

1 (reversal)

but, in general, NOT

  • L1 (complement) or
  • L1 ∩ L2 (intersection).

Let S1 and S2 be start symbols in grammars G1 and G2. Make new grammar with start symbol S: union: S → S1 | S2, concatenation: S → S1S2 star: S → S1S | λ, reversal: (exercise)

  • Determ. CFLs are closed under complement, but NOT under union.

Helle Hvid Hansen 13 June 2014 FLGA 20 / 24

slide-86
SLIDE 86

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Questions about Context-Free Languages

Decidable (general algorithm exists)

  • Given any CFG G and w ∈ Σ∗, is w ∈ L(G)?

(CYK-algorithm or build PDA).

  • Given PDA M, is L(M) = ∅?
  • Given PDA M, is L(M) finite?
  • Given any CFG G, is L(G) regular?

Undecidable (no general algorithm exists)

  • Given any CFG G, is L(G) = Σ∗?
  • Given any CFGs G1 and G2, is L(G1) = L(G2)?
  • Given any CFG G, is L(G) deterministic?
  • Given any CFG G, is it ambiguous?

Helle Hvid Hansen 13 June 2014 FLGA 21 / 24

slide-87
SLIDE 87

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Chomsky Hierarchy

Languages Grammars Automata Recursively phrase-structure, Turing machines enumerable unrestricted Context-sensitive context-sensitive Linear bounded (natural lang.) grammar Turing machine Context-free context-free (nondet.) PDA (program.lang.) grammar Regular regular grammar DFA, NFA, NFA-λ

Helle Hvid Hansen 13 June 2014 FLGA 22 / 24

slide-88
SLIDE 88

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Chomsky Hierarchy

Languages Grammars Automata Recursively phrase-structure, Turing machines enumerable unrestricted Context-sensitive context-sensitive Linear bounded (natural lang.) grammar Turing machine Context-free context-free (nondet.) PDA (program.lang.) grammar Regular regular grammar DFA, NFA, NFA-λ – Noam Chomsky, born 1928, American linguist.

Helle Hvid Hansen 13 June 2014 FLGA 22 / 24

slide-89
SLIDE 89

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Chomsky Hierarchy

Languages Grammars Automata Recursively phrase-structure, Turing machines enumerable unrestricted Context-sensitive context-sensitive Linear bounded (natural lang.) grammar Turing machine Context-free context-free (nondet.) PDA (program.lang.) grammar Regular regular grammar DFA, NFA, NFA-λ – Noam Chomsky, born 1928, American linguist. – Sheila Adele Greibach, born 1939, American computer scientist.

Helle Hvid Hansen 13 June 2014 FLGA 22 / 24

slide-90
SLIDE 90

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Chomsky Hierarchy

Languages Grammars Automata Recursively phrase-structure, Turing machines enumerable unrestricted Context-sensitive context-sensitive Linear bounded (natural lang.) grammar Turing machine Context-free context-free (nondet.) PDA (program.lang.) grammar Regular regular grammar DFA, NFA, NFA-λ – Noam Chomsky, born 1928, American linguist. – Sheila Adele Greibach, born 1939, American computer scientist. Learning more: “Berekenbaarheid” (NWI-IBC003) (Informatica BSc vak, 3ec)

Helle Hvid Hansen 13 June 2014 FLGA 22 / 24

slide-91
SLIDE 91

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Summary

Formal Languages Grammars (generators) Automata (acceptors)

Helle Hvid Hansen 13 June 2014 FLGA 23 / 24

slide-92
SLIDE 92

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Summary

Formal Languages Grammars (generators) Automata (acceptors)

  • Context-free grammars generate context-free languages.
  • All regular languages are context-free, but not vice versa.
  • Context-free languages are accepted by PDAs.
  • PDAs cannot be determinised (no subset construction)

Helle Hvid Hansen 13 June 2014 FLGA 23 / 24

slide-93
SLIDE 93

Introduction Pushdown Automata CFLs and PDAs Closure Properties and Concluding Remarks

Radboud University Nijmegen

Next (last) lecture

  • Wrapping up the course.
  • Solutions to the midterm test (online later today).
  • Examp preparation.
  • Question hour.

Remember to register for the exam in Osiris!

Helle Hvid Hansen 13 June 2014 FLGA 24 / 24