Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines
Fall 2005 CSE 467/567 2 Formal languages A string is a (perhaps empty) sequence of symbols. denotes the empty string. A language is a (perhaps empty) set of strings. denotes the empty set. There are many different classes of languages. Main ones in Chomsky hierarchy are regular, context free, context sensitive and unrestricted.
Fall 2005 CSE 467/567 3 Sets and set operations Examples: is the empty set, a set with no members {a, b, c} is a set with three members Operations: Suppose A={a, b, c} and B={1, 2}, then A B={a1, a2, b1, b2, c1, c2} A ={(a,1),(a,2),(b,1),(b,2),(c,1),(c,2)} A B={a, b, c, 1, 2} A*={ , a, b, c, aa, ab, ac, ba, bb, bc, aaa, aab, aac, …}
Fall 2005 CSE 467/567 4 Regular languages The class of regular languages over an alphabet can be defined recursively: base case 1: is a regular language base case 2: { } is a regular language base case 3: for each symbol in , { } is a regular language recursive cases: If S and T are regular languages, then so are: {st| s is in S and t is in T}, the concatenation of S and T {x| x is in S or x is in T}, the disjunction of S and T S*, the Kleene closure of S Nothing else is a regular language.
Fall 2005 CSE 467/567 5 Finite state automata Formally a 5-tuple (Q, ,q0,F, ) where Q is a finite set of states is a finite input alphabet of symbols q0 Q is the initial state F Q is a set of final states : Q Q
Fall 2005 CSE 467/567 6 Examples FSA (5-tuple and diagram) accepting each of the following (assume ={a,b,c,…z}): {a} {fred, wilma} {ball, bell, bill, boll, bull} { , a} { , a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, …}
Fall 2005 CSE 467/567 7 RE’s outside of Perl? Can always directly implement the DFA. –switch on state, switch on symbol –table-driven method (put in an array) Example!
Fall 2005 CSE 467/567 8 Construction of FA Base cases is a regular language 2.{ } is a regular language 3.for each symbol in , { } is a regular language Recursive cases If S and T are regular languages, then so are: 4.{st| s is in S and t is in T}, the concatenation of S and T 5.{x| x is in S or x is in T}, the disjunction of S and T 6.S*, the Kleene closure of S
Fall 2005 CSE 467/567 9 NFA vs. DFA Accept same set of languages. Simulation of NFA through search: depth-first (stack regime for next node) breadth-first (queue regime) Can mechanically convert NFA to DFA, with possible exponential increase in number of states.