From e9fa657f1ea66a759f4eae7e58d46a1870c8783a Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sat, 1 Dec 2018 16:17:02 +0000 Subject: [PATCH] Fix not --- Main.hs | 3 ++- Programs.hs | 3 +++ boolNot.prog | 1 + fibonacci.prog | 1 + ttdb.cabal | 2 +- 5 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 boolNot.prog create mode 100644 fibonacci.prog diff --git a/Main.hs b/Main.hs index ce81efb..951f388 100644 --- a/Main.hs +++ b/Main.hs @@ -70,7 +70,7 @@ eval (Div e0 e1) = evali div e0 e1 eval (And e0 e1) = evalb (&&) e0 e1 eval (Or e0 e1) = evalb (||) e0 e1 -eval (Not e0 ) = evalb (const not) e0 (Const (B True)) +eval (Not e) = evalb (const not) (Const (B True)) e eval (Eq e0 e1) = evalib (==) e0 e1 eval (Gt e0 e1) = evalib (>) e0 e1 @@ -155,6 +155,7 @@ menu = do "r increment" -> debugProg increment "r tryCatch" -> debugProg tryCatch "r fibonacci" -> debugProg fibonacci + "r boolNot" -> debugProg boolNot ('r':' ':file) -> read <$> readFile file >>= debugProg x -> printUnknown x >> menu diff --git a/Programs.hs b/Programs.hs index 14f066b..3f05aaa 100644 --- a/Programs.hs +++ b/Programs.hs @@ -24,3 +24,6 @@ fibonacci = Seq (Assign "n" (Const (I 5))) (Seq (Assign "x" (Add (Var "x") (Var "y"))) (Seq (Assign "y" (Var "x")) (Assign "n" (Sub (Var "n") (Const (I 1)))))))))) + +boolNot :: Statement +boolNot = Print (Not (Const (B False))) diff --git a/boolNot.prog b/boolNot.prog new file mode 100644 index 0000000..588a57e --- /dev/null +++ b/boolNot.prog @@ -0,0 +1 @@ +Print !False \ No newline at end of file diff --git a/fibonacci.prog b/fibonacci.prog new file mode 100644 index 0000000..501caf8 --- /dev/null +++ b/fibonacci.prog @@ -0,0 +1 @@ +Seq (Assign "n" 5) (Seq (Assign "x" 1) (Seq (Assign "y" 0) (While n > 0 (Seq (Assign "tmp" x) (Seq (Assign "x" x + y) (Seq (Assign "y" x) (Assign "n" n - 1))))))) \ No newline at end of file diff --git a/ttdb.cabal b/ttdb.cabal index de59cfa..ff83079 100644 --- a/ttdb.cabal +++ b/ttdb.cabal @@ -7,7 +7,7 @@ author: Luke Lau maintainer: luke_lau@icloud.com category: Development build-type: Simple -extra-source-files: stack.yaml, README.md +extra-source-files: stack.yaml, README.md, *.prog cabal-version: >=1.10 executable ttdb -- 2.30.2