summaryrefslogtreecommitdiff
path: root/src/SPL
diff options
context:
space:
mode:
Diffstat (limited to 'src/SPL')
-rw-r--r--src/SPL/Lex.hs14
-rw-r--r--src/SPL/Syntax.hs24
2 files changed, 33 insertions, 5 deletions
diff --git a/src/SPL/Lex.hs b/src/SPL/Lex.hs
index 23a697d..1843cdd 100644
--- a/src/SPL/Lex.hs
+++ b/src/SPL/Lex.hs
@@ -22,7 +22,7 @@ data Token
| TBrackClose
| TBraceOpen
| TBraceClose
- | TDoubleColon
+ | TColonColon
| TEquals
| TSemicolon
| TDot
@@ -55,7 +55,16 @@ data Token
| TSingleComment String
| TBlockComment String
- deriving (Show)
+ deriving (Show, Eq)
+
+isCommentToken :: Token -> Bool
+isCommentToken (TSingleComment _) = True
+isCommentToken (TBlockComment _) = True
+isCommentToken _ = False
+
+isIdentToken :: Token -> Bool
+isIdentToken (TIdent _) = True
+isIdentToken _ = False
lex :: (Monad m, Alternative m) => String -> m [Token]
lex [] = pure []
@@ -110,6 +119,7 @@ lex s = (comment s <|> item s <|> int s <|> char s <|> bool s <|> ident s) >>=
item ('!':'=':s) = pure (TExclamEq, s)
item ('&':'&':s) = pure (TAmpAmp, s)
item ('|':'|':s) = pure (TPipePipe, s)
+ item (':':':':s) = pure (TColonColon, s)
item ('(':s) = pure (TParenOpen, s)
item (')':s) = pure (TParenClose, s)
item ('[':s) = pure (TBrackOpen, s)
diff --git a/src/SPL/Syntax.hs b/src/SPL/Syntax.hs
index 4b0f670..d274803 100644
--- a/src/SPL/Syntax.hs
+++ b/src/SPL/Syntax.hs
@@ -8,20 +8,32 @@ data Program = Program
{ funs :: [Function]
, vars :: [Variable]
}
+ deriving (Show)
data Function = Function
{ fname :: Name
- , ftype :: Type
+ , ftype :: Maybe Type
+ , fargs :: [Name]
+ , fvars :: [Variable]
, fcode :: Statement
}
+ deriving (Show)
data Variable = Variable
{ vname :: Name
- , vtype :: Type
+ , vtype :: Maybe Type
+ , vval :: Expression
}
+ deriving (Show)
data Type
- = Type -- TODO
+ = TInt
+ | TBool
+ | TChar
+ | TList Type
+ | TTuple Type Type
+ | TArrow [Type] Type
+ deriving (Show)
data Statement
= If Expression Statement (Maybe Statement)
@@ -30,6 +42,7 @@ data Statement
| Eval Expression
| Return (Maybe Expression)
| Seq Statement Statement
+ deriving (Show)
data Expression
= Field Name Field
@@ -38,12 +51,14 @@ data Expression
| Literal Literal
| FunCall Name [Expression]
| Tuple Expression Expression
+ deriving (Show)
data Field
= Hd
| Tl
| Fst
| Snd
+ deriving (Show)
data Op2
= Add
@@ -60,13 +75,16 @@ data Op2
| And
| Or
| Cons
+ deriving (Show)
data Op1
= Not
| Neg
+ deriving (Show)
data Literal
= LInt Int
| LChar Char
| LBool Bool
| LNil
+ deriving (Show)