diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-04-22 18:38:38 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-04-22 18:59:19 +0200 |
commit | 2e893fd0df7dae8c4ae843d4a23acb098dd97aff (patch) | |
tree | 1f4a50da28d2e6ef04b2fc2b663790b42352f2ca /lib/to_string.ml | |
parent | af76b11278204c25428c4f95ef51d4aa8f2a1e0e (diff) | |
download | chadprover-2e893fd0df7dae8c4ae843d4a23acb098dd97aff.tar.gz chadprover-2e893fd0df7dae8c4ae843d4a23acb098dd97aff.tar.bz2 chadprover-2e893fd0df7dae8c4ae843d4a23acb098dd97aff.zip |
added a functional parser
Diffstat (limited to 'lib/to_string.ml')
-rw-r--r-- | lib/to_string.ml | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/to_string.ml b/lib/to_string.ml new file mode 100644 index 0000000..30e909b --- /dev/null +++ b/lib/to_string.ml @@ -0,0 +1,44 @@ +open Types + +let rec string_of_prop = function + | True -> "True" + | False -> "False" + | Lit symbol -> symbol + | Not p -> "¬" ^ (string_of_prop p) + | And (p1, p2) -> "(" ^ (string_of_prop p1) ^ " ∧ " ^ (string_of_prop p2) ^ ")" + | Or (p1, p2) -> "(" ^ (string_of_prop p1) ^ " ∨ " ^ (string_of_prop p2) ^ ")" + | Implies (p1, p2) -> "(" ^ (string_of_prop p1) ^ " → " ^ (string_of_prop p2) ^ ")" + | Iff (p1, p2) -> "(" ^ (string_of_prop p1) ^ " ↔ " ^ (string_of_prop p2) ^ ")";; + + let string_of_sub sub = + let rec stringify = function + | [] -> "" + | (s, value) :: [] -> "(" ^ s ^ ": " ^ (string_of_prop value) ^ ")" + | (s, value) :: tl -> "(" ^ s ^ ": " ^ (string_of_prop value) ^ "), " ^ (stringify tl) + in "[" ^ (stringify sub) ^ "]";; + +let string_of_interpr (i : interpretation) = + let rec stringify = function + | [] -> "" + | (s, value) :: [] -> "(" ^ s ^ ": " ^ (string_of_bool value) ^ ")" + | (s, value) :: tl -> "(" ^ s ^ ": " ^ (string_of_bool value) ^ "), " ^ (stringify tl) + in "[" ^ (stringify i) ^ "]";; + +let print_prop prop = print_endline (string_of_prop prop);; + +let string_of_tok = function + | TRUE -> "TRUE" + | FALSE -> "FALSE" + | LIT s -> "LIT " ^ s + | NOT -> "NOT" + | AND -> "AND" + | OR -> "OR" + | IMPLIES -> "IMPLIES" + | IFF -> "IFF" + | LEFT_PAREN -> "LEFT_PAREN" + | RIGHT_PAREN -> "RIGHT_PAREN" + | SKIP -> "SKIP" + +let rec string_of_tokens = function + | [] -> "" + | t :: ts -> "[" ^ string_of_tok t ^ "] " ^ string_of_tokens ts |