aboutsummaryrefslogtreecommitdiff
path: root/Sjit/Syntax.icl
diff options
context:
space:
mode:
authorCamil Staps2018-12-25 01:54:02 +0100
committerCamil Staps2018-12-25 01:54:02 +0100
commitf8c9564372709e0634c9eb0c208ec9cc31a93de7 (patch)
tree4092e07b7e341150639491f2b0b4c32a65be2be3 /Sjit/Syntax.icl
parentBetter use of monads (diff)
Add if construct; fib example
Diffstat (limited to 'Sjit/Syntax.icl')
-rw-r--r--Sjit/Syntax.icl7
1 files changed, 6 insertions, 1 deletions
diff --git a/Sjit/Syntax.icl b/Sjit/Syntax.icl
index 7412d7c..90aeb39 100644
--- a/Sjit/Syntax.icl
+++ b/Sjit/Syntax.icl
@@ -16,6 +16,8 @@ import Text.Parsers.Simple.Core
| TTrue
| TFalse
+ | TIf
+
| TEq
| TComma
@@ -32,6 +34,7 @@ where
TInt n -> toString n
TTrue -> "True"
TFalse -> "False"
+ TIf -> "if"
TEq -> "="
TComma -> ","
TParenOpen -> "("
@@ -51,6 +54,7 @@ where
# tk = case n of
"True" -> TTrue
"False" -> TFalse
+ "if" -> TIf
n -> TIdent n
-> lex [tk:tks] i e s
@@ -112,7 +116,8 @@ where
noInfix :: Parser Token Expr
noInfix =
- liftM2 App ident (pToken TParenOpen *> pSepBy expr (pToken TComma) <* pToken TParenClose)
+ liftM2 App ident (pToken TParenOpen *> pSepBy expr (pToken TComma) <* pToken TParenClose)
+ <|> liftM3 If (pToken TIf *> expr) expr expr
<|> Var <$> ident
<|> Int <$> int
<|> Bool <$> bool