MiniJavaCompiler/src/Ast.hs

66 lines
1.8 KiB
Haskell
Raw 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-05-07 09:04:40 +00:00
type Identifier = String
data ParameterDeclaration = ParameterDeclaration DataType Identifier deriving (Show)
data VariableDeclaration = VariableDeclaration DataType Identifier (Maybe Expression) deriving (Show)
data Class = Class DataType [MethodDeclaration] [VariableDeclaration] deriving (Show)
data MethodDeclaration = MethodDeclaration DataType Identifier [ParameterDeclaration] Statement deriving (Show)
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
deriving (Show)
2024-05-05 08:00:11 +00:00
data StatementExpression
= Assignment Identifier Expression
| ConstructorCall DataType [Expression]
2024-05-07 09:09:10 +00:00
| MethodCall Expression Identifier [Expression]
2024-05-05 08:00:11 +00:00
| TypedStatementExpression DataType StatementExpression
deriving (Show)
2024-05-05 08:00:11 +00:00
data BinaryOperator
= Addition
| Subtraction
| Multiplication
| Division
2024-05-13 11:13:24 +00:00
| Modulus
2024-05-05 08:00:11 +00:00
| BitwiseAnd
| BitwiseOr
| BitwiseXor
| CompareLessThan
| CompareLessOrEqual
| CompareGreaterThan
| CompareGreaterOrEqual
| CompareEqual
| CompareNotEqual
| And
| Or
| NameResolution
deriving (Show)
2024-05-05 08:00:11 +00:00
data UnaryOperator
= Not
| Minus
deriving (Show)
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
| StatementExpressionExpression StatementExpression
| TypedExpression DataType Expression
deriving (Show)