Pushdown Automata. A PDA is an FA together with a stack.

Similar documents
CSE 105 THEORY OF COMPUTATION

Chapter 14: Pushdown Automata

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

Decidable Problems. We examine the problems for which there is an algorithm.

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ.

Specifying Syntax COMP360

Context Free Languages and Pushdown Automata

Theory of Computations Spring 2016 Practice Final Exam Solutions

1 Parsing (25 pts, 5 each)

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

where is the transition function, Pushdown Automata is the set of accept states. is the start state, and is the set of states, is the input alphabet,

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

LL(1) predictive parsing

A Characterization of the Chomsky Hierarchy by String Turing Machines

Models of Computation II: Grammars and Pushdown Automata

From Theorem 8.5, page 223, we have that the intersection of a context-free language with a regular language is context-free. Therefore, the language

Introduction to Computers & Programming

PDA s. and Formal Languages. Automata Theory CS 573. Outline of equivalence of PDA s and CFG s. (see Theorem 5.3)


Theory Bridge Exam Example Questions Version of June 6, 2008

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

COMP 330 Autumn 2018 McGill University

JNTUWORLD. Code No: R

CS402 - Theory of Automata Glossary By

Multiple Choice Questions

ONE-STACK AUTOMATA AS ACCEPTORS OF CONTEXT-FREE LANGUAGES *

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Nested Words. A model of linear and hierarchical structure in data. Examples of such data

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CT32 COMPUTER NETWORKS DEC 2015

Limits of Computation p.1/?? Limits of Computation p.2/??

QUESTION BANK. Unit 1. Introduction to Finite Automata

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Syntax Analysis Part I

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Introduction to Lexing and Parsing

CS 4120 Introduction to Compilers

LR Parsing. The first L means the input string is processed from left to right.

Theory of Computation, Homework 3 Sample Solution

We can create PDAs with multiple stacks. At each step we look at the current state, the current input symbol, and the top of each stack.

Lecture 2 Finite Automata

Stack Abstract Data Type

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Optimizing Finite Automata

Lexical and Syntax Analysis. Bottom-Up Parsing

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

The Big Picture. Chapter 3

Equivalence of NTMs and TMs

An Interactive Approach to Formal Languages and Automata with JFLAP

UNIT I PART A PART B

CS/B.Tech/CSE/IT/EVEN/SEM-4/CS-402/ ItIauIafIaAblll~AladUnrtel1ity

Computation Engineering Applied Automata Theory and Logic. Ganesh Gopalakrishnan University of Utah. ^J Springer

Computer Sciences Department

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

CS402 - Theory of Automata FAQs By

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Formal Languages and Automata Theory, SS Project (due Week 14)

Limited Automata and Unary Languages

Verification in Loosely Synchronous Queue-Connected Discrete Timed Automata

Lexical Analysis - 2

announcements CSE 311: Foundations of Computing review: regular expressions review: languages---sets of strings

Bottom-Up Parsing II (Different types of Shift-Reduce Conflicts) Lecture 10. Prof. Aiken (Modified by Professor Vijay Ganesh.

CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

CSCI 340: Computational Models. Turing Machines. Department of Computer Science

Languages and Automata

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

Theory and Compiling COMP360

CSCI312 Principles of Programming Languages!

CSE 105 THEORY OF COMPUTATION

t!1; R 0! 1; R q HALT

Ambiguous Grammars and Compactification

CIT3130: Theory of Computation. Regular languages

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

COMP 382: Reasoning about algorithms

Converting a DFA to a Regular Expression JP

Eliminating the Storage Tape in Reachability Constructions

CSE 311 Lecture 21: Context-Free Grammars. Emina Torlak and Kevin Zatloukal

Languages and Compilers

Parsing Scheme (+ (* 2 3) 1) * 1

Properties of Regular Expressions and Finite Automata

Introduction to Parsing. Lecture 8

LL(1) predictive parsing

LL Parsing, LR Parsing, Complexity, and Automata

Bottom-Up Parsing II. Lecture 8

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Bottom-Up Parsing. Lecture 11-12

Outline. Language Hierarchy

Final Course Review. Reading: Chapters 1-9

Fall Compiler Principles Context-free Grammars Refresher. Roman Manevich Ben-Gurion University of the Negev

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

Theory of Programming Languages COMP360

Transcription:

Pushdown Automata A PDA is an FA together with a stack.

Stacks A stack stores information on the last-in firstout principle. Items are added on top by pushing; items are removed from the top by popping. Goddard 7: 2

A Pushdown Automaton A pushdown automaton (PDA) has a fixed set of states (like FA), but it also has one unbounded stack for storage. When symbol is read, depending on (a) state of automaton, (b) symbol on top of stack, and (c) symbol read, the automaton. updates its state, and 2. (optionally) pops or pushes a symbol. The automaton may also pop or push without reading input. Goddard 7: 3

Flowcharts We draw the program of a PDA as a flowchart (we will see FA-like diagram later). This uses: A single start state; A single halt-and-accept state; A reader box: read one symbol from input and based on that update state (as in FA); A pop box: pop one symbol from stack and based on that update state; A push box: add symbol to stack. Goddard 7: 4

Notes There is no explicit reject state: if no legal continuation, then PDA halts and rejects. We use symbol to indicate both the end of input, and the result of popping from an empty stack. Goddard 7: 5

Example: 0 n n Again Consider a PDA for { 0 n n : n > 0 }. uses its stack as counter. The PDA For each 0 read, PDA pushes an x (say). When first read, PDA enters new state. Now, it pops one symbol for each read. If now 0 is read or pop from empty stack, it rejects. PDA accepts if and only if stack becomes empty as the input finishes... Goddard 7: 6

Flowchart for 0 n n Start Push x 0 Accept x Goddard 7: 7

Casualness There are traditional shapes for the different types of functions on flowcharts, but we don t worry about that. Also, ε often requires very special handling: from now on, however, we will simply ignore the empty string. Goddard 7: 8

Balanced Brackets A string of left and right brackets is balanced if (a) reading from left to right, number of left brackets is always at least number of right brackets; and (b) total number of left brackets equals total number of right brackets. For example, (()())() is balanced; (() and )))( are not. Here is CFG: S (S) SS ε Goddard 7: 9

PDA for Balanced Brackets In PDA, each ( is pushed; each ) causes a matching ( to be popped. Start Push ( ( Accept ) ( Goddard 7: 0

Nondeterminism By definition, a PDA is nondeterministic. It accepts the input string if there exists a sequence of actions leading to the accept state. There are two ways to depict nondeterminism in the flowchart: two transitions with the same label, or a transition labeled with ε (which does not consume an input symbol). Goddard 7:

PDA for Palindromes The PDA for palindromes uses nondeterminism to guess the midpoint of the string; and the stack to compare the first and second halves. Here is the PDA for even-length palindromes... Goddard 7: 2

Even-Length Palindromes Start 0 Push 0 Push ε 0 0 Accept Goddard 7: 3

Another Example Consider the language { 0 m n : n m 2n }. Goddard 7: 4

Another Example Consider the language { 0 m n : n m 2n }. The PDA starts by counting the 0 s, say using x. Then matches each with either one or two x s. Start Push x 0 Accept x x Goddard 7: 5

PDA for Equality Here is PDA for all binary strings with equal 0 s and s. The PDA again uses stack as counter. Several approaches. One idea is to pair symbols off, storing the excess on the stack. The following PDA actually stores one less than the excess... Goddard 7: 6

Flowchart for Equality Push 0 Start Push 0 0 0 Accept 0 Goddard 7: 7

Context-Free Languages Theorem. A language is generated by a context-free grammar if and only if it is accepted by a pushdown automaton. We prove this later. Goddard 7: 8

Applications of PDAs: Reverse Polish A compiler converts an arithmetic expression into code that can be evaluated using a stack. For example, might become + 5 (3 + 2) + 4 PUSH() PUSH(5) PUSH(3) PUSH(2) ADD MUL ADD PUSH(4) ADD Goddard 7: 9

Practice. Draw a PDA for the set of all strings of the form 0 a b such that a b. 2. Draw a PDA for the set of all strings of the form 0 a b 0 c such that a + c = b. Goddard 7: 20

Solutions to Practice Start Push x 0 Accept, x x Goddard 7: 2

Start Push x 0 Push y x Accept 0 0 y Goddard 7: 22

Summary A pushdown automaton (PDA) is an FA with a stack added for storage. We choose to draw these as flowcharts where the character indicates both empty stack and end-of-input. A PDA is nondeterministic by definition. Goddard 7: 23