aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-30 21:02:24 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-30 21:02:24 +0100
commitaaf2ef628772e5789203544ac6226b467891d1d9 (patch)
tree5d3dedb1e6c6c12791f8dc5d47d6d29a3b3b0fd8
parent49940ac6b38204c4b1eb60e9dc1c553c331ac122 (diff)
downloadmicro-lang-hs-aaf2ef628772e5789203544ac6226b467891d1d9.tar.gz
micro-lang-hs-aaf2ef628772e5789203544ac6226b467891d1d9.zip
Boolean type, and true/false symbols
-rw-r--r--src/Ast.hs1
-rw-r--r--src/Compiler.hs1
-rw-r--r--src/Lexer.hs2
-rw-r--r--src/Parser.hs14
4 files changed, 17 insertions, 1 deletions
diff --git a/src/Ast.hs b/src/Ast.hs
index aa6a5c8..3d351c6 100644
--- a/src/Ast.hs
+++ b/src/Ast.hs
@@ -21,6 +21,7 @@ type FuncParam = (Ident, Type, SourcePos)
data Expr
= Num Integer SourcePos
+ | Bool' Bool SourcePos
| BinOp Op Expr Expr
| Var Ident SourcePos
| -- fn [params] return body private anomyous pos
diff --git a/src/Compiler.hs b/src/Compiler.hs
index bdbc5f3..f788c11 100644
--- a/src/Compiler.hs
+++ b/src/Compiler.hs
@@ -82,6 +82,7 @@ compile x = do
case x of
(A.Module name pos) -> return $ Right Nothing
(A.Num _ _) -> return $ Right $ Just $ A.Type "u8" -- TODO: placeholder
+ (A.Bool' _ _) -> return $ Right $ Just $ A.Type "bool"
(A.BinOp _ a b) -> do
l <- compile a
r <- compile b
diff --git a/src/Lexer.hs b/src/Lexer.hs
index 83a1391..1778b21 100644
--- a/src/Lexer.hs
+++ b/src/Lexer.hs
@@ -10,7 +10,7 @@ scanner :: T.TokenParser ()
scanner = T.makeTokenParser style
where
ops = ["+", "*", "-", ";"]
- names = ["module", "private", "def", "return", "->"]
+ names = ["module", "private", "def", "return", "->", "true", "false"]
style =
emptyDef
{ T.commentLine = "#",
diff --git a/src/Parser.hs b/src/Parser.hs
index 41f2ba3..ea698c8 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -27,6 +27,18 @@ number = do
n <- integer
return $ Num n pos
+true :: Parser Expr
+true = do
+ pos <- getPosition
+ reserved "true"
+ return $ Bool' True pos
+
+false :: Parser Expr
+false = do
+ pos <- getPosition
+ reserved "false"
+ return $ Bool' False pos
+
variable :: Parser Expr
variable = do
pos <- getPosition
@@ -107,6 +119,8 @@ call = do
factor :: Parser Expr
factor =
number
+ <|> true
+ <|> false
<|> try call
<|> try lambda
<|> try variable