projects
/
kaleidoscope-hs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Begin codegen
[kaleidoscope-hs.git]
/
AST.hs
diff --git
a/AST.hs
b/AST.hs
index 7dad3a19e91eab9f12657101bd224b5c81742d07..dfa43b7c60c0d0ced86a73268167b1b9584b9d74 100644
(file)
--- a/
AST.hs
+++ b/
AST.hs
@@
-4,17
+4,19
@@
import Data.Char
import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
-data Expr = Num
Float
+data Expr = Num
Double
| Var String
| BinOp BinOp Expr Expr
| Var String
| BinOp BinOp Expr Expr
+ | Call String [Expr]
deriving Show
data BinOp = Add | Sub | Mul | Cmp Ordering
deriving Show
instance Read Expr where
deriving Show
data BinOp = Add | Sub | Mul | Cmp Ordering
deriving Show
instance Read Expr where
- readPrec = choice [ parseNum
+ readPrec =
parens $
choice [ parseNum
, parseVar
, parseVar
+ , parseCall
, parseBinOp "<" 10 (Cmp LT)
, parseBinOp "+" 20 Add
, parseBinOp "-" 20 Sub
, parseBinOp "<" 10 (Cmp LT)
, parseBinOp "+" 20 Add
, parseBinOp "-" 20 Sub
@@
-30,6
+32,12
@@
instance Read Expr where
skipSpaces
b <- readPrec
return (BinOp op a b)
skipSpaces
b <- readPrec
return (BinOp op a b)
+ parseCall = do
+ func <- lift (munch1 isAlpha)
+ params <- lift $ between (char '(') (char ')') $
+ sepBy (readS_to_P reads)
+ (skipSpaces >> char ',' >> skipSpaces)
+ return (Call func params)
data Prototype = Prototype String [String]
deriving Show
data Prototype = Prototype String [String]
deriving Show