|
|
@@ -1,24 +1,46 @@
|
|
|
open Types
|
|
|
|
|
|
-(*
|
|
|
-let omega = "\xcf\x89"
|
|
|
-let pound = "\xc2\xa3"
|
|
|
-*)
|
|
|
-let omega = "*"
|
|
|
-let pound = "$"
|
|
|
-
|
|
|
-let rec string_of_instruction = function
|
|
|
- | Basic c -> Char.escaped c
|
|
|
- | Terminate -> "!"
|
|
|
- | Ptest c -> "+" ^ Char.escaped c
|
|
|
- | Ntest c -> "-" ^ Char.escaped c
|
|
|
- | Jump len -> "#" ^ string_of_int len
|
|
|
-
|
|
|
- | Concat l -> "(" ^ String.concat ";" (List.map string_of_instruction l) ^ ")"
|
|
|
- | Repeat i -> string_of_instruction i ^ omega
|
|
|
-
|
|
|
- | Program c -> Char.escaped c
|
|
|
- | Empty -> ""
|
|
|
-
|
|
|
-let rec string_of_program instrs =
|
|
|
- String.concat ";" (List.map string_of_instruction instrs)
|
|
|
+let utf8_omega = "\xcf\x89"
|
|
|
+let utf8_pound = "\xc2\xa3"
|
|
|
+let utf8_super = [|
|
|
|
+ "\xe2\x81\xb0"; "\xc2\xb9"; "\xc2\xb2"; "\xc2\xb3"; "\xe2\x81\xb4";
|
|
|
+ "\xe2\x81\xb5"; "\xe2\x81\xb6"; "\xe2\x81\xb7"; "\xe2\x81\xb8"; "\xe2\x81\xb9"
|
|
|
+|]
|
|
|
+
|
|
|
+let cat string_of_ins instrs =
|
|
|
+ "(" ^ String.concat ";" (List.map string_of_ins instrs) ^ ")"
|
|
|
+
|
|
|
+let rec string_of_ins_ascii = function
|
|
|
+ | Basic c -> Char.escaped c
|
|
|
+ | Terminate -> "!"
|
|
|
+ | Ptest c -> "+" ^ Char.escaped c
|
|
|
+ | Ntest c -> "-" ^ Char.escaped c
|
|
|
+ | Jump len -> "#" ^ string_of_int len
|
|
|
+
|
|
|
+ | Concat l -> cat string_of_ins_ascii l
|
|
|
+ | Repeat (i, n) -> string_of_ins_ascii i ^ string_of_int n
|
|
|
+ | Loop i -> string_of_ins_ascii i ^ "*"
|
|
|
+
|
|
|
+ | Program c -> Char.escaped c
|
|
|
+ | Empty -> ""
|
|
|
+
|
|
|
+let rec string_of_ins_utf8 = function
|
|
|
+ | Concat l -> cat string_of_ins_utf8 l
|
|
|
+ | Repeat (i, n) when n <= 9 -> string_of_ins_utf8 i ^ utf8_super.(n)
|
|
|
+ | Loop i -> string_of_ins_utf8 i ^ utf8_omega
|
|
|
+ | i -> string_of_ins_ascii i
|
|
|
+
|
|
|
+let rec string_of_ins_latex = function
|
|
|
+ | Concat l -> cat string_of_ins_latex l
|
|
|
+ | Repeat (i, n) -> string_of_ins_latex i ^ "^{" ^ string_of_int n ^ "}"
|
|
|
+ | Loop i -> string_of_ins_latex i ^ "^\\omega"
|
|
|
+ | i -> string_of_ins_ascii i
|
|
|
+
|
|
|
+let string_of_program_ascii instrs =
|
|
|
+ String.concat ";" (List.map string_of_ins_ascii instrs)
|
|
|
+
|
|
|
+let string_of_program_utf8 instrs =
|
|
|
+ String.concat ";" (List.map string_of_ins_utf8 instrs)
|
|
|
+
|
|
|
+let string_of_program_latex instrs =
|
|
|
+ "$" ^ String.concat ";" (List.map string_of_ins_latex instrs) ^ "$"
|