CSE 105 THEORY OF COMPUTATION

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

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

CSE 105 THEORY OF COMPUTATION

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

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

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 ǫ.

CSE 105 THEORY OF COMPUTATION

Theory of Computations Spring 2016 Practice Final Exam Solutions

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

CSE 105 THEORY OF COMPUTATION

Lexical Analysis. Lecture 3-4

CS402 - Theory of Automata Glossary By

Models of Computation II: Grammars and Pushdown Automata

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

Introduction to Computers & Programming

A Characterization of the Chomsky Hierarchy by String Turing Machines

Lexical Analysis. Lecture 2-4

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

Course Project 2 Regular Expressions

JNTUWORLD. Code No: R

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

Multiple Choice Questions

Lexical Analysis. Implementation: Finite Automata

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

Lexical Analysis. Chapter 2

Converting a DFA to a Regular Expression JP

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

Decision Properties for Context-free Languages

CS 310: State Transition Diagrams

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

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


Introduction to Lexing and Parsing

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Actually talking about Turing machines this time

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

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

Review: Shift-Reduce Parsing. Bottom-up parsing uses two actions: Bottom-Up Parsing II. Shift ABC xyz ABCx yz. Lecture 8. Reduce Cbxy ijk CbA ijk

ECS 120 Lesson 16 Turing Machines, Pt. 2

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Context Free Languages and Pushdown Automata

CS 4120 Introduction to Compilers

1 Parsing (25 pts, 5 each)

COMP 330 Autumn 2018 McGill University

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

CS52 - Assignment 10

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,

CISC 4090 Theory of Computation

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

CT32 COMPUTER NETWORKS DEC 2015

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

Chapter 14: Pushdown Automata

Answer All Questions. All Questions Carry Equal Marks. Time: 20 Min. Marks: 10.

Syntax Analysis Part I

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

Behaviour Diagrams UML

Finite Automata Part Three

Lexical Analysis. Prof. James L. Frankel Harvard University

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

Implementation of Lexical Analysis

Computer Sciences Department

lec3:nondeterministic finite state automata

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

Context-Free Grammars

Theory Bridge Exam Example Questions Version of June 6, 2008

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

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

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.

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

Lexical and Syntax Analysis. Bottom-Up Parsing

14.1 Encoding for different models of computation

CSE 431S Scanning. Washington University Spring 2013

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Theory of Programming Languages COMP360

Theory of Computations Spring 2016 Practice Final

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

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

Recursively Enumerable Languages, Turing Machines, and Decidability

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

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Bottom-Up Parsing II. Lecture 8

The Big Picture. Chapter 3

CS2 Language Processing note 3

Introduction to Bottom-Up Parsing

Lexical Analysis - 2

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

CS 314 Principles of Programming Languages. Lecture 3

UNIT I PART A PART B

SLR parsers. LR(0) items

6 NFA and Regular Expressions

ECS 120 Lesson 7 Regular Expressions, Pt. 1

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

Compiler course. Chapter 3 Lexical Analysis

ANIMATING THE CONVERSION OF NONDETERMINISTIC FINITE STATE AUTOMATA TO DETERMINISTIC FINITE STATE AUTOMATA. William Patrick Merryman

CS402 - Theory of Automata FAQs By

1.0 Languages, Expressions, Automata

Specifying Syntax COMP360

Transcription:

CSE 105 THEORY OF COMPUTATION Spring 2018 http://cseweb.ucsd.edu/classes/sp18/cse105-ab/

Today's learning goals Sipser Section 2.2 Define push-down automata informally and formally Trace the computation of a push-down automaton Describe the language recognized by a push-down automaton

Regular sets: not the end of the story Many nice / simple / important sets are not regular Limitation of the finite-state automaton model Can't "count" Can only remember finitely far into the past Can't backtrack Must make decisions in "real-time" We know computers are more powerful than this model Which conditions should we relax?

The next model of computation Idea: allow some memory of unbounded size How? Generalization of regular expressions Context-free grammars Generalization for (D or N)FA Pushdown Automata

