projects
/
kaleidoscope-hs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8a66ac4
)
Parse parentheses
author
Luke Lau
<luke_lau@icloud.com>
Sat, 18 May 2019 19:32:54 +0000
(20:32 +0100)
committer
Luke Lau
<luke_lau@icloud.com>
Sat, 18 May 2019 22:36:45 +0000
(23:36 +0100)
Yes, it's that easy. Try out the difference between
1 * 2 + 3
and
1 * (2 + 3)
AST.hs
patch
|
blob
|
history
diff --git
a/AST.hs
b/AST.hs
index 7dad3a19e91eab9f12657101bd224b5c81742d07..e491b648a7d45f7bd3b419b0e3ff6a8c215cbd83 100644
(file)
--- a/
AST.hs
+++ b/
AST.hs
@@
-13,7
+13,7
@@
data BinOp = Add | Sub | Mul | Cmp Ordering
deriving Show
instance Read Expr where
deriving Show
instance Read Expr where
- readPrec = choice [ parseNum
+ readPrec =
parens $
choice [ parseNum
, parseVar
, parseBinOp "<" 10 (Cmp LT)
, parseBinOp "+" 20 Add
, parseVar
, parseBinOp "<" 10 (Cmp LT)
, parseBinOp "+" 20 Add