MiniJavaCompiler/src/Ast.hs

72 lines
2.0 KiB
Haskell
Raw Permalink Normal View History

2024-05-02 11:44:02 +00:00
module Ast where
2024-05-07 09:04:40 +00:00
type CompilationUnit = [Class]
2024-05-02 11:44:02 +00:00
type DataType = String
2024-06-21 06:49:55 +00:00
type Identifier = String
2024-05-02 11:44:02 +00:00
2024-05-07 19:18:01 +00:00
data ParameterDeclaration = ParameterDeclaration DataType Identifier deriving (Show, Eq)
data VariableDeclaration = VariableDeclaration DataType Identifier (Maybe Expression) deriving (Show, Eq)
data Class = Class DataType [ConstructorDeclaration] [MethodDeclaration] [VariableDeclaration] deriving (Show, Eq)
2024-05-07 19:18:01 +00:00
data MethodDeclaration = MethodDeclaration DataType Identifier [ParameterDeclaration] Statement deriving (Show, Eq)
2024-06-26 15:58:52 +00:00
data ConstructorDeclaration = ConstructorDeclaration Identifier [ParameterDeclaration] Statement deriving (Show, Eq)
2024-05-02 11:44:02 +00:00
2024-05-05 08:00:11 +00:00
data Statement
= If Expression Statement (Maybe Statement)
| LocalVariableDeclaration VariableDeclaration
| While Expression Statement
| Block [Statement]
| Return (Maybe Expression)
| StatementExpressionStatement StatementExpression
| TypedStatement DataType Statement
2024-05-07 19:18:01 +00:00
deriving (Show, Eq)
2024-05-05 08:00:11 +00:00
data StatementExpression
= Assignment Expression Expression
2024-05-05 08:00:11 +00:00
| ConstructorCall DataType [Expression]
2024-05-07 09:09:10 +00:00
| MethodCall Expression Identifier [Expression]
| PostIncrement Expression
| PostDecrement Expression
| PreIncrement Expression
| PreDecrement Expression
2024-06-24 09:28:57 +00:00
| TypedStatementExpression DataType StatementExpression
2024-05-07 19:18:01 +00:00
deriving (Show, Eq)
2024-05-05 08:00:11 +00:00
data BinaryOperator
= Addition
| Subtraction
| Multiplication
| Division
| Modulo
2024-05-05 08:00:11 +00:00
| BitwiseAnd
| BitwiseOr
| BitwiseXor
| CompareLessThan
| CompareLessOrEqual
| CompareGreaterThan
| CompareGreaterOrEqual
| CompareEqual
| CompareNotEqual
| And
| Or
| NameResolution
2024-05-07 19:18:01 +00:00
deriving (Show, Eq)
2024-05-05 08:00:11 +00:00
data UnaryOperator
= Not
| Minus
2024-05-07 19:18:01 +00:00
deriving (Show, Eq)
2024-05-05 08:00:11 +00:00
data Expression
= IntegerLiteral Int
| CharacterLiteral Char
| BooleanLiteral Bool
| NullLiteral
| Reference Identifier
2024-05-08 08:26:19 +00:00
| LocalVariable Identifier
| FieldVariable Identifier
2024-05-05 08:00:11 +00:00
| BinaryOperation BinaryOperator Expression Expression
| UnaryOperation UnaryOperator Expression
2024-05-05 08:00:11 +00:00
| StatementExpressionExpression StatementExpression
| TypedExpression DataType Expression
2024-05-07 19:18:01 +00:00
deriving (Show, Eq)