module Language.Qux.Syntax where
type Id = String
newtype Program = Program [Decl]
deriving (Eq, Show)
data Decl = FunctionDecl Id [(Type, Id)] [Stmt]
deriving (Eq, Show)
name :: Decl -> Id
name (FunctionDecl n _ _) = n
types :: Decl -> [Type]
types (FunctionDecl _ ps _) = map fst ps
parameters :: Decl -> [(Type, Id)]
parameters (FunctionDecl _ ps _) = init ps
parameterNames :: Decl -> [Id]
parameterNames = (map snd) . parameters
parameterTypes :: Decl -> [Type]
parameterTypes = (map fst) . parameters
returnType :: Decl -> Type
returnType (FunctionDecl _ ps _) = fst $ last ps
stmts :: Decl -> [Stmt]
stmts (FunctionDecl _ _ ss) = ss
data Stmt = IfStmt Expr [Stmt] [Stmt]
| ReturnStmt Expr
| WhileStmt Expr [Stmt]
deriving (Eq, Show)
data Expr = ApplicationExpr Id [Expr]
| BinaryExpr BinaryOp Expr Expr
| ListExpr [Expr]
| UnaryExpr UnaryOp Expr
| ValueExpr Value
deriving (Eq, Show)
data BinaryOp = Acc
| Mul | Div | Mod
| Add | Sub
| Lt | Lte | Gt | Gte
| Eq | Neq
deriving (Eq, Show)
data UnaryOp = Len
| Neg
deriving (Eq, Show)
data Value = BoolValue Bool
| IntValue Integer
| ListValue [Value]
| NilValue
deriving (Eq, Show)
data Type = BoolType
| IntType
| ListType Type
| NilType
deriving (Eq, Show)