WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.

Slides:



Advertisements
Similar presentations
Finite-State Machines with No Output Ying Lu
Advertisements

4b Lexical analysis Finite Automata
Lecture 6 Nondeterministic Finite Automata (NFA)
Regular Expressions and DFAs COP 3402 (Summer 2014)
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
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.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Natural Language Processing Lecture 4 : Regular Expressions and Automata.
CSC3315 (Spring 2009)1 CSC 3315 Lexical and Syntax Analysis Hamid Harroud School of Science and Engineering, Akhawayn University
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
Modeling Computation: Finite State Machines without Output
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.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Deterministic Finite Automata Nondeterministic Finite Automata.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Computation Automata Theory Dr. Ayman Srour.
Department of Software & Media Technology
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Introduction to Automata Theory Theory of Computation Lecture 3 Tasneem Ghnaimat.
Finite automate.
Finite State Machines Dr K R Bond 2009
Finite-State Machines (FSMs)
Lexical analysis Finite Automata
Non Deterministic Automata
Compilers Welcome to a journey to CS419 Lecture5: Lexical Analysis:
Finite-State Machines (FSMs)
Theory of Computation Lecture # 9-10.
Two issues in lexical analysis
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Hierarchy of languages
Some slides by Elsa L Gunter, NJIT, and by Costas Busch
THEORY OF COMPUTATION Lecture One: Automata Theory Automata Theory.
Deterministic Finite Automata And Regular Languages Prof. Busch - LSU.
Non-Deterministic Finite Automata
Principles of Computing – UFCFA3-30-1
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
NFAs and Transition Graphs
Finite Automata Reading: Chapter 2.
Finite Automata.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
CSC312 Automata Theory Transition Graphs Lecture # 9
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
NFAs and Transition Graphs
Lecture 5 Scanning.
Non Deterministic Automata
Lexical Analysis Uses formalism of Regular Languages
Presentation transcript:

WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University

2

Input “Accept” or “Reject” String Finite Automaton Output

4  A state The start state An accepting state A transition a

5  A finite automaton that accepts only “1”  A finite automaton accepts a string if we can follow transitions labeled with the characters in the string from the start to some accepting state 1

6  A finite automaton accepting any number of 1’s followed by a single 0  Alphabet: {0,1}  Check that “1110” is accepted but “0110” is not 0 1

baaa*!

 Definition: A finite-state automaton is a 5-tuple M=(S, I, f, S 0, F) where  S is a finite set of states  I is a finite input alphabet  f:S  I  S is a transition function from each state- input pair to a state  S 0 is the initial state  F  S is a set of final states  Note: automaton is the singular of automata.

 FSA is a 5-tuple consisting of  Q: set of states {q0,q1,q2,q3,q4}   : an alphabet of symbols {a,b,!}  q0: a start state in Q  F: a set of final states in Q {q4}   (q,i): a transition function mapping Q x  to Q q0 q4 q1q2q3 ba a a!

 An FSA recognizes (accepts) strings of a regular language  baa!  baaa!  baaaa! ……  Tape metaphor: will this input be accepted? baAa

State Input ba! q0 q4 q1q2q3 ba a a!

 Possible Goals  Determine whether a string should be accepted by a machine  Or… determine whether a string is in the language defined by the automaton  Or… determine whether a regular expression matches a string  This process can be represented with an input tape

aba!b q0q baa ! a REJECT Slide from Dorr/Monz

baaa q0q0 q1q1 q2q2 q3q3 q3q3 q4q4 ! baa ! a ACCEPT Slide from Dorr/Monz

15  Alphabet {0,1}  What language does this recognize?

16  Alphabet still { 0, 1 } The operation of the automaton is not completely defined by the input  On input “11” the automaton could be in either state 1 1

 Definition: A finite-state automaton accepts (or recognizes) a string x if f(S 0, x)  F. That is, the finite state automaton ends up in a final state.  Definition: The language accepted (or recognized) by a finite-state automaton M, denoted by L(M), is the set of all strings recognized by M.  Definition: Two finite-state automata are equivalent if they recognize the same language.

 If end of input  If in accepting state => accept  Otherwise => reject  If no transition possible (got stuck) => reject

 A finite automaton is a recognizer that takes a string, and answers “yes” if the string matches a pattern of a specified language, and “no” otherwise.  Two kinds:  Nondeterministic finite automaton (NFA)  no restriction on the labels of their edges  Deterministic finite automaton (DFA)  exactly one edge with a distinguished symbol goes out of each state  Both NFA and DFA have the same capability  We may use NFA or DFA as lexical analyzer 19

