Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. type aut = {alpha: string array; final: bool array; trans: int array array};;
  2.  
  3. let a = {alpha=[|"*";"a";"b"|]; final = [|false;true;false|]; trans= [| [|2;0;1|];[|0;2;1|];[|2;2;2|] |] }; ;;
  4.  
  5. exception String_is_Empty of string;;
  6.  
  7. let match_state tester aut current_state =
  8. (* find the acceptance for tester by matching it with the current transmissions array and the right index for tester and then checking if the resulting state is one of the accepted. *)
  9. match tester with
  10. |[] -> []
  11. |"a" -> final.(aut.trans.(current_state).(1))
  12. |"b" -> final.(aut.trans.(current_state).(2))
  13.  
  14.  
  15. let rec accepts_from aut s state =
  16. match s with
  17. |[] -> 0
  18. |[hd] -> match_state hd aut state
  19. |hd :: tl -> match_state hd aut state && accepts_from aut tl state
  20.  
  21.  
  22. let accepts aut s =
  23. if String.length s <> 0 then accepts_from aut s 0 else raise (String_is_Empty "Eingabestring")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement