Working example

This commit is contained in:
2023-03-10 13:58:16 +00:00
parent 35a081162f
commit 180ebb56fa
62 changed files with 1487 additions and 372 deletions

View File

@@ -1,15 +1,21 @@
TRUE := \t.\f.t
FALSE := \t.\f.f
NOT := \x.x FALSE TRUE
AND := \x.\y.x y FALSE
OR := \x.\y. x TRUE y
Y := \f.(\x.f (x x))(\x.f (x x))
import std::conv::(parse_float, to_string)
import std::cpsio::(readline, print)
import std::str::(concatenate)
(! ...$expr) =10=> (NOT ...$expr)
(...$lhs & ...$rhs) =10=> (AND (...$lhs) (...$rhs))
(...$lhs | ...$rhs) =20=> (OR (...$lhs) (...$rhs))
main := (TRUE & TRUE | FALSE & FALSE)
(start_token ...$rest) ==> (carriage(()) ...$rest)
(..$prefix carriage($state) $next ..$rest) ==> (..$prefix $out carriage(??) ..$rest)
export main := do{
cps data = readline;
let a = parse_float data;
cps op = readline;
cps print ("\"" ++ op ++ "\"\n");
cps data = readline;
let b = parse_float data;
let result = (
if op = "+" then a + b
else if op = "-" then a - b
else if op = "*" then a * b
else if op = "/" then a / b
else "Unsupported operation" -- dynamically typed shenanigans
);
cps print (to_string result ++ "\n");
0
}