CSE 105 THEORY OF COMPUTATION

Similar documents
CSE 105 THEORY OF COMPUTATION

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

ECS 120 Lesson 7 Regular Expressions, Pt. 1

CSE 105 THEORY OF COMPUTATION

Regular Languages and Regular Expressions

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

CSE 105 THEORY OF COMPUTATION

Chapter Seven: Regular Expressions

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

Finite Automata Part Three

Ambiguous Grammars and Compactification

CSE 105 THEORY OF COMPUTATION

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

G52LAC Languages and Computation Lecture 6

Converting a DFA to a Regular Expression JP

(Refer Slide Time: 0:19)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

CIT3130: Theory of Computation. Regular languages

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Lexical Analysis. Chapter 2


Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

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

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.

Languages and Compilers

CSE 105 THEORY OF COMPUTATION

Actually talking about Turing machines this time

Lexical Analysis. Implementation: Finite Automata

Lexical Analysis. Introduction

Lecture 4: Syntax Specification

The Front End. The purpose of the front end is to deal with the input language. Perform a membership test: code source language?

Formal Languages and Automata

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

Lexical Analysis. Lecture 3-4

Lexical Analysis. Lecture 2-4

Course Project 2 Regular Expressions

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

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

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

Decision, Computation and Language

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

Lexical Analysis. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

CMSC 350: COMPILER DESIGN

Finite Automata Part Three

David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain)

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

FAdo: Interactive Tools for Learning Formal Computational Models

Regular Expressions. Regular Expressions. Regular Languages. Specifying Languages. Regular Expressions. Kleene Star Operation

Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

8 ε. Figure 1: An NFA-ǫ

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

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

CSE 431S Scanning. Washington University Spring 2013

Multiple Choice Questions

Compiler Construction

Languages and Finite Automata

COMP Logic for Computer Scientists. Lecture 25

CS 301. Lecture 05 Applications of Regular Languages. Stephen Checkoway. January 31, 2018

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

CSE302: Compiler Design

ECS 120 Lesson 16 Turing Machines, Pt. 2

Lecture 5: Regular Expression and Finite Automata

CS308 Compiler Principles Lexical Analyzer Li Jiang

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Implementation of Lexical Analysis

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

CT32 COMPUTER NETWORKS DEC 2015

Implementation of Lexical Analysis

Final Course Review. Reading: Chapters 1-9

lec3:nondeterministic finite state automata

Learn Smart and Grow with world

CS 310: State Transition Diagrams

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Compiler Construction

Computer Sciences Department

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

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

CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

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

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

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

Automating Construction of Lexers

Context-Free Grammars

LECTURE NOTES THEORY OF COMPUTATION

CSE Lecture 4: Scanning and parsing 28 Jan Nate Nystrom University of Texas at Arlington

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

1 Finite Representations of Languages

6 NFA and Regular Expressions

Finite Automata Part Three

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

LECTURE NOTES THEORY OF COMPUTATION

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

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Transcription:

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

Today's learning goals Sipser Ch 1.2, 1.3 Design NFA recognizing a given language Convert an NFA (with or without spontaneous moves) to a DFA recognizing the same language Decide whether or not a string is described by a given regular expression Design a regular expression to describe a given language Convert between regular expressions and automata

Nondeterministic finite automata "Guess" some stage of input at which switch modes Input M1 M2 "Guess" one of finite list of criteria to meet Input M1 M2 Accept if either (or both) accepts

Acceptance in an NFA

NFA

Simulating NFA with DFA Not quite a closure proof, but Proof: Given name variables for sets, machines assumed to exist. WTS state goal and outline plan. Construction using objects previously defined + new tools working towards goal. Give formal definition and explain. Correctness prove that construction works. Conclusion recap what you've proved.

Simulating NFA with DFA For any language recognized by an NFA, there is a DFA that recognizes this language. Proof: Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Correctness Conclusion

From NFA to DFA Which of the following strings is accepted by this NFA? A. The empty string B. 01 C. 111 D. 0 E. More than one of the above.

Subset construction Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Define M = (Q', Σ, δ',q0', F') with Q' = the power set of Q = { X X is a subset of Q } q0' = { states N can be in before first input symbol read } F' = { } δ' ( ) =

From NFA to DFA Which states can this NFA be in before first input symbol is read? A. q0 B. any state C. q0, q1 D. q0, q4 E. q0, q1, q4

Subset construction Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Define M = (Q', Σ, δ',q0', F') with Q' = the power set of Q = { X X is a subset of Q } q0' = { q0 } U δ((q0, ε)) F' = { } δ' ( ) =

Subset construction Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Define M = (Q', Σ, δ',q0', F') with Q' = the power set of Q = { X X is a subset of Q } q0' = { q0 } U δ((q0, ε)) F' = { guarantee at least one computation is successful } δ' ( ) =

From NFA to DFA What does it mean for a set of states X to guarantee at least one computation is successful? A. X is a subset of F B. X = F C. X F is nonempty D. X is an element of F E. None of the above. U

Subset construction Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Define M = (Q', Σ, δ',q0', F') with Q' = the power set of Q = { X X is a subset of Q } q0' = { q0 } U δ((q0, ε)) F' = { X X is a subset of Q and X F is nonempty } δ' ( (X, x) ) = { } U

Types? Subset construction Given A, a language recognized by N = (Q,Σ,δ,q0,F) a NFA WTS there is some DFA M with L(M) = A Construction Define M = (Q', Σ, δ',q0', F') with Q' = the power set of Q = { X X is a subset of Q } q0' = { q0 } U δ((q0, ε)) F' = { X X is a subset of Q and X F is nonempty } δ' ( (X, x) ) = { q in Q q is in δ(r,x) for some r in X or accessible via spontaneous moves} U

Subset construction warmup examples

Subset construction example

Recap Regular sets of strings i.e., those that aren't too complicated are those that are the language of some DFA, or equivalently, the language of some NFA. If a set of strings can be expressed as the result of complement, union, intersection, concatenation, Kleene star of regular languages, then it itself is regular.

Regular expressions Can all regular languages be expressed as those that are built up from very simple languages using the regular operations?

Inductive application of closure Sipser 1.52 p. 64 R is a regular expression over Σ if Watch out for overloaded symbols! Σ is shorthand for (0 U 1) if Σ = {0,1}, Parentheses may be omitted, R + means RR *, R k means R concatenated with itself k times

Syntax à Languages The language described by a regular expression, L(R): L ( (0 U 1)U1 ) = { } L ( ) = { } L ( ) = { }

L(R) Which of the following strings is not in the language described by A. 00 B. 01 C. 1101 ( ( (00) * (11) ) U 01 ) * D. E. I don't know

L(R) Let L be the language over {a,b} described by the regular expression ((a U Ø) b * ) * Which of the following is not true about L? A. Some strings in L have equal numbers of a's and b's B. L contains the string aaaaaa C. a's never follow b's in any string in L D. L can also be represented by the regular expression (ab * ) * E. More than one of the above.

Regular expressions in practice Compilers: first phase of compiling transforms Strings to Tokens keywords, operators, identifiers, literals One regular expression for each token type Other software tools: grep, Perl, Python, Java, Ruby,

"Regular = regular" Sipser Theorem 1.54 p. 66 Theorem: A language is regular if and only if some regular expression describes it. Lemma 1.55: If a language is described by a regular expression, then it is regular. Lemma 1.60: If a language is regular, then it is described by some regular expression