stringify.ml 597 B

123456789101112131415161718192021222324
  1. open Types
  2. (*
  3. let omega = "\xcf\x89"
  4. let pound = "\xc2\xa3"
  5. *)
  6. let omega = "*"
  7. let pound = "$"
  8. let rec string_of_instruction = function
  9. | Basic c -> Char.escaped c
  10. | Terminate -> "!"
  11. | Ptest c -> "+" ^ Char.escaped c
  12. | Ntest c -> "-" ^ Char.escaped c
  13. | Jump len -> "#" ^ string_of_int len
  14. | Concat l -> "(" ^ String.concat ";" (List.map string_of_instruction l) ^ ")"
  15. | Repeat i -> string_of_instruction i ^ omega
  16. | Program c -> Char.escaped c
  17. | Empty -> ""
  18. let rec string_of_program instrs =
  19. String.concat ";" (List.map string_of_instruction instrs)