1 / 49

Finite automate

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

rnielson
Download Presentation

Finite automate

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Finite automate

  2. 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)+ Patterns for token

  3. 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. Transition Diagram

  4. 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 . Transition Diagram • Start state • Accept state • Any state

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

  6. Regular expressions = specification Finite automata = implementation Finite automata: why?

  7. Definition : Finite Automaton

  8. Finite Automata

  9. State Diagram 1 0 0 q3 q1 q2 1 0, 1

  10. 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 Finite Automata

  11. Data Representation

  12. A finite automaton that accepts only “a” • Language of FS is the set of accepted states Exercise

  13. 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. Finite Automata

  14. NFA

  15. 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 Nondetermistic Finite Automata: NFA

  16. NFA 0,1 0,1 q3 1 q4 q1 q2 1 0,e

  17. NFA

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

  19. Answer

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

  21. Answer 2

  22. DFA

  23. 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. DFA

  24. 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 DFA

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

  26. 1- Answer

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

  28. 2- answer

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

  30. 3 Answer

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

  32. 4- Answer

  33. Construction of an NFA from regular Expression

  34. 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

  35. -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 Construction of an NFA from regular Expression

  36. Regular language Regular language NFA NFA Single final state Single final state

  37. Example

  38. Union • NFA for Ԑ Ԑ Ԑ Ԑ

  39. Example NFA for Ԑ Ԑ Ԑ Ԑ

  40. Concatenation • NFA for Ԑ Ԑ

  41. Example • NFA for Ԑ Ԑ

  42. Star Operation Ԑ • NFA for Ԑ Ԑ Ԑ Ԑ

  43. Example • NFA for Ԑ Ԑ Ԑ Ԑ

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

  45. Steps 1,2

  46. Step 3,4

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

  48. 3.4 3.6 3.7.4

More Related