Push-down automaton Sipser p. 111 NFA + stack

Push-down automaton Sipser p. 111 NFA + stack At each step 1. Transition to new state based on current state, letter read, and top letter of stack. 2. (Possibly) push or pop a letter to (or from) top of stack

Push-down automaton Sipser p. 111 NFA + stack Accept a string iff there is some sequence of states and some sequence of stack contents which processes the entire input string and ends in an accepting state.

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b c means "read an a from the input, pop b from the stack, push c to the stack." In JFLAP use ; instead of

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b c means "read an a from the input, pop b from the stack, push c to the stack." What edge label would indicate "Read a 0, don't pop anything from stack, don t push anything to the stack"? A. 0, ε ε B. ε, 0 ε C. ε, ε 0 D. ε ε, 0 E. I don't know.

Without reading any input, push a $ to the stack While we read 0s, push each one to stack (to keep count) When we read a 1, match it with one of the 0s in stack For each 1 we read, match it to a 0 that was on the stack. L(M) = If have reached the end of the input and the stack is empty (only $ remains), then #0s = #1s and the machine accepts the string.

Formal definition of PDA Sipser Def 2.13 p. 113

Formal definition What is Σ and what is Γ for this PDA? A. Σ = Γ = {0, 1} B. Σ = {0, 1}, Γ = {$, ε} C. Σ = {0, 1}, Γ = {$, 0} D. Σ = {0, 1, ε}, Γ = {$, 0, 1, ε} E. None of the above.

Informal description Describe operation of PDA - covering all possible input strings, - specifying changes to stack along computation, - without naming states or giving formal definition of transition function

Informal description Ex: Read symbols from the input. As each 0 is read, push it onto the stack. As soon as 1s are seen, pop a 0 off the stack for each 1 read. If the stack becomes empty and there is exactly one 1 left to read, read that 1 and accept the input. If the stack becomes empty and there are either zero or more than one 1s left to read, or if the 1s are finished while the stack still contains 0s, or if any 0s appear in the input following 1s, reject the input.

Designing a PDA Informal description of PDA: Read symbols from the input. As each 0 is read, push it onto the stack. As soon as 1s are seen, pop a 0 off the stack for each 1 read. If the stack becomes empty and there is exactly one 1 left to read, read that 1 and accept the input. If the stack becomes empty and there are either zero or more than one 1s left to read, or if the 1s are finished while the stack still contains 0s, or if any 0s appear in the input following 1s, reject the input. L = { 0 i 1 i+1 i 0 }

L = { 0 i 1 i+1 i 0 } How would you change this state diagram to build PDA recognizing L?

Designing/Tracing a PDA L = { 0 i 1 i+1 i 0 } Sample computations? - nondeterminism - stack contents

Example L = { a i b j c k i=j or i=k, with i,j,k 0 } Which of the following strings are not in L? A. b B. abc C. abbcc D. aabcc E. I don't know.

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } Informal description of PDA: How would you design an algorithm that, given a string, decides if it is in this set? - What information do you need to track? - How much memory do you need? - Are you using non-determinism?

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } Informal description of PDA: The PDA pushes a $ to indicate the top of the stack, then starts reading a's, pushing each one on to the stack. The PDA guesses when it's reached the end of the a's and whether to match the number of a's to the number of b's or the number of c's. If trying to match number of b's with number of a's: PDA pops off a's for each b read. If there are more a's on the stack but no more b's being read, reject. When the end of the stack ($) is reached, the number of a's matches the number of b's. If this is the end of the input or if any number of c's is read at this point, accept; otherwise, reject. If trying to match the number of c's with number of a's: first read any number of b's without changing stack contents and then nondeterministically guess when to start reading c's. For each c read, pop one a off the stack. When the end of the stack ($) is reached the number of a's and c's so far match.

Designing a PDA L = { a i b j c k i=j or i=k, with i,j,k 0 } State diagram of PDA:

For next time Work on Indiv HW3 due Tuesday Pre class-reading for Monday: Examples 2.16, 2.18