fixed mac envs
[cc1516.git] / parse.dcl
index c7d177c..281c804 100644 (file)
--- a/parse.dcl
+++ b/parse.dcl
@@ -1,8 +1,48 @@
 definition module parse
 
+from Data.Either import :: Either
+from Data.Maybe import :: Maybe
+from StdString import class toString
+
 import lex
 
-:: ParserOutput :== Either String AST
-:: AST = If | While //stub
+:: ParserOutput :== Either Error AST
+
+:: AST = AST [VarDecl] [FunDecl]
+:: VarDecl = VarDecl Type String Expr
+:: Type 
+       = TupleType (Type, Type)
+       | ListType Type
+       | IdType String
+       | IntType 
+       | BoolType
+       | CharType
+       | VarType
+:: Expr 
+       = VarExpr VarDef
+       | Op2Expr Expr Op2 Expr
+       | Op1Expr Op1 Expr
+       | IntExpr Int
+       | CharExpr Char
+       | BoolExpr Bool
+       | FunExpr FunCall
+       | EmptyListExpr
+       | TupleExpr (Expr, 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 String [String] (Maybe FunType) [VarDecl] [Stmt]
+:: FunType = FunType [Type] (Maybe Type)
+:: FunCall = FunCall String [Expr]
+:: Stmt 
+       = IfStmt Expr [Stmt] [Stmt]
+       | WhileStmt Expr [Stmt]
+       | AssStmt VarDef Expr
+       | FunStmt FunCall
+       | ReturnStmt (Maybe Expr)
+
+instance toString AST
 
-parse :: LexerOutput -> ParserOutput
+parser :: LexerOutput -> ParserOutput