91320675bcae60c1f042f88847f5662246af6e2e
[cc1516.git] / AST.dcl
1 definition module AST
2
3 from Data.Maybe import :: Maybe
4 from StdOverloaded import class toString
5
6 /*
7 * Type errors can happen in either
8 * - variable declarations (x :: Int = True)
9 * - function declarations (f :: (Char -> Int) = (+)1)
10 * - Expressions (1 + 'a')
11 * So these are the items that will get position metadata
12 */
13
14 :: Pos = {line :: Int, col :: Int}
15
16 :: AST = AST [VarDecl] [FunDecl]
17 :: VarDecl = VarDecl Pos Type String Expr
18 :: Type
19 = TupleType (Type, Type)
20 | ListType Type
21 | IdType String
22 | IntType
23 | BoolType
24 | CharType
25 | VarType
26 :: Expr
27 = VarExpr Pos VarDef
28 | Op2Expr Pos Expr Op2 Expr
29 | Op1Expr Pos Op1 Expr
30 | IntExpr Pos Int
31 | CharExpr Pos Char
32 | BoolExpr Pos Bool
33 | FunExpr Pos FunCall
34 | EmptyListExpr Pos
35 | TupleExpr Pos (Expr, Expr)
36 :: VarDef = VarDef String [FieldSelector]
37 :: FieldSelector = FieldHd | FieldTl | FieldFst | FieldSnd
38 :: Op1 = UnNegation | UnMinus
39 :: Op2 = BiPlus | BiMinus | BiTimes | BiDivide | BiMod | BiEquals | BiLesser |
40 BiGreater | BiLesserEq | BiGreaterEq | BiUnEqual | BiAnd | BiOr | BiCons
41
42 :: FunDecl = FunDecl Pos String [String] (Maybe FunType) [VarDecl] [Stmt]
43 :: FunType = FunType [Type] (Maybe Type)
44 :: FunCall = FunCall String [Expr]
45 :: Stmt
46 = IfStmt Expr [Stmt] [Stmt]
47 | WhileStmt Expr [Stmt]
48 | AssStmt VarDef Expr
49 | FunStmt FunCall
50 | ReturnStmt (Maybe Expr)
51
52 instance toString AST