Deterministic Finite Automata

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Lecture 16 Deterministic Turing Machine (DTM) Finite Control tape head.
YES-NO machines Finite State Automata as language recognizers.
Lexical Analysis - Scanner Computer Science Rensselaer Polytechnic Compiler Design Lecture 2.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
CS5371 Theory of Computation
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
1 Languages and Finite Automata or how to talk to machines...
Turing Machines.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Topics Automata Theory Grammars and Languages Complexities
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Lecture 3 Graph Representation for Regular Expressions
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
Finite-State Machines with No Output
CMPS 3223 Theory of Computation
Deterministic Finite State Machines Chapter 5. Languages and Machines 2.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Fall 2006Costas Busch - RPI1 Deterministic Finite Automaton (DFA) Input Tape “Accept” or “Reject” String Finite Automaton Output.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Languages Given an alphabet , we can make a word or string by concatenating the letters of . Concatenation of “x” and “y” is “xy” Typical example: 
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
Finite Automata – Definition and Examples Lecture 6 Section 1.1 Mon, Sep 3, 2007.
Deterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.2)
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Introduction to Turing Machines
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Department of Software & Media Technology
Theory of Languages and Automata By: Mojtaba Khezrian.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
Introduction to Automata Theory Theory of Computation Lecture 3 Tasneem Ghnaimat.
Finite Automata.
CS314 – Section 5 Recitation 2
Finite automate.
Foundations of Computing Science
Languages.
Lexical analysis Finite Automata
Lecture2 Regular Language
Push-down Automata Section 3.3 Wed, Oct 27, 2004.
Push-down Automata.
Deterministic Finite Automata
Finite Automata & Regular Languages
An Introduction to Finite Automata
Hierarchy of languages
Deterministic Finite Automata And Regular Languages Prof. Busch - LSU.
Chapter Two: Finite Automata
Nondeterministic Finite Automata
Principles of Computing – UFCFA3-30-1
Introduction to Finite Automata
Finite Automata.
4b Lexical analysis Finite Automata
Chapter Five: Nondeterministic Finite Automata
Deterministic Finite Automaton (DFA)
4b Lexical analysis Finite Automata
Chapter 1 Regular Language
Presentation transcript:

Deterministic Finite Automata Section 2.1 Mon, Sep 19, 2005

Intuitive View of an Automaton An automaton is a machine that has an input tape and can be put into any of several states. A string of symbols is written on the tape before execution. The automaton begins by reading the symbols on the tape, from left to right. Upon reading a symbol from the tape, the machine (possibly) changes state and advances the tape. After reading the last symbol, the machine halts. The last state tells the result of the processing (accept or reject).

More Precise View of an Automaton Divide the states into two groups: final (accepting) an nonfinal (rejecting). Begin in the designated start state. Upon reading a symbol on the tape, make a transition to the appropriate state.

Transition Diagrams In a transition diagram, Each state is represented by a circle. Each final state is represented by a circle within a circle. Transitions are represented by arrows from one state to another state. Transitions are labeled with an input symbol. Final states are indicated by a circle within a circle. The following diagram represents the transition from state p to state q upon reading the symbol a. p q a

Example of an Automaton Describe an automaton that reports whether the input string begins with a 0. Describe an automaton that reports whether the input string ends with a 0. Describe an automaton that would read the input tape and report whether the tape contained an even number or an odd number of symbols. Describe an automaton that would read a binary string and report whether the string contained an even number of 0s and an odd number of 1s.

Some Special DFAs Let  = {0, 1}. Design a DFA that accepts no string. Design a DFA that accepts every string. Design a DFA that accepts only strings of length 1. Design a DFA that accepts only strings of length 2. Design a DFA that accepts only the empty string.

Definition of a Deterministic Finite Automaton A deterministic finite automaton (DFA) is a quintuple (K, , , s, F) where K is a finite set of states.  is a finite input alphabet. s  K is the initial (start) state. F  K is the set of final states.  is the transition function from K   to K, i.e.,   K    K.

The Functioning of a DFA The DFA begins in the initial state s. Upon reading an input symbol, the DFA changes state according to the rule expressed by the transition function . After reading the last symbol on the tape, the DFA halts. The input is accepted if the final state is in F. Otherwise, the input is rejected.

Configurations Given a DFA M, a configuration is a pair (q, w) where q is the current state of M and w is the remainder of the input string. Given configuration (q, w), if the next transition produces the configuration (q, w), then we say that (q, w) yields (q, w) in one step. That is, w = aw' for some a   and there is a transition (q, a) = q'. This is denoted (q, w) M (q, w).

Configurations The configuration (q, w) yields the configuration (q, w) if there is a sequence of configurations (q1, w1), (q2, w2), …, (qn, wn) such that (qi, wi) yields (qi + 1, wi + 1) in one step, for i = 1, …, n – 1, and (q1, w1) = (q, w) and (qn, wn) = (q, w). This is denoted (q, w) M* (q, w). The relation M* is the reflexive, transitive closure of the relation M.

The Language of a DFA The string w is accepted by M if (s, w) M* (q, e) for some state q  F. The language of a DFA M, denoted L(M), is L(M) = {w  * | M accepts w} or L(M) = {w  * |  q  F, (s, w) M* (q, e)}.

Examples of DFAs Let  = {0, 1}. Design a DFA whose language is the set of all strings containing 00. Design a DFA whose language is the set of all strings containing 00 or 11. Design a DFA whose language is the set of all strings that do not contain 00. Design a DFA whose language is the set of all strings that contain 00, but not 11.

C++ Tokens: Identifiers A C++ identifier is a string of letters, digits, and underscores that begins with a letter. Design a DFA that will accept C++ identifiers.

C++ Tokens: Integers A C++ integer may be expressed in decimal, octal, or hexadecimal. In each base, the integer may begin with an optional + or – sign and end with an optional L or l. Decimal One or more decimal digits (0 – 9), first digit nonzero. Octal An initial 0, followed by one or more octal digits (0 – 7). Hexadecimal An initial 0x, followed by one or more hexadecimal digits (0 – 9, a – f, A – F).

C++ Tokens: Integers Design a DFA that accepts C++ integers.

C++ Tokens: Floating-Point Numbers A C++ floating-point number consists of the following. The mantissa A + or – sign, followed by zero or more digits, followed by a decimal point, followed by zero or more digits. The exponent An e or E, followed by a + or – sign, followed by one or more digits. The final F or f.

C++ Tokens: Floating-Point Numbers The mantissa and exponent + or – signs are optional. (-1.23, 1.23e-4) Digits before the decimal point are optional, provided there is at least one digit after the decimal point, and vice versa. (.123 and 123.) The decimal point, the exponential part, and the final F are optional, provided at least one is used. (1230f or 123e4 or 1230.)

C++ Tokens: Floating-Point Numbers Design a DFA that accepts C++ floating-point numbers.

Programming DFAs in C++ I have written a program that will read a description of a DFA from a file, and then simulate that DFA. The project is named Universal DFA.mcp. The input file contains A list of transitions. A list of final states. States Each state is represented as a nonnegative integer. 0 is the start state.

Simulating DFAs in C++ Input symbols Transitions Example Each input symbol is a character. Transitions Each transition is of the form (state, symbol; state). Example  = {0, 1}. The following DFA will accept all strings of even length. {(0, 0, 1), (0, 1, 1), (1, 0, 0), (1, 1, 0)} {0}