Finite Automata CPSC 388 Ellen Walker Hiram College.

Slides:



Advertisements
Similar presentations
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Advertisements

CSE 311 Foundations of Computing I
4b Lexical analysis Finite Automata
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Compiler Construction
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Introduction to Computability Theory
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
REGULAR LANGUAGES.
2. Scanning College of Information and Communications Prof. Heejin Park.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Regular Expressions Fundamental Data Structures and Algorithms Peter Lee March 13, 2003.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Theory of Computation Automata Theory Dr. Ayman Srour.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Deterministic Finite Automata Nondeterministic Finite Automata.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lexical analysis Finite Automata
Non Deterministic Automata
Two issues in lexical analysis
Chapter 2 FINITE AUTOMATA.
Non-Deterministic Finite Automata
Principles of Computing – UFCFA3-30-1
Non-Deterministic Finite Automata
Non Deterministic Automata
4b Lexical analysis Finite Automata
CSCI 2670 Introduction to Theory of Computing
4b Lexical analysis Finite Automata
Non Deterministic Automata
Presentation transcript:

Finite Automata CPSC 388 Ellen Walker Hiram College

Machine Model of Computation Strings in the language are accepted Strings not in the language are rejected

Deterministic Finite Automaton Accepts strings with an odd number of 1’s (e.g. 1011, , 10, 01110)

Parts of a DFA An alphabet (  ) A finite set of states (S) A deterministic set of transitions from one state to the next (T : S x  S) One start state (s 0  S) One or more accepting states (A  S)

Deterministic Transition Table

Testing some strings 1001reject 0101reject 10101accept 0reject 1accept accept

Results

Data for DFA in C++ Class State{ Public: string name; int index; // unique integer bool isFinal; //true if final state } State start; State next [MAXSTATES][MAXCHARS];

Implementing DFA in C++ //Construct all the states, set isFinal //Create next array from transitions int machine(istream &sin){ //sin.get() reads a single character from sin for(State S=start; c=sin.get(); S=next[S.index][c]); //Action for S would go here... return S.isFinal; }

What Language is This?

Draw DFA for: {aa, ab, bb} (ab)* (a+ab+aab)*b All strings with 1 a and 2 b’s All strings containing ab All strings that don’t contain ab All strings that don’t contain abc

Deterministic vs. Non-Deterministic Deterministic: exactly one new state for a given state,character pair Non-deterministic: 0 or more new states for each state,character pair –Assume machine will always make the right choice! –Add  -transitions (move w/o symbol)

NFA: All strings containing “ab”

Are NFA’s More Powerful? Yes if... –There is at least one language that can be accepted by an NFA but no DFA No if … –For every NFA, we can make a DFA that accepts the same language

From NFA to DFA Each DFA state corresponds to a set of states in the NFA –DFA has max 2 n states if NFA has n states (still finite) Transition from {s1,s2} on a is union of transitions from s1 on a and s2 on a

Conversion Algorithm Copy the transitions from the start state. Choose one of the “new state” sets. Create a new row for that set, and construct its transitions (by unioning transitions from original table) Repeat until every set in the table has a row

Example: DFA for (a|b)*ab(a|b)* Initial NFA table Copy start state, create transition for {s1,s2}

Final NFA

Minimizing DFA If 2 states have different isFinal, they are different If 2 states have transitions on the same character to states that are known different, they are different Otherwise, the states are the same and can be merged (repeat until all different)

Minimization Example s1 != {s1,s3} s1 != {s1,s2,s3} (final) s1 != {s1,s2} (transition on b) {s1,s2} != {s1,s3} {s1,s2} != {s1,s2,s3} (final) We cannot say {s1,s3} != {s1,s2,s3}, so merge!

Why minimize? Implement machine with smaller table Compare two machines –If both are minimized, if both compute the same language, then the machines will be identical except for state names

DFA and Regular Expression The set of languages accepted by DFA’s = the set of languages accepted by regular expressions –For every r.e. we can make a DFA that accepts the same language –For every DFA we can make a r.e. that accepts the same language

For every r.e. there is a DFA... If we can construct an NFA, that’s good enough Prove by induction: –Base cases: , , a (element of  ) -- build an NFA for each. –Step cases: r | s, rs, r* -- build resulting NFA from NFA’s from r and/or s