X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=src%2Fparse.dcl;h=aca0ba427b456509bc41655842e4b38b008d7046;hb=b3bedf1e825aaaee9134dddc6de82b373bf8b86b;hp=3f42eda5effdfebccc321bdfb277253888c3a852;hpb=b4636110ab65f233ed40d4390b62c7799df3c949;p=cc1516.git diff --git a/src/parse.dcl b/src/parse.dcl index 3f42eda..aca0ba4 100644 --- a/src/parse.dcl +++ b/src/parse.dcl @@ -5,36 +5,43 @@ from Data.Maybe import :: Maybe import lex -:: ParserOutput :== Either String AST +:: ParserOutput :== Either Error AST :: AST = AST [VarDecl] [FunDecl] -:: VarDecl = VarDecl String Type Expr +:: VarDecl = VarDecl Type String Expr :: Type - = TupleType Type Type + = TupleType (Type, Type) | ListType Type | IdType String | IntType | BoolType | CharType | VarType - :: Expr - = VarExpr String (Maybe FieldSelector) - | Op2Expr Expr Op2 Expr //TODO, iets met associativiteit wat niet weet hoe + = VarExpr VarDef + | Op2Expr Expr Op2 Expr | Op1Expr Op1 Expr | IntExpr Int | CharExpr Char | BoolExpr Bool + | FunExpr FunCall | EmptyListExpr - | TupleExpr Expr Expr - + | 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 - -//TODO - -:: FunDecl = Stub - -parse :: LexerOutput -> ParserOutput +:: 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 + +parser :: LexerOutput -> ParserOutput