Finite Automata Motivation Examples.

Slides:



Advertisements
Similar presentations
Regular Expressions and DFAs COP 3402 (Summer 2014)
Advertisements

From Cooper & Torczon1 The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source language?
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
1 Finite Automata. 2 Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
Finite Automata Motivation An Example.
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
Finite Automata Costas Busch - RPI.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Lecture 03: Theory of Automata:08 Finite Automata.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
___________________________________________ COMPILER Theory___________________________________________ Fourth Year (First Semester) Dr. Hamdy M. Mousa.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
CSc 453 Lexical Analysis (Scanning)
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
Finite Automata – Definition and Examples Lecture 6 Section 1.1 Mon, Sep 3, 2007.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Chapter 2 Scanning. Dr.Manal AbdulazizCS463 Ch22 The Scanning Process Lexical analysis or scanning has the task of reading the source program as a file.
Formal Languages Finite Automata Dr.Hamed Alrjoub 1FA1.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
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:
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Department of Software & Media Technology
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
Finite Automata.
Transition Graphs.
Finite automate.
Finite Automata Alphabet word
Generalized Transition Graphs
Chapter 2 Scanning – Part 1 June 10, 2018 Prof. Abdelaziz Khamis.
CSc 453 Lexical Analysis (Scanning)
Lexical analysis Finite Automata
Using SLK and Flex++ Followed by a Demo
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSc 453 Lexical Analysis (Scanning)
G. Pullaiah College of Engineering and Technology
What Are They? Who Needs ‘em? An Example: Scoring in Tennis
Finite Automata Alphabet word
Advanced Programming Behnam Hatami Fall 2017.
Finite Automata Motivation An Example.
Some slides by Elsa L Gunter, NJIT, and by Costas Busch
Lexical Analysis - An Introduction
Deterministic Finite Automata And Regular Languages Prof. Busch - LSU.
What Are They? Who Needs ‘em? An Example: Scoring in Tennis
CSE322 Minimization of finite Automaton & REGULAR LANGUAGES
Finite Automata.
Finite Automata.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Language Recognition (12.4)
Lexical Analysis - An Introduction
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSC312 Automata Theory Transition Graphs Lecture # 9
Some Graph Algorithms.
NFAs and Transition Graphs
Lecture 5 Scanning.
Formal Languages and Automata Theory BODDEDA HARITHA LAKSHMI,
CHAPTER 1 Regular Languages
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSc 453 Lexical Analysis (Scanning)
Automata theory and formal languages COS 3112 – AUTOMATA THEORY PRELIM PERIOD WEEK 1 AND 2.
Regular Expressions.
Presentation transcript:

Finite Automata Motivation Examples

Informal Explanation Finite automata are finite collections of states with transition rules that take you from one state to another. Original application was sequential switching circuits, where the “state” was the settings of internal bits. Today, several kinds of software can be modeled by Finite Automata.

Representing Finite Automata Simplest representation is often a graph. Nodes = states. Arcs indicate state transitions. Labels on arcs tell what causes the transition.

Example: Recognizing Strings Ending in “ing” Saw ing g i Not i or g Saw i i Not i i Saw in n Not i or n nothing Start i Not i

Automata to Code (by hand) In C/C++/Java: Initialize state q to start state. Loop through the string one character at a time. Make a switch statement with a case for each state for q, where each case sets q according to the transitions for that state. Accept if you end in a final state.

Example in Java Start state Loop through string s Transitions Scanner scan = new Scanner(System.in); String s = scan.next(); int q = 0; for (char c : s.toCharArray()) { switch (q) { case 0: q = (c=='i')? 1 : 0; break; case 1: q = (c=='n')? 2 : ((c=='i')? 1 : 0); break; case 2: q = (c=='g')? 3 : ((c=='i')? 1 : 0); break; case 3: q = (c=='i')? 1 : 0; } if (q==3) System.out.println("accept."); else System.out.println("reject."); Start state Loop through string s Transitions 1 2 3 Final state

Automata to Code – General It would be nice to have an automatic way to generate such code… Rather than do it by hand, a code generator takes a “regular expression” describing the pattern(s) you are looking for and produces the code for it. Example: .*ing works in grep.

Example: An Even Number of 1’s 1 even odd 1 Start How would it look to accept a number of 1’s that is a multiple of 3?

Password/Keyword Example any character any character This is sometimes called a dead state. BTW, there is a potential security risk on the password application if this finite automaton reports failure too quickly.

Exactly Two a’s

At Least Two b’s

Exactly two a’s and at least two b’s

Containing Substrings or Not Contains baba: Does not contain baba:

General Comments Some things are easy with finite automata: Substrings (…abcabc…) Subsequences (…a…b…c…b…a…) Modular counting (odd number of 1’s) Some things are impossible with finite automata (we will prove this later): An equal number of a’s and b’s More 0’s than 1’s But when they can be used, they are fast.