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
4b Lexical analysis Finite Automata
Advertisements

Lecture 6 Nondeterministic Finite Automata (NFA)
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata CPSC 388 Ellen Walker Hiram College.
Compiler Construction
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
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.
Cohen, Chapter 61 Introduction to Computational Theory Chapter 6.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
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)
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
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,
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
using Deterministic Finite Automata & Nondeterministic Finite Automata
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
Lecture # 8 (Transition Graphs). Example Consider the language L of strings, defined over Σ={a, b}, having (containing) triple a or triple b. Consider.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
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.
Theory of Languages and Automata By: Mojtaba Khezrian.
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.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Generalized Transition Graphs
Lexical analysis Finite Automata
Non Deterministic Automata
Compilers Welcome to a journey to CS419 Lecture5: Lexical Analysis:
Chapter 2 Finite Automata
CSC312 Automata Theory Chapter # 5 by Cohen Finite Automata
Theory of Computation Lecture # 9-10.
Pushdown Automata PDAs
Two issues in lexical analysis
Chapter 2 FINITE AUTOMATA.
Hierarchy of languages
Non-Determinism 12CS45 Finite Automata.
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
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
NFAs and Transition Graphs
Finite Automata.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
CSC312 Automata Theory Chapter # 5 by Cohen Finite Automata
CSC312 Automata Theory Transition Graphs Lecture # 9
NFAs and Transition Graphs
Chapter # 5 by Cohen (Cont…)
LECTURE # 07.
CHAPTER 1 Regular Languages
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  High-level sketch Regular expressions NFA DFA Lexical Specification Table-driven Implementation of DFA

3  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

4  A DFA can take only one path through the state graph  Completely determined by input  NFAs can choose  Whether to make  -moves  Which of multiple transitions for a single input to take

 There is a fixed number of states but we can be in multiple states at one time. NFA = “a 5-tuple “  (Q, Σ, , q 0, F) QA finite set of states ΣA finite input alphabet q 0 The initial/starting state, q 0 is in Q FA set of final/accepting states, which is a subset of Q δA transition function, which is a total function from Q x Σ to 2 Q, this function:  Takes a state and input symbol as arguments.  Returns a set of states instead a single state as in DFA. δ: (Q x Σ) – > 2 Q -2 Q is the power set of Q, the set of all subsets of Q δ(q,s) is a function from Q x S to 2 Q (but not to Q) Dr. Hussien M. Sharaf 5

 There is a fixed number of states and the DFA can only be in one state at a time. DFA = “a 5-tuple “  (Q, Σ, , q 0, F) Q: { q 0, q 1, q 2, … } is set of states. Σ: {a, b, …} set of alphabet. (delta): A transition function, which is a total function from Q x Σ to Q, this function:  Takes a state and input symbol as arguments.  Returns a single state. : Q x Σ → Q q 0 Q is the start state. FQ is the set of final/accepting states. Dr. Hussien M. Sharaf 6

A finite automaton is deterministic if  It has no edges/transitions labeled with epsilon/lamda.  For each state and for each symbol in the alphabet, there is exactly one edge labeled with that symbol.

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

9  For BC B C  For B|c C B    

10  For D* D   

11  Choose the NFA that accepts the following regular expression: 1* + 0

12  Consider the regular expression (1 | 0)*1  The NFA is …  1 C E 0 DF   B   G    A H 1 IJ

13 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. Dr. Hussien M. Sharaf

14 Two choices Alphabet = Dr. Hussien M. Sharaf

15 No transition Two choices No transition Alphabet = Dr. Hussien M. Sharaf

16 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 Dr. Hussien M. Sharaf

17 Acceptance Example 1 Dr. Hussien M. Sharaf

18 Dr. Hussien M. Sharaf

19 Dr. Hussien M. Sharaf “reject” “accept”

20 is accepted by the NFA: “accept” “reject” because this computation accepts this computation is ignored Dr. Hussien M. Sharaf

21 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:

22 is rejected by the NFA: “reject” All possible computations lead to rejection Dr. Hussien M. Sharaf

23 is rejected by the NFA: “reject” All possible computations lead to rejection Dr. Hussien M. Sharaf

24 Dr. Hussien M. Sharaf

25 Dr. Hussien M. Sharaf Acceptance Example 2

26 Dr. Hussien M. Sharaf

27 input tape head does not move Dr. Hussien M. Sharaf

28 “accept” String is accepted all input is consumed Dr. Hussien M. Sharaf

29 Rejection Example 3 Dr. Hussien M. Sharaf

30 Dr. Hussien M. Sharaf

31 (read head doesn’t move) Dr. Hussien M. Sharaf

32 “reject” String is rejected Input cannot be consumed Automaton halts Dr. Hussien M. Sharaf

33 Language accepted: Dr. Hussien M. Sharaf

34 Example 4 Dr. Hussien M. Sharaf

35 Dr. Hussien M. Sharaf

36 Dr. Hussien M. Sharaf

37 “accept” Dr. Hussien M. Sharaf

38 Another String Dr. Hussien M. Sharaf

39 Dr. Hussien M. Sharaf

40 Dr. Hussien M. Sharaf

41 Dr. Hussien M. Sharaf

42 Dr. Hussien M. Sharaf

43 Dr. Hussien M. Sharaf

44 “accept” Dr. Hussien M. Sharaf

45 Language accepted Dr. Hussien M. Sharaf

46 Dr. Hussien M. Sharaf

47 Language accepted (redundant state) Dr. Hussien M. Sharaf

 All words with even count of letters. ((a+b)(a+b))* 1±2 a, b Dr. Hussien M. Sharaf 48

 All words that start with “a” a(a+b)* 1- 2 b a 3 + a,b 1- 2 b a 3 + a,b Does not accept all inputs Dr. Hussien M. Sharaf 49

 All words that start with “a” a(a+b)* b a 3 + a,b Special accept state for string “a”, might give better performance in hardware implementation Dr. Hussien M. Sharaf 50

 All words that start with triple letter (aaa+bbb)(a+b)* 1- 2 a 3 a,b 4 b 5 b 6+ b a a Dr. Hussien M. Sharaf 51

{aa, ba, baba, aaaa, ab, bb, bababa, aaba, …} All words with even count of letters having “a” in an even position from the start, where the first letter is letter number one.  (a+b)a((a+b)a)* - a,b Dr. Hussien M. Sharaf 52