improving type checking
[cc1516.git] / AST.dcl
diff --git a/AST.dcl b/AST.dcl
index 9132067..b005f62 100644 (file)
--- a/AST.dcl
+++ b/AST.dcl
@@ -1,28 +1,22 @@
 definition module AST
 
 from Data.Maybe import :: Maybe
-from StdOverloaded import class toString
-
-/*
- * Type errors can happen in either 
- * - variable declarations (x :: Int = True)
- * - function declarations (f :: (Char -> Int) = (+)1)
- * - Expressions (1 + 'a')
- * So these are the items that will get position metadata
- */
+from StdOverloaded import class toString, class ==, class zero, class <
 
 :: Pos = {line :: Int, col :: Int}
-
-:: AST = AST [VarDecl] [FunDecl]
-:: VarDecl = VarDecl Pos Type String Expr
+:: AST = AST [FunDecl]
+:: VarDecl = VarDecl Pos (Maybe Type) String Expr
+:: TVar :== String
 :: Type 
        = TupleType (Type, Type)
        | ListType Type
-       | IdType String
+       | IdType TVar 
        | IntType 
        | BoolType
        | CharType
-       | VarType
+    | VoidType
+       | FuncType Type
+    | (->>) infixl 7 Type Type
 :: Expr 
        = VarExpr Pos VarDef
        | Op2Expr Pos Expr Op2 Expr
@@ -30,23 +24,35 @@ from StdOverloaded import class toString
        | IntExpr Pos Int
        | CharExpr Pos Char
        | BoolExpr Pos Bool
-       | FunExpr Pos FunCall
+       | FunExpr Pos String [Expr] [FieldSelector]
        | EmptyListExpr Pos 
        | TupleExpr Pos (Expr, Expr)
+    | LambdaExpr Pos [String] Expr
 :: VarDef = VarDef String [FieldSelector]
 :: FieldSelector = FieldHd | FieldTl | FieldFst | FieldSnd
 :: Op1 = UnNegation | UnMinus
 :: Op2 = BiPlus | BiMinus | BiTimes | BiDivide | BiMod | BiEquals | BiLesser |
        BiGreater | BiLesserEq | BiGreaterEq | BiUnEqual | BiAnd | BiOr | BiCons
-
-:: FunDecl = FunDecl Pos String [String] (Maybe FunType) [VarDecl] [Stmt]
-:: FunType = FunType [Type] (Maybe Type)
-:: FunCall = FunCall String [Expr]
+:: FunDecl = FunDecl Pos String [String] (Maybe Type) [VarDecl] [Stmt]
 :: Stmt 
        = IfStmt Expr [Stmt] [Stmt]
        | WhileStmt Expr [Stmt]
        | AssStmt VarDef Expr
-       | FunStmt FunCall
+       | FunStmt String [Expr] [FieldSelector]
        | ReturnStmt (Maybe Expr)
 
+instance toString Pos
+instance toString Type
 instance toString AST
+instance toString FieldSelector
+instance toString Op2
+instance toString Expr
+instance toString VarDecl
+instance toString FunDecl
+
+instance zero Pos
+instance == Op1
+instance == Op2
+instance < Op1
+instance < Op2
+instance == Type