Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Deterministic finite automata ====== ==== 1. Writing DFAs ==== 1.1. Write a DFA which accepts the language $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of 1s} \} $ Hint: * in a DFA, delta is total! 1.2 Define a DFA which accepts arithmetic expressions. Consider the following definition for arithmetic expressions: <code> <expr> ::= <var> | <expr> + <expr> | <expr> * <expr> <var> ::= STRING </code> Hint: * how would you define the alphabet for the DFA? * can <expr> be the empty string? ==== 2. Implementing DFAs ==== Consider the following encoding of a DFA: <code> <number_of_states> <list_of_final_states> <state> <symbol> <state> </code> Example: <code> 4 2 3 0 a 1 1 b 2 2 a 0 </code> 2.1. Write a function which takes a DFA encoding as above and returns a DFA representation. Define a class "DFA". 2.2. Add a method accept which takes a word and returns true if it is accepted by the DFA 2.3. Add a method step with takes a DFA configuration and returns the "next-step" configuration of the DFA. How is a configuration defined? 2.4(*) Write a method which: * takes a list of DFAs ''a1, a2, ..., an'' * takes a string ''s''. We know the string consists of a sequence of words, each accepted by some dfa in the list. * returns a list of pairs ''(w1,x1), ...(wi,xi) ... (wn,xn)'' such that ''w1w2...wn = s'' and the dfa ''i'' accepts word ''wi'', for each i from 1 to n. Example: <code> l = [a1, a2, a3] ''' a1 accepts sequences of digits [0-9] a2 accepts sequences of lowercase symbols [a-z] a3 accepts operands (+ and *) ''' s = "var+40*2300" our function returns: [("var",2), ("+",3), ("40",1), ("*",3), ("2300",1)] </code>