20  Deterministic Finite Automata (DFA)  One transition per input per state  No  -moves  Nondeterministic Finite Automata (NFA)  Can have multiple transitions for one input in a given state  Can have  -moves  Finite automata have finite memory  Need only to encode the current state

21  Another kind of transition:  -moves  Machine can move from state A to state B without reading input A B

 FSMs can be represented by:  Transition diagrams  Transition tables

The language recognized by this NFA is (a|b) * a b 23

NFA accepting aa* |bb* 24

 initial state accepting state transition

 Input String

accept Input finished

reject Input finished

 reject

accept Input finished

reject Input finished

 accept

51  High-level sketch Regular expressions NFA DFA Lexical Specification Table-driven Implementation of DFA

 Regular expression is a declarative way to describe the tokens  It describes what is a token, but not how to recognize the token.  FA is used to describe how the token is recognized  FA is easy to be simulated by computer programs;  There is a 1-1 correspondence between FA and regular expression  Scanner generator (such as lex) bridges the gap between regular expression and FA. Scanner generator Finite automaton Regular expression scanner program String stream Tokens

Main components of scanner generation (e.g., Lex)  Convert a regular expression to a non-deterministic finite automaton (NFA)  Convert the NFA to a determinstic finite automaton (DFA)  Improve the DFA to minimize the number of states  Generate a program in C or some other language to “simulate” the DFA RE NFA DFA Minimized DFA Program Subset construction DFA simulation Scanner generator Minimization

54

 NFA (Non-deterministic Finite Automaton) is a 5-tuple (S, Σ, , S0, F):  S: a set of states;   : the symbols of the input alphabet;   : a set of transition functions;  move(state, symbol)  a set of states  S0: s0  S, the start state;  F: F  S, a set of final or accepting states.  Non-deterministic -- a state and symbol pair can be mapped to a set of states.  Finite—the number of states is finite.

 NFA can be represented by a transition graph  Accepts a string x, if and only if there is a path from the starting state to one of accepting states such that edge labels along this path spell out x.  Remarks  The same symbol can label edges from one state to several different states  An edge may be labeled by ε, the empty string 56

57  For each kind of rexp, define an NFA  Notation: NFA for rexp A A For   For input a a

58  For AB A B  For A | B A B    

59  For A* A   

60  Consider the regular expression (1 | 0)*1  The NFA is (there are multiple valid answers)  1 C E 0 DF   B   G    A H 1 IJ

61 Alphabet =  NFA travels all possible paths, and so it remains in many states at once. As long as at least one of the paths results in an accepting state, the NFA accepts the input.

62 Two choices Alphabet =

63 No transition Two choices No transition Alphabet =

64 An NFA accepts a string: if there is a computation of the NFA that accepts the string i.e., all the input string is processed and the automaton is in an accepting state

65 Acceptance Example 1

66

67 “reject” “accept”

68 is accepted by the NFA: “accept” “reject” because this computation accepts this computation is ignored

69 An NFA rejects a string: if there is no computation of the NFA that accepts the string. All the input is consumed and the automaton is in a non final state The input cannot be consumed OR For each computation:

70 is rejected by the NFA: “reject” All possible computations lead to rejection

71 is rejected by the NFA: “reject” All possible computations lead to rejection

72 Remember! Bothe Lambda λ and Epsilon є can be used to represent an empty move

73 Acceptance Example 2

74

75 input tape head does not move

76 “accept” String is accepted all input is consumed

77 Rejection Example 3

78

79 (read head doesn’t move)

80 “reject” String is rejected Input cannot be consumed Automaton halts

81 Language accepted:

82 Example 4 what is the language accepted by this automata?

83

84

85 “accept”

86 Another String

87

88

89

90

91

92 “accept”

93 Language accepted

94

95 Language accepted (redundant state)