Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite automate.

Similar presentations


Presentation on theme: "Finite automate."— Presentation transcript:

1 Finite automate

2 Patterns for token digit  [0-9] digits  digit+ Letter  [A –Z a-z]
If if then ten else else Relop <|<=|=|<>|>|>= Idletter(letter|digit)* Numdigits+ (.digits+)?(E(+|-)?digits+)? ws (blank|tab|newline)+

3 Transition Diagram A transition diagram is a stylized flowchart.
Transition diagram is used to keep track of information about characters that are seen as the forward pointer scans the input. We do so by moving from position to position in the diagrams as characters are read.

4 Transition Diagram Start state Accept state Any state
Have a collection of circles called states . Each state represents a condition that could occur during the process of scanning the input looking for a lexeme that matches one of several patterns . Start state Accept state Any state

5 Transition Diagram Edge : represent transitions from one state to another as caused by the input

6

7 Finite automata: why? Regular expressions = specification
Finite automata = implementation

8 Definition : Finite Automaton

9 Finite Automata

10 State Diagram 1 q3 q1 q2 1 0, 1

11 Finite Automata Transition s1 a s2 Is read
In state s1 on input a go to state s2 •If end of input and in accepting state => accept •Otherwise => reject

12 Data Representation

13 Exercise A finite automaton that accepts only “a”
Language of FS is the set of accepted states stat input 1 a 2 Is accepted b ? a 1 2

14 Finite Automata Two types – both describe what are called regular languages Deterministic (DFA) – There is a fixed number of states and we can only be in one state at a time Nondeterministic (NFA) –There is a fixed number of states but we can be in multiple states at one time NFA and DFA stand for nondeterministic finite automaton and deterministic finite automaton, respectively.

15 NFA

16 Nondetermistic Finite Automata: NFA
A nondeterministic finite automaton can be different from a deterministic one in that for any input symbol, nondeterministic one can transit to more than one states. epsilon transition

17 NFA 0,1 0,1 q3 1 q4 q1 q2 1 0,e

18 NFA

19 Test youself Construct an NFA to accept all strings terminating in 01 

20 Answer

21 Test yourself 2 Construct an NFA to accept those strings containing three consecutive zeroes

22 Answer 2

23 DFA

24 DFA Is special case of NFA where: There are no moves on input Ԑ
For each state s and input symbol a , there exactly one edge out of a labeled a.

25 DFA 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

26 Test yourself (DFA1) 1- Construct a DFA to accept a string containing a zero followed by a one

27 Answer 1-

28 Test yourself (DFA2) 2-  Construct a DFA to accept a string containing two consecutive zeroes followed by two consecutive ones

29 answer 2-

30 Test yourself (DFA3) 3- Construct a DFA to accept a string containing even number of zeroes and any number of ones

31 Answer 3

32 Test yourself (DFA4) 4-  Construct a DFA to accept all strings which do not contain three consecutive zeroes  

33 Answer 4-

34 Construction of an NFA from regular Expression

35 Construction of an NFA from regular Expression
Recursive construction Base cases follow base case definitions of regular expressions : -NFA that accepts the empty string – a single state that is the start and end state a: -NFA that accepts {a} – two-state machine (start and final state) with an a-transition Note: technically, we also need an -NFA for the empty language {} – easy

36 Construction of an NFA from regular Expression
-NFA that accepts the empty string – a single state that is the start and end state a: -NFA that accepts {a} – two-state machine (start and final state) with an a-transition

37 Regular language Single final state Regular language NFA Single final state NFA

38 Example

39 Union NFA for Ԑ Ԑ Ԑ Ԑ

40 Example NFA for Ԑ Ԑ Ԑ Ԑ

41 Concatenation NFA for Ԑ Ԑ

42 Example NFA for Ԑ Ԑ

43 Star Operation Ԑ NFA for Ԑ Ԑ Ԑ Ԑ

44 Example NFA for Ԑ Ԑ Ԑ Ԑ

45 Test yourself Construct the NFA for r= (a|b)*abb

46 Steps 1,2

47 Step 3,4

48 Answer Construct the NFA for r= (a|b)*abb

49 3.4 3.6 3.7.4


Download ppt "Finite automate."

Similar presentations


Ads by Google