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