-- vim: et ts=2 sw=2 ai: {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DefaultSignatures #-} module SPL.Syntax where import GHC.Generics import Data.Serialize type Name = String data Program = Program { funs :: [Function] , vars :: [Variable] } deriving (Show, Generic) data Function = Function { fname :: Name , ftype :: Maybe Type , fargs :: [Name] , fvars :: [Variable] , fcode :: Statement } deriving (Show, Generic) data Variable = Variable { vname :: Name , vtype :: Maybe Type , vval :: Expression } deriving (Show, Generic) data Type = TInt | TBool | TChar | TVoid | TList Type | TTuple Type Type | TArrow [Type] Type | TVar Name deriving (Show, Generic) data Statement = If Expression Statement (Maybe Statement) | While Expression Statement | Assign Name [Field] Expression | Eval Expression | Return (Maybe Expression) | Seq Statement Statement | Nop deriving (Show, Generic) data Expression = Var Name | Field Expression Field | Op2 Expression Op2 Expression | Op1 Op1 Expression | Literal Literal | FunCall Name [Expression] | Tuple Expression Expression deriving (Show, Generic) data Field = Hd | Tl | Fst | Snd deriving (Show, Generic) data Op2 = Add | Sub | Mul | Div | Mod | Eq | Lt | Gt | Le | Ge | Ne | And | Or | Cons deriving (Show, Generic) data Op1 = Not | Neg deriving (Show, Generic) data Literal = LInt Int | LChar Char | LBool Bool | LNil deriving (Show, Generic) instance Serialize Program instance Serialize Function instance Serialize Variable instance Serialize Type instance Serialize Statement instance Serialize Expression instance Serialize Field instance Serialize Op2 instance Serialize Op1 instance Serialize Literal