(* The DFA shown in the homework assignment. It accepts strings where *) (* there is an even number of 1's and an even number of 0's. The first *) (* input is valid, the second is not. *) let dfa1 = ("0", [("0", "0", "2"); ("0", "1", "1"); ("1", "0", "3"); ("1", "1", "0"); ("2", "0", "0"); ("2", "1", "3"); ("3", "0", "1"); ("3", "1", "2")], ["0"]);; let dfa1input1 = ["0";"1";"0";"1";"0";"0"];; let dfa1input2 = ["0";"1";"0";"1";"0";"0";"1"];; (* This DFA simulates a coffee machine. The input is a series of *) (* coins: either a nickel ('n'), dime ('d'), or quarter ('q'). Once *) (* the input reaches $0.30, the machine will make coffee, and possibly *) (* return change (although we aren't dealing with the change return). *) (* The states are numbered as to the amount of money entered so far. *) (* Of the two inputs after the DFA spec, the first is valid and the *) (* second is not *) let dfa2 = ("0", [("0", "n","5" );("0", "d","10");("0" ,"q","25"); ("5", "n","10");("5", "d","15");("5", "q","30"); ("10","n","15");("10","d","20");("10","q","35"); ("15","n","20");("15","d","25");("15","q","40"); ("20","n","25");("20","d","30");("20","q","45"); ("25","n","30");("25","d","35");("25","q","50")], ["30";"35";"40";"45";"50"]);; let dfa2input1 = ["n";"d";"n";"q"];; let dfa2input2 = ["d";"d";"n";"q";"n"];; (* The NFA shown in the homework assignment. The first input is *) (* valid, the second is not. *) let nfa1 = ("0", [("0", "a", "1"); ("0", "a", "2"); ("1", "a", "1"); ("1", "a", "2"); ("2", "b", "1"); ("2", "b", "3"); ("3", "a", "1"); ("3", "a", "2")], ["0"; "1"]);; let nfa1input1 = ["a";"b";"a";"b";"a";"b";"a";"a";"a";"b";"a";"a"];; let nfa1input2 = ["a";"a";"b";"a";"b";"b"];; (* This NFA will accept strings of the form a+b+ or a+c+. More *) (* formally, it accepts strings of the regular expression a+(b+|c+) *) (* The first input is valid, the second is not. *) let nfa2 = ("0", [("0","a","1"); ("0","a","3"); ("1","a","1"); ("1","b","2"); ("2","b","2"); ("3","a","3"); ("3","c","4"); ("4","c","4") ], ["2";"4"]);; let nfa2input1 = ["a";"a";"a";"b"];; let nfa2input2 = ["a";"a";"a";"b";"b";"b";"b";"c"];; (* Converts a string into a string list *) let explode s = let c2s = String.make 1 in let rec expl i l = if i < 0 then l else expl (i - 1) ((c2s s.[i]) :: l) in expl (String.length s - 1) [];; (* Thus, you can call your functions this way: *) (* nfasimulate nfa2 (explode "aaaaabbbbbc");; *)