From 8c33b3d2c69b6800ca34155d62c000250980e47e Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sat, 18 Feb 2023 16:58:51 +1300 Subject: Introduce stdlib and fix lexing bug --- DSL/StdLib.hs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 DSL/StdLib.hs (limited to 'DSL/StdLib.hs') diff --git a/DSL/StdLib.hs b/DSL/StdLib.hs new file mode 100644 index 0000000..6483433 --- /dev/null +++ b/DSL/StdLib.hs @@ -0,0 +1,37 @@ +module DSL.StdLib (stdlib) where + +import DSL.Types +import DSL.BaseParsers (parse, mult, chain) +import DSL.Parsing (tokenizer, procP) + +stdlib :: [ProcSpec] +stdlib = procs + where + p = tokenizer `chain` mult procP + procs = case parse p (unlines sources) of + Nothing -> error "Failed to parse standard library" + Just (_, ps) -> ps + +sources :: [String] +sources = [ div' + , mod' + , lteq + , gteq + , neq + ] + +div' :: String +div' = "PROC / /% DROP END" + +mod' :: String +mod' = "PROC % /% SWAP DROP END" + +lteq :: String +lteq = "PROC <= OVER OVER == ROT < || END" + +gteq :: String +gteq = "PROC >= OVER OVER == ROT > || END" + +neq :: String +neq = "PROC != == ! END" + -- cgit v1.2.1