From 8d8bc0603478481851f2bb8e5d250b260f65a509 Mon Sep 17 00:00:00 2001 From: mrab Date: Thu, 2 May 2024 13:44:02 +0200 Subject: [PATCH] AST --- src/Ast.hs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Ast.hs diff --git a/src/Ast.hs b/src/Ast.hs new file mode 100644 index 0000000..c48074d --- /dev/null +++ b/src/Ast.hs @@ -0,0 +1,51 @@ +module Ast where + +type CompilationUnit = [Class] +type DataType = String +type Identifier = String + +data ParameterDeclaration = ParameterDeclaration DataType Identifier +data VariableDeclaration = VariableDeclaration DataType Identifier (Maybe Expression) +data Class = Class DataType [MethodDeclaration] [VariableDeclaration] +data MethodDeclaration = MethodDeclaration DataType Identifier [ParameterDeclaration] Statement + +data Statement = If Expression Statement (Maybe Statement) + | LocalVariableDeclaration VariableDeclaration + | While Expression Statement + | Block [Statement] + | Return (Maybe Expression) + | StatementExpressionStatement StatementExpression + +data StatementExpression = Assignment Identifier Expression + | ConstructorCall DataType [Expression] + | MethodCall Identifier [Expression] + +data BinaryOperator = Addition + | Subtraction + | Multiplication + | Division + | BitwiseAnd + | BitwiseOr + | BitwiseXor + | CompareLessThan + | CompareLessOrEqual + | CompareGreaterThan + | CompareGreaterOrEqual + | CompareEqual + | CompareNotEqual + | And + | Or + | NameResolution + +data UnaryOperator = Not + | Minus + +data Expression = IntegerLiteral Int + | CharacterLiteral Char + | BooleanLiteral Bool + | NullLiteral + | Reference Identifier + | BinaryOperation BinaryOperator Expression Expression + | UnaryOperation UnaryOperator Expression + | StatementExpressionExpression StatementExpression + \ No newline at end of file