types.ml 795 B

1234567891011121314151617181920212223242526272829303132
  1. type ins =
  2. | Basic of char (* a *)
  3. | Terminate (* ! *)
  4. | Ptest of char (* +a *)
  5. | Ntest of char (* -a *)
  6. | Jump of int (* #1 *)
  7. | Concat of ins list (* a;b *)
  8. | Repeat of ins * int (* a2 : execute a twice *)
  9. | Loop of ins (* a* : repeat a infinitely *)
  10. | Program of char (* X *)
  11. | Empty
  12. type program = ins list
  13. (* Natural numbers *)
  14. type natural = Infinity | N of int
  15. let natural_binop binop a b =
  16. match (a, b) with
  17. | N i, N j -> N (binop i j)
  18. | _ -> Infinity
  19. let ( ++ ) = natural_binop ( + )
  20. let ( -- ) = natural_binop ( - )
  21. let ( ** ) = natural_binop ( * )
  22. let ( // ) = natural_binop ( / )
  23. exception Fatal_error of string
  24. exception Ins_error of ins * string
  25. exception Program_error of program * string