1
+ module Normal.Ast
2
+
3
+ type Program = Declaration list
4
+
5
+ and Declaration =
6
+ | StaticVariableDeclaration of VariableDeclaration
7
+ | FunctionDeclaration of FunctionDeclaration
8
+
9
+ and TypeSpec =
10
+ | Void
11
+ | Bool
12
+ | Int
13
+ | Float
14
+ override x.ToString () =
15
+ match x with
16
+ | Void -> " void"
17
+ | Bool -> " bool"
18
+ | Int -> " int"
19
+ | Float -> " float"
20
+
21
+ and VariableDeclaration =
22
+ | ScalarVariableDeclaration of TypeSpec * Identifier
23
+ | ArrayVariableDeclaration of TypeSpec * Identifier
24
+
25
+ and FunctionDeclaration = TypeSpec * Identifier * Parameters * CompoundStatement
26
+
27
+ and Identifier = string
28
+
29
+ and Parameters = VariableDeclaration list
30
+
31
+ and IdentifierRef = { Identifier : string ; }
32
+
33
+ and Statement =
34
+ | ExpressionStatement of ExpressionStatement
35
+ | CompoundStatement of CompoundStatement
36
+ | IfStatement of IfStatement
37
+ | WhileStatement of WhileStatement
38
+ | ReturnStatement of Expression option
39
+ | BreakStatement
40
+
41
+ and ExpressionStatement =
42
+ | Expression of Expression
43
+ | Nop
44
+
45
+ and CompoundStatement = LocalDeclarations * Statement list
46
+
47
+ and LocalDeclarations = VariableDeclaration list
48
+
49
+ and IfStatement = Expression * Statement * Statement option
50
+
51
+ and WhileStatement = Expression * Statement
52
+
53
+ and Expression =
54
+ | ScalarAssignmentExpression of IdentifierRef * Expression
55
+ | ArrayAssignmentExpression of IdentifierRef * Expression * Expression
56
+ | BinaryExpression of Expression * BinaryOperator * Expression
57
+ | UnaryExpression of UnaryOperator * Expression
58
+ | IdentifierExpression of IdentifierRef
59
+ | ArrayIdentifierExpression of IdentifierRef * Expression
60
+ | FunctionCallExpression of Identifier * Arguments
61
+ | ArraySizeExpression of IdentifierRef
62
+ | LiteralExpression of Literal
63
+ | ArrayAllocationExpression of TypeSpec * Expression
64
+
65
+ and BinaryOperator =
66
+ | ConditionalOr
67
+ | Equal
68
+ | NotEqual
69
+ | LessEqual
70
+ | Less
71
+ | GreaterEqual
72
+ | Greater
73
+ | ConditionalAnd
74
+ | Add
75
+ | Subtract
76
+ | Multiply
77
+ | Divide
78
+ | Modulus
79
+ override x.ToString () =
80
+ match x with
81
+ | ConditionalOr -> " ||"
82
+ | Equal -> " =="
83
+ | NotEqual -> " !="
84
+ | LessEqual -> " <="
85
+ | Less -> " <"
86
+ | GreaterEqual -> " >="
87
+ | Greater -> " >"
88
+ | ConditionalAnd -> " &&"
89
+ | Add -> " +"
90
+ | Subtract -> " -"
91
+ | Multiply -> " *"
92
+ | Divide -> " /"
93
+ | Modulus -> " %"
94
+
95
+ and UnaryOperator =
96
+ | LogicalNegate
97
+ | Negate
98
+ | Identity
99
+
100
+ and Arguments = Expression list
101
+
102
+ and Literal =
103
+ | BoolLiteral of bool
104
+ | IntLiteral of int
105
+ | FloatLiteral of float
106
+ override x.ToString () =
107
+ match x with
108
+ | BoolLiteral( b) -> b.ToString()
109
+ | IntLiteral( i) -> i.ToString()
110
+ | FloatLiteral( f) -> f.ToString()
0 commit comments