Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Similar documents
Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Pushdown Automata (Pre Lecture)

Harvard CS 121 and CSCI E-207 Lecture 9: Regular Languages Wrap-Up, Context-Free Grammars

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

CSE 105 THEORY OF COMPUTATION

Context-Free Languages

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

CISC4090: Theory of Computation

CSE 105 THEORY OF COMPUTATION

Foundations of Informatics: a Bridging Course

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Introduction to Theory of Computing

CPS 220 Theory of Computation Pushdown Automata (PDA)

Introduction to Formal Languages, Automata and Computability p.1/42

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Intro to Theory of Computation

Pushdown Automata: Introduction (2)

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Theory of Computation (IV) Yijia Chen Fudan University

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Computability and Complexity

Accept or reject. Stack

Computational Models - Lecture 5 1

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

5 Context-Free Languages

CPS 220 Theory of Computation

Computational Models - Lecture 4

CS Pushdown Automata

(pp ) PDAs and CFGs (Sec. 2.2)

Einführung in die Computerlinguistik

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Homework Assignment 6 Answers

Pushdown Automata (2015/11/23)

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

Pushdown Automata (PDA) The structure and the content of the lecture is based on

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

CSE 105 THEORY OF COMPUTATION

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

Automata Theory (2A) Young Won Lim 5/31/18

COM364 Automata Theory Lecture Note 2 - Nondeterminism

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

(pp ) PDAs and CFGs (Sec. 2.2)

PUSHDOWN AUTOMATA (PDA)

Push-down Automata = FA + Stack

Pushdown Automata. Chapter 12

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Final exam study sheet for CS3719 Turing machines and decidability.

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Computational Models - Lecture 4 1

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

Please give details of your answer. A direct answer without explanation is not counted.

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

MA/CSSE 474 Theory of Computation

Pushdown Automata. Reading: Chapter 6

Computational Models: Class 5

Theory of Computation Turing Machine and Pushdown Automata

Variants of Turing Machine (intro)

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Automata and Computability. Solutions to Exercises

Undecidable Problems and Reducibility

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Theory of Computation

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Part I: Definitions and Properties

Automata and Computability. Solutions to Exercises

Automata Theory - Quiz II (Solutions)

Theory of Computation

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

CS375: Logic and Theory of Computing

UNIT-VI PUSHDOWN AUTOMATA

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Fundamentele Informatica II

ECS 120 Lesson 15 Turing Machines, Pt. 1

Mildly Context-Sensitive Grammar Formalisms: Embedded Push-Down Automata

Lecture 17: Language Recognition

Lecture 3: Nondeterministic Finite Automata

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Section 1 (closed-book) Total points 30

Theory of Computation (VI) Yijia Chen Fudan University

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

Introduction and Motivation. Introduction and Motivation. Introduction to Computability. Introduction and Motivation. Theory. Lecture5: Context Free

Computability and Complexity

CS21 Decidability and Tractability

Lecture III CONTEXT FREE LANGUAGES

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

CISC 4090 Theory of Computation

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

CSE 105 THEORY OF COMPUTATION

Introduction to Computers & Programming

Computability Theory

Solution Scoring: SD Reg exp.: a(a

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

Transcription:

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Salil Vadhan October 4, 2012 Reading: Sipser, 2.2.

Another example of a CFG (with proof) L = {x {a, b} : x has the same # of a s and b s}. 1

More examples of CFGs Arithmetic Expressions G 1 : E x y E E E + E (E) G 2 : E T E + T T T F F F (E) x y Q: Which is preferable? Why? 2

Parse Trees Derivations in a CFG can be represented by parse trees. Examples: Each parse tree corresponds to many derivations, but has unique leftmost derivation. 3

Parsing Parsing: Given x L(G), produce a parse tree for x. (Used to interpret x. Compilers parse, rather than merely recognize, so they can assign semantics to expressions in the source language.) Ambiguity: A grammar is ambiguous if some string has two parse trees. Example: 4

Context-free Grammars and Automata What is the fourth term in the analogy: Regular Languages : Finite Automata as Context-free Languages :??? 5

Regular Grammars Regular Grammars Hint: Hint: There There areisa aspecial kind kind of CFGs, of CFGs, the the regular regular grammars, grammars, that gene languages. that generate exactly the regular languages. A CFG A CFG is (right-)regular is (right-)regular if any if anyoccurrence of of a anonterminal on onthe R rightmost the RHS symbol. of a rule is as the rightmost symbol. DFA Turning Regular a DFA Grammar into an equivalent Regular Grammar Variables are states. Variables are states. Transition δ(p, σ) = R P σ R becomes becomes P P σr σr If is accepting, add rule ε If P is accepting, add rule P ε Example: {x : x has an even # of a s and an even # of b s} Other Direction: Omitted. 6

Regular Grammars (cont.) Example of DFA Regular Grammars: {x : x has an even # of a s and an even # of b s}. Other Direction: Omitted. 7

Context-free Grammars and Automata What is the fourth term in the analogy: Regular Languages : Finite Automata as Context-free Languages :??? 8

Sheila Greibach, AB Radcliffe 60 summa cum laude Inverses of Phrase Structure Generators Harvard PhD Thesis, 1963 9

Pushdown Automata Pushdown Automata Finite automaton + pushdown store = Finite automaton + pushdown store The pushdown store is a stack of symbols of unlimited size which the machine can read and alter only at the top. The pushdown store is a stack of symbols of unlimited size which the machine can read and alter only at the top. Input a b b a b a reading head (L to R only, one symbol at a time, or stays put) F.C. pushdown store head can push (add symbols) or pop (remove and check symbols) a d c b b Stack Transitions of PDA are of form (q, σ, γ) (q, γ ), which means: If in state q with σ on the input tape and γ on top of the stack, replace γ by γ on the stack and enter state q while advancing Transitions of PDA are of form (q, σ, γ) (q, γ ) If in state q with σ on the input tape and γ on top of the stack, replace γ by γ on the stack and enter the state reading q while head advancing over theσ. reading head over σ. 10

(Nondeterministic) PDA for even palindromes {ww R : w {a, b} } (q, a, ε) (q, a) (q, b, ε) (q, b) (q, ε, ε) (r, ε) (r, a, a) (r, ε) (r, b, b) (r, ε) Push a s and b s switch to other state pop a s matching input pop b s matching input So the precondition (q, σ, γ) means that the next σ symbols (0 or 1) of the input are σ and the top γ symbols (0 or 1) on the stack are γ 11

(Nondeterministic) PDA for even palindromes {ww R : w {a, b} } (q, a, ε) (q, a) (q, b, ε) (q, b) (q, ε, ε) (r, ε) (r, a, a) (r, ε) (r, b, b) (r, ε) Push a s and b s switch to other state pop a s matching input pop b s matching input Need to test whether stack empty: push $ at beginning and check at end. (q 0, ε, ε) (q, $) (r, ε, $) (q f, ε) 12

Language recognition with PDAs A PDA accepts an input string If there is a computation that starts in the start state with reading head at the beginning of string and the stack is empty and ends in a final state with all the input consumed A PDA computation becomes blocked (i.e. dies ) if no transition matches both the input and stack 13

Formal Definition of a PDA M = (Q, Σ, Γ, δ, q 0, F ) Q = states Σ = input alphabet Γ = stack alphabet δ = transition function Q (Σ {ε}) (Γ {ε}) P (Q (Γ {ε})). q 0 = start state F = final states 14

Computation by a PDA M accepts w if we can write w = w 1 w m, where each w i Σ {ε}, and there is a sequence of states r 0,..., r m and stack strings s 0,..., s m Γ that satisfy 1. r 0 = q 0 and s 0 = ε. 2. For each i, (r i+1, γ ) δ(r i, w i+1, γ) where s i = γt and s i+1 = γ t for some γ, γ Γ {ε} and t Γ. 3. r m F. L(M) = {w Σ : M accepts w}. 15

PDA for {w {a, b} : # a (w) = # b (w)} 16