1 / 20

Deterministic Finite Automata

Deterministic Finite Automata. Section 2.1 Mon, Sep 19, 2005. Intuitive View of an Automaton. An automaton is a machine that has an input tape and can be put into any of several states . A string of symbols is written on the tape before execution.

Télécharger la présentation

Deterministic Finite Automata

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. Deterministic Finite Automata Section 2.1 Mon, Sep 19, 2005

  2. Intuitive View of an Automaton • An automaton is a machine that has an input tape and can be put into any of several states. • A string of symbols is written on the tape before execution. • The automaton begins by reading the symbols on the tape, from left to right. • Upon reading a symbol from the tape, the machine (possibly) changes state and advances the tape. • After reading the last symbol, the machine halts. • The last state tells the result of the processing (accept or reject).

  3. More Precise View of an Automaton • Divide the states into two groups: final (accepting) an nonfinal (rejecting). • Begin in the designated start state. • Upon reading a symbol on the tape, make a transition to the appropriate state.

  4. a p q Transition Diagrams • In a transition diagram, • Each state is represented by a circle. • Each final state is represented by a circle within a circle. • Transitions are represented by arrows from one state to another state. • Transitions are labeled with an input symbol. • Final states are indicated by a circle within a circle. • The following diagram represents the transition from state p to state q upon reading the symbol a.

  5. Example of an Automaton • Describe an automaton that reports whether the input string begins with a 0. • Describe an automaton that reports whether the input string ends with a 0. • Describe an automaton that would read the input tape and report whether the tape contained an even number or an odd number of symbols. • Describe an automaton that would read a binary string and report whether the string contained an even number of 0s and an odd number of 1s.

  6. Some Special DFAs • Let  = {0, 1}. • Design a DFA that accepts no string. • Design a DFA that accepts every string. • Design a DFA that accepts only strings of length 1. • Design a DFA that accepts only strings of length 2. • Design a DFA that accepts only the empty string.

  7. Definition of a Deterministic Finite Automaton • A deterministic finite automaton (DFA) is a quintuple (K, , , s, F) where • K is a finite set of states. •  is a finite input alphabet. • sK is the initial (start) state. • FK is the set of final states. •  is the transition function from K to K, i.e., KK.

  8. The Functioning of a DFA • The DFA begins in the initial state s. • Upon reading an input symbol, the DFA changes state according to the rule expressed by the transition function . • After reading the last symbol on the tape, the DFA halts. • The input is accepted if the final state is in F. Otherwise, the input is rejected.

  9. Configurations • Given a DFA M, a configuration is a pair (q, w) where q is the current state of M and w is the remainder of the input string. • Given configuration (q, w), if the next transition produces the configuration (q, w), then we say that (q, w) yields(q, w) in one step. • That is, w = aw' for some a   and there is a transition (q, a) = q'. • This is denoted (q, w) M(q, w).

  10. Configurations • The configuration (q, w) yields the configuration (q, w) if there is a sequence of configurations (q1, w1), (q2, w2), …, (qn, wn) such that (qi, wi) yields (qi + 1, wi + 1) in one step, for i = 1, …, n – 1, and (q1, w1) = (q, w) and (qn, wn) = (q, w). • This is denoted (q, w) M*(q, w). • The relation M*is the reflexive, transitive closure of the relation M.

  11. The Language of a DFA • The string w is accepted by M if (s, w) M*(q, e) for some state q F. • The language of a DFA M, denoted L(M), is L(M) = {w * | M accepts w} or L(M) = {w * |  q  F, (s, w) M*(q, e)}.

  12. Examples of DFAs • Let  = {0, 1}. • Design a DFA whose language is the set of all strings containing 00. • Design a DFA whose language is the set of all strings containing 00 or 11. • Design a DFA whose language is the set of all strings that do not contain 00. • Design a DFA whose language is the set of all strings that contain 00, but not 11.

  13. C++ Tokens: Identifiers • A C++ identifier is a string of letters, digits, and underscores that begins with a letter. • Design a DFA that will accept C++ identifiers.

  14. C++ Tokens: Integers • A C++ integer may be expressed in decimal, octal, or hexadecimal. • In each base, the integer may begin with an optional + or – sign and end with an optional L or l. • Decimal • One or more decimal digits (0 – 9), first digit nonzero. • Octal • An initial 0, followed by one or more octal digits (0 – 7). • Hexadecimal • An initial 0x, followed by one or more hexadecimal digits (0 – 9, a – f, A – F).

  15. C++ Tokens: Integers • Design a DFA that accepts C++ integers.

  16. C++ Tokens: Floating-Point Numbers • A C++ floating-point number consists of the following. • The mantissa • A + or – sign, followed by zero or more digits, followed by a decimal point, followed by zero or more digits. • The exponent • An e or E, followed by a + or – sign, followed by one or more digits. • The final F or f.

  17. C++ Tokens: Floating-Point Numbers • The mantissa and exponent + or – signs are optional. (-1.23, 1.23e-4) • Digits before the decimal point are optional, provided there is at least one digit after the decimal point, and vice versa. (.123 and 123.) • The decimal point, the exponential part, and the final F are optional, provided at least one is used. (1230f or 123e4 or 1230.)

  18. C++ Tokens: Floating-Point Numbers • Design a DFA that accepts C++ floating-point numbers.

  19. Programming DFAs in C++ • I have written a program that will read a description of a DFA from a file, and then simulate that DFA. • The project is named Universal DFA.mcp. • The input file contains • A list of transitions. • A list of final states. • States • Each state is represented as a nonnegative integer. • 0 is the start state.

  20. Simulating DFAs in C++ • Input symbols • Each input symbol is a character. • Transitions • Each transition is of the form (state, symbol; state). • Example •  = {0, 1}. • The following DFA will accept all strings of even length. {(0, 0, 1), (0, 1, 1), (1, 0, 0), (1, 1, 0)} {0}

More Related