Equivalence with context-free grammars I Language context free - - PowerPoint PPT Presentation

equivalence with context free grammars i
SMART_READER_LITE
LIVE PREVIEW

Equivalence with context-free grammars I Language context free - - PowerPoint PPT Presentation

Equivalence with context-free grammars I Language context free recognized by pushdown automata For the left-hand side, recall that by definition a language is context-free if it is constructed by some CFG For the proof, one direction is


slide-1
SLIDE 1

Equivalence with context-free grammars I

Language context free ⇔ recognized by pushdown automata For the left-hand side, recall that by definition a language is context-free if it is constructed by some CFG For the proof, one direction is easier, while the other is harder As usual, we do the easier one first

October 12, 2020 1 / 7

slide-2
SLIDE 2

CFL → PDA I

Given a CFG, we find a PDA to simulate this grammar Two keys: stack nondeterminism: different substitutions We do the proof by an example Suppose we are given the following CFG S → aTb | b T → Ta | ǫ

October 12, 2020 2 / 7

slide-3
SLIDE 3

CFL → PDA II

Idea: for rule substitution, push right-hand side to stack For example, aTb is pushed to stack in a reversed way A PDA can be as follows

October 12, 2020 3 / 7

slide-4
SLIDE 4

CFL → PDA III

qs qloop qa ǫ, ǫ → $ ǫ, ǫ → S ǫ, $ → ǫ ǫ, S → b ǫ, T → ǫ a, a → ǫ b, b → ǫ ǫ, S → b ǫ, ǫ → T ǫ, ǫ → a ǫ, T → a ǫ, ǫ → T

October 12, 2020 4 / 7

slide-5
SLIDE 5

CFL → PDA IV

Consider an example sequence aaaab

October 12, 2020 5 / 7

slide-6
SLIDE 6

CFL → PDA V

qstart

ǫ

→ qloop, {S, $}

ǫ

→ q1, {b, $}

ǫ

→ q2, {T, b, $}

ǫ

→ qloop, {a, T, b, $}

a

→ qloop, {T, b, $}

ǫ

→ q3, {a, b, $}

ǫ

→ qloop, {T, a, b, $}

ǫ

→ q3, {a, a, b, $}

ǫ

→ qloop, {T, a, a, b, $}

ǫ

→ q3, {a, a, a, b, $}

ǫ

→ qloop, {T, a, a, a, b, $}

ǫ

→ qloop, {a, a, a, b, $}

a

→ qloop, {a, a, b, $}

a

→ qloop, {a, b, $}

a

→ qloop, {b, $}

b

→ qloop, {$}

ǫ

→ qaccept

October 12, 2020 6 / 7

slide-7
SLIDE 7

CFL → PDA VI

Even with a non-deterministic setting, we ensure that only strings generated by this CFG can be accepted by the PDA

1

A string is accepted only if all characters are processed

2

We have $ to ensure that the stack is empty in the end

October 12, 2020 7 / 7