Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

From Context-Free Grammars to Pushdown Automata: Understanding the Process, Slides of Computer Science

How to convert context-free grammars (cfgs) into pushdown automata (pdas), a type of automaton used to recognize the languages defined by cfgs. The process involves recognizing recursive procedures in cfgs and carrying out recursive computations on a stack. The document also provides examples and instructions on how to recognize certain strings using a stack.

Typology: Slides

2012/2013

Uploaded on 04/25/2013

rajnikanth
rajnikanth 🇮🇳

4.3

(32)

101 documents

1 / 45

Toggle sidebar

Related documents


Partial preview of the text

Download From Context-Free Grammars to Pushdown Automata: Understanding the Process and more Slides Computer Science in PDF only on Docsity! 1 Pushdown Stack Automata Docsity.com 2 Agenda Pushdown Automata  Stacks and recursiveness  Formal Definition Docsity.com 19 From CFG’s to Stack Machines A: Palindromes in {a,b,#}* containing exactly one #-symbol. Q: Using a stack, how can we recognize such strings? Docsity.com 20 From CFG’s to Stack Machines A: Use a three phase process: 1. Push mode: Before reading “#”, push everything on the stack. 2. Reading “#” switches modes. 3. Pop mode: Read remaining symbols making sure that each new read symbol is identical to symbol popped from stack. Accept if able to empty stack completely. Otherwise reject, and reject if could not pop somewhere. Docsity.com 21 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? Docsity.com 24 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a a Input: aaab#baa Docsity.com 25 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a a a Input: aaab#baa Docsity.com 26 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? b a a a Input: aaab#baa Docsity.com 29 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a a Input: aaab#baa Docsity.com 30 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a Input: aaab#baa REJECT (nonempty stack) Docsity.com 31 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a a Input: aaab#baaa Docsity.com 34 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? Input: aaab#baaa ACCEPT Docsity.com 35 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a a Input: aaab#baaaa Docsity.com 36 From CFG’s to Stack Machines (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? a Input: aaab#baaaa Docsity.com 39 PDA’s à la Sipser To aid analysis, theoretical stack machines restrict the allowable operations. Each text- book author has his own version. Sipser’s machines are especially simple: Push/Pop rolled into a single operation: replace top stack symbol No intrinsic way to test for empty stack Epsilon’s used to increase functionality, result in default nondeterministic machines. Docsity.com 40 Sipser’s Version Becomes: (1) PUSH (3) POP read a or b ? Push it ACCEPT (2) read # ? (ignore stack) read == peek ? Pop Else: CRASH! empty stack? e , e$ a , ea b , eb #, ee e , $e a , ae b , be Docsity.com 41 Sipser’s Version Meaning of labeling convention: If at p and next input x and top stack y, then go to q and replace y by z on stack. x = e: ignore input, don’t read y = e: ignore top of stack and push z z = e: pop y p q x, y z Docsity.com 44 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be $ Input: aaab#baaa Docsity.com 45 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be a $ Input: aaab#baaa Docsity.com 46 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be a a $ Input: aaab#baaa Docsity.com 49 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be b a a a $ Input: aaab#baaa Docsity.com 50 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be a a a $ Input: aaab#baaa Docsity.com 51 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be a a $ Input: aaab#baaa Docsity.com 54 Sipser’s Version e , e$ a , ea b , eb #, ee e , $e a , ae b , be Input: aaab#baaa ACCEPT! Docsity.com 55 PDA Formal Definition DEF: A pushdown automaton (PDA) is a 6-tuple M = (Q, S, G, d, q0, F ). Q, S, and q0, are the same as for an FA. G is the tape alphabet. d is as follows: So given a state p, an input letter x and a tape letter y, d(p,x,y) gives all (q,z) where q is a target state and z a stack replacement for y. )(Σ:δ εεε GG QPQ Docsity.com 56 PDA Formal Definition Q: What is d(p,x,y) in each case? 1. d(0,a,b) 2. d(0,e,e) 3. d(1,a,e) 4. d(3,e,e) 0 1 2 e , e$ 3 a , ea b , eb b, e$ e , $e a , ae b , be a , e e Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved