Commit f8778da5 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Cleanup

parent 9340893b
open Printf
open Types open Types
open Stringify open Stringify
open Parse open Parse
let main () = let main () =
let argc = Array.length Sys.argv in
let usage status = let usage status =
printf "usage: %s command [args]\n" Sys.argv.(0); prerr_endline ("usage: " ^ Sys.argv.(0) ^ " command [args]");
printf "command:\n"; prerr_endline "command:";
printf " help\n"; prerr_endline " help show this help page";
printf " echo PROGRAM\n"; prerr_endline " echo PROGRAM pretty-print a program";
status prerr_endline "input program syntax:";
prerr_endline " - omit omega sign after closing parenthesis";
prerr_endline " - write dollar sign ($) instead of pound sign";
exit status
in in
if argc = 1 then begin
usage 1 let argc = Array.length Sys.argv in
end else if argc = 1 then usage 1;
begin
match Sys.argv.(1) with match Sys.argv.(1) with
| "help" -> | "help" ->
usage 0 usage 0
| "echo" when argc > 2 -> | "echo" when argc > 2 ->
printf "%s\n" (string_of_program (parse_string Sys.argv.(2))); print_endline (string_of_program (parse_string Sys.argv.(2)))
0
| _ -> | _ ->
usage 1 usage 1
end;
exit 0
let () = exit (main ()) let () = main ()
open Types open Types
let omega = "\207\137"
let string_of_basic ins = ins let string_of_basic ins = ins
let string_of_primitive = function let string_of_primitive = function
...@@ -12,5 +14,5 @@ let string_of_primitive = function ...@@ -12,5 +14,5 @@ let string_of_primitive = function
let rec string_of_program = function let rec string_of_program = function
| Primitive p -> string_of_primitive p | Primitive p -> string_of_primitive p
| Concat l -> String.concat ";" (List.map string_of_program l) | Concat l -> String.concat ";" (List.map string_of_program l)
| Repeat p -> "(" ^ string_of_program p ^ ")\207\137" | Repeat p -> "(" ^ string_of_program p ^ ")" ^ omega
| Empty -> "" | Empty -> ""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment