From: Luke Lau Date: Sat, 18 May 2019 19:32:54 +0000 (+0100) Subject: Parse parentheses X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs.git;a=commitdiff_plain;h=2f3c8f5cb6c8b9e6f5be02b20910f8105a9011a6;hp=8a66ac4f81c3d1eab3b13a9e58cee0098573eff1 Parse parentheses Yes, it's that easy. Try out the difference between 1 * 2 + 3 and 1 * (2 + 3) --- diff --git a/AST.hs b/AST.hs index 7dad3a1..e491b64 100644 --- a/AST.hs +++ b/AST.hs @@ -13,7 +13,7 @@ data BinOp = Add | Sub | Mul | Cmp Ordering deriving Show instance Read Expr where - readPrec = choice [ parseNum + readPrec = parens $ choice [ parseNum , parseVar , parseBinOp "<" 10 (Cmp LT) , parseBinOp "+" 20 Add