projects
/
kaleidoscope-hs-old.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(initial)
Begin parsing addition
author
Luke Lau
<luke_lau@icloud.com>
Sun, 10 Mar 2019 01:18:24 +0000
(
01:18
+0000)
committer
Luke Lau
<luke_lau@icloud.com>
Wed, 17 Apr 2019 22:38:28 +0000
(23:38 +0100)
AST.hs
[new file with mode: 0644]
patch
|
blob
diff --git a/AST.hs
b/AST.hs
new file mode 100644
(file)
index 0000000..
6528215
--- /dev/null
+++ b/
AST.hs
@@ -0,0
+1,20
@@
+module AST where
+
+import Text.Read
+import Text.ParserCombinators.ReadP hiding ((+++))
+
+data Expr = Num Float
+ | Add Expr Expr
+ deriving Show
+
+instance Read Expr where
+ readPrec = parseNum +++ parseAdd
+ where parseNum = Num <$> readPrec
+ parseAdd = step $ do
+ a <- prec 11 readPrec
+ lift $ do
+ skipSpaces
+ char '+'
+ skipSpaces
+ b <- readPrec
+ return (Add a b)