Formal Languages PushDown Automata PDAs Pushdown Automaton PDA

  • Slides: 93
Download presentation
Formal Languages Push-Down Automata (PDAs)

Formal Languages Push-Down Automata (PDAs)

Pushdown Automaton -- PDA Input String Stack States 2

Pushdown Automaton -- PDA Input String Stack States 2

Initial Stack Symbol Stack stack head top bottom special symbol Appears at time 0

Initial Stack Symbol Stack stack head top bottom special symbol Appears at time 0 3

The States Input symbol Pop symbol Push symbol 4

The States Input symbol Pop symbol Push symbol 4

input stack top Replace 5

input stack top Replace 5

input stack top Push 6

input stack top Push 6

input stack top Pop 7

input stack top Pop 7

input stack top No Change 8

input stack top No Change 8

Empty Stack input stack top Pop empty The automaton HALTS No possible transition after

Empty Stack input stack top Pop empty The automaton HALTS No possible transition after 9

A Possible Transition input stack top Pop 10

A Possible Transition input stack top Pop 10

Non-Determinism PDAs are non-deterministic Allow non-deterministic transitions 11

Non-Determinism PDAs are non-deterministic Allow non-deterministic transitions 11

Example PDA: Basic Idea? PDA 12

Example PDA: Basic Idea? PDA 12

Basic Idea: 1. Push the a’s on the stack 2. Match the b’s on

Basic Idea: 1. Push the a’s on the stack 2. Match the b’s on input with a’s on stack 3. Match found 13

Execution Example: Time 0 Input Stack current state 14

Execution Example: Time 0 Input Stack current state 14

Time 1 Input Stack 15

Time 1 Input Stack 15

Time 2 Input Stack 16

Time 2 Input Stack 16

Time 3 Input Stack 17

Time 3 Input Stack 17

Time 4 Input Stack 18

Time 4 Input Stack 18

Time 5 Input Stack 19

Time 5 Input Stack 19

Time 6 Input Stack 20

Time 6 Input Stack 20

Time 7 Input Stack 21

Time 7 Input Stack 21

Time 8 Input Stack accept 22

Time 8 Input Stack accept 22

A string is accepted if there is a computation such that: All the input

A string is accepted if there is a computation such that: All the input is consumed AND The last state is an accepting state At the end of the computation, we do not care about the stack contents (the stack can be empty at the last state) 23

The input string is accepted by the PDA: 24

The input string is accepted by the PDA: 24

In general, is the language accepted by the PDA: 25

In general, is the language accepted by the PDA: 25

Rejection Example: Time 0 Input Stack current state 26

Rejection Example: Time 0 Input Stack current state 26

Rejection Example: Time 1 Input Stack current state 27

Rejection Example: Time 1 Input Stack current state 27

Rejection Example: Time 2 Input Stack current state 28

Rejection Example: Time 2 Input Stack current state 28

Rejection Example: Time 3 Input Stack current state 29

Rejection Example: Time 3 Input Stack current state 29

Rejection Example: Time 4 Input Stack current state 30

Rejection Example: Time 4 Input Stack current state 30

Rejection Example: Time 4 Input reject Stack current state 31

Rejection Example: Time 4 Input reject Stack current state 31

The input string is rejected by the PDA: 32

The input string is rejected by the PDA: 32

A string is rejected if there is no computation such that: All the input

A string is rejected if there is no computation such that: All the input is consumed AND The last state is an accept state At the end of the computation, we do not care about the stack contents 33

Another PDA example: Language? PDA 34

Another PDA example: Language? PDA 34

Another PDA example PDA 35

Another PDA example PDA 35

Basic Idea: 1. Push v on stack 2. Guess middle of input 3. Match

Basic Idea: 1. Push v on stack 2. Guess middle of input 3. Match on input with v on stack 4. Match found 36

Execution Example: Time 0 Input Stack 37

Execution Example: Time 0 Input Stack 37

Time 1 Input Stack 38

Time 1 Input Stack 38

Time 2 Input Stack 39

Time 2 Input Stack 39

Time 3 Input Guess the middle of string Stack 40

Time 3 Input Guess the middle of string Stack 40

Time 4 Input Stack 41

Time 4 Input Stack 41

Time 5 Input Stack 42

Time 5 Input Stack 42

Time 6 Input Stack accept 43

Time 6 Input Stack accept 43

Rejection Example: Time 0 Input Stack 44

Rejection Example: Time 0 Input Stack 44

Time 1 Input Stack 45

Time 1 Input Stack 45

Time 2 Input Stack 46

Time 2 Input Stack 46

Time 3 Input Guess the middle of string Stack 47

Time 3 Input Guess the middle of string Stack 47

Time 4 Input Stack 48

Time 4 Input Stack 48

Input Time 5 There is no possible transition. Input is not consumed Stack 49

Input Time 5 There is no possible transition. Input is not consumed Stack 49

Another computation on same string: Input Time 0 Stack 50

Another computation on same string: Input Time 0 Stack 50

Time 1 Input Stack 51

Time 1 Input Stack 51

Time 2 Input Stack 52

Time 2 Input Stack 52

Time 3 Input Stack 53

Time 3 Input Stack 53

Time 4 Input Stack 54

Time 4 Input Stack 54

Time 5 Input No final state is reached Stack 55

Time 5 Input No final state is reached Stack 55

There is no computation that accepts string 56

There is no computation that accepts string 56

Another PDA example: Language? PDA 57

Another PDA example: Language? PDA 57

Another PDA example PDA 58

Another PDA example PDA 58

Execution Example: Time 0 Input Stack 59

Execution Example: Time 0 Input Stack 59

Time 1 Input Stack 60

Time 1 Input Stack 60

Time 2 Input Stack 61

Time 2 Input Stack 61

Time 3 Input Stack accept 62

Time 3 Input Stack accept 62

Rejection example: Time 0 Input Stack 63

Rejection example: Time 0 Input Stack 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 Halt and Reject 67

Time 4 Input Stack Halt and Reject 67

Pushing Strings Input symbol Pop symbol Push string 68

Pushing Strings Input symbol Pop symbol Push string 68

Example: input stack top pushed string Push 69

Example: input stack top pushed string Push 69

Another PDA example: Language? PDA 70

Another PDA example: Language? PDA 70

Another PDA example PDA 71

Another PDA example PDA 71

Execution Example: Time 0 Input Stack current state 72

Execution Example: Time 0 Input Stack current state 72

Time 1 Input Stack 73

Time 1 Input Stack 73

Time 3 Input Stack 74

Time 3 Input Stack 74

Time 4 Input Stack 75

Time 4 Input Stack 75

Time 5 Input Stack 76

Time 5 Input Stack 76

Time 6 Input Stack 77

Time 6 Input Stack 77

Time 7 Input Stack 78

Time 7 Input Stack 78

Time 8 Input Stack accept 79

Time 8 Input Stack accept 79

PDAs: Formal Definition 80

PDAs: Formal Definition 80

Transition function: 81

Transition function: 81

Transition function: 82

Transition function: 82

Formal Definition Pushdown Automaton (PDA) States Input alphabet Transition Initial Stack function state alphabet

Formal Definition Pushdown Automaton (PDA) States Input alphabet Transition Initial Stack function state alphabet Final states Stack start symbol 83

Instantaneous Description Current state Remaining input Current stack contents 84

Instantaneous Description Current state Remaining input Current stack contents 84

Example: Instantaneous Description Time 4: Input Stack 85

Example: Instantaneous Description Time 4: Input Stack 85

Example: Instantaneous Description Time 5: Input Stack 86

Example: Instantaneous Description Time 5: Input Stack 86

We write: Time 4 Time 5 87

We write: Time 4 Time 5 87

A computation: 88

A computation: 88

For convenience we write: 89

For convenience we write: 89

Formal Definition Language of PDA Initial state : Final state 90

Formal Definition Language of PDA Initial state : Final state 90

Example: PDA : 91

Example: PDA : 91

PDA : 92

PDA : 92

Therefore: PDA : 93

Therefore: PDA : 93