Pushdown Automata PDAs 1 Pushdown Automaton PDA Input

  • Slides: 77
Download presentation
Pushdown Automata PDAs 1

Pushdown Automata PDAs 1

Pushdown Automaton -- PDA Input String Stack States 2

Pushdown Automaton -- PDA Input String Stack States 2

Initial Stack Symbol Stack bottom special symbol 3

Initial Stack Symbol Stack bottom special symbol 3

The States Input symbol Pop symbol Push symbol 4

The States Input symbol Pop symbol Push symbol 4

input stack top 5

input stack top 5

input stack top 6

input stack top 6

input stack top 7

input stack top 7

input stack top 8

input stack top 8

Non-Determinism 9

Non-Determinism 9

NPDA: Non-Deterministic PDA Example: 10

NPDA: Non-Deterministic PDA Example: 10

Execution Example: Time 0 Input Stack current state 11

Execution Example: Time 0 Input Stack current state 11

Time 1 Input Stack 12

Time 1 Input Stack 12

Time 2 Input Stack 13

Time 2 Input Stack 13

Time 3 Input Stack 14

Time 3 Input Stack 14

Time 4 Input Stack 15

Time 4 Input Stack 15

Time 5 Input Stack 16

Time 5 Input Stack 16

Time 6 Input Stack 17

Time 6 Input Stack 17

Time 7 Input Stack 18

Time 7 Input Stack 18

Time 8 Input Stack accept 19

Time 8 Input Stack accept 19

A string is accepted if: • All the input is consumed • The last

A string is accepted if: • All the input is consumed • The last state is a final state We do not care about the stack contents 20

The input string is accepted by the NPDA: 21

The input string is accepted by the NPDA: 21

In general, is the language accepted by the NPDA: 22

In general, is the language accepted by the NPDA: 22

Another NPDA example NPDA 23

Another NPDA example NPDA 23

24

24

Execution Example: Time 0 Input Stack 25

Execution Example: Time 0 Input Stack 25

Time 1 Input Stack 26

Time 1 Input Stack 26

Time 2 Input Stack 27

Time 2 Input Stack 27

Time 3 Input Stack 28

Time 3 Input Stack 28

Time 4 Input Stack 29

Time 4 Input Stack 29

Time 5 Input Stack 30

Time 5 Input Stack 30

Time 6 Input Stack accept 31

Time 6 Input Stack accept 31

Pushing Strings Input symbol Pop symbol Push string 32

Pushing Strings Input symbol Pop symbol Push string 32

Example: input stack top pushed string 33

Example: input stack top pushed string 33

Another NPDA example NPDA 34

Another NPDA example NPDA 34

35

35

Execution: Time 0 Input Stack current state 36

Execution: Time 0 Input Stack current state 36

Time 1 Input Stack 37

Time 1 Input Stack 37

Time 3 Input Stack 38

Time 3 Input Stack 38

Time 4 Input Stack 39

Time 4 Input Stack 39

Time 5 Input Stack 40

Time 5 Input Stack 40

Time 6 Input Stack 41

Time 6 Input Stack 41

Time 7 Input Stack 42

Time 7 Input Stack 42

Time 8 Input Stack accept 43

Time 8 Input Stack accept 43

Formalities for NPDAs 44

Formalities for NPDAs 44

Transition function: 45

Transition function: 45

Transition function: 46

Transition function: 46

Formal Definition Non-Deterministic Pushdown Automaton NPDA Final states States Input alphabet Stack alphabet Transition

Formal Definition Non-Deterministic Pushdown Automaton NPDA Final states States Input alphabet Stack alphabet Transition function Stack start symbol 47

Instantaneous Description Current state Remaining input Current stack contents 48

Instantaneous Description Current state Remaining input Current stack contents 48

Example: Instantaneous Description Time 4: Input Stack 49

Example: Instantaneous Description Time 4: Input Stack 49

Example: Instantaneous Description Time 5: Input Stack 50

Example: Instantaneous Description Time 5: Input Stack 50

We write: (Time 4) (Time 5) 51

We write: (Time 4) (Time 5) 51

A computation: 52

A computation: 52

For convenience we write: 53

For convenience we write: 53

Formal Definition Language of NPDA Start state : Final state 54

Formal Definition Language of NPDA Start state : Final state 54

Example: thus NPDA : 55

Example: thus NPDA : 55

thus NPDA : 56

thus NPDA : 56

Therefore: NPDA : 57

Therefore: NPDA : 57

Converting Context-Free Grammars to NPDAs 58

Converting Context-Free Grammars to NPDAs 58

An example grammar: What is the equivalent NPDA? 59

An example grammar: What is the equivalent NPDA? 59

Grammar: NPDA: 60

Grammar: NPDA: 60

The NPDA simulates leftmost derivations of the grammar L(grammar) = L(NPDA) 61

The NPDA simulates leftmost derivations of the grammar L(grammar) = L(NPDA) 61

Grammar: A leftmost derivation: 62

Grammar: A leftmost derivation: 62

NPDA execution: Time 0 Input Stack current state 63

NPDA execution: Time 0 Input Stack current state 63

Time 1 Input Stack 64

Time 1 Input Stack 64

Time 2 Input Stack 65

Time 2 Input Stack 65

Time 3 Input Stack 66

Time 3 Input Stack 66

Time 4 Input Stack 67

Time 4 Input Stack 67

Time 5 Input Stack 68

Time 5 Input Stack 68

Time 6 Input Stack 69

Time 6 Input Stack 69

Time 7 Input Stack 70

Time 7 Input Stack 70

Time 8 Input Stack 71

Time 8 Input Stack 71

Time 9 Input Stack 72

Time 9 Input Stack 72

Time 10 Input Stack accept 73

Time 10 Input Stack accept 73

In general: Given any grammar We can construct a NPDA With 74

In general: Given any grammar We can construct a NPDA With 74

Constructing NPDA from grammar : For any production For any terminal 75

Constructing NPDA from grammar : For any production For any terminal 75

Grammar generates string if and only if NPDA accepts 76

Grammar generates string if and only if NPDA accepts 76

Therefore: For any context-free language there is an NPDA that accepts the same language

Therefore: For any context-free language there is an NPDA that accepts the same language 77