-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.ts
142 lines (123 loc) · 3.01 KB
/
ast.ts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
export type NodeTypes =
| 'BinaryExpression'
| 'NumberLiteral'
| 'Identifier'
| 'AssignmentExpression'
| 'UnaryExpression'
| 'Program'
| 'CallExpression'
| 'FunctionDeclaration'
| 'PrintStatement'
| 'IntegerVariableDeclaration'
| 'RealVariableDeclaration'
| 'StringVariableDeclaration'
| 'BooleanVariableDeclaration'
| 'ConstantVariableDeclaration'
| 'StringLiteral'
| 'BooleanLiteral'
| 'IfStatement'
| 'CaseStatement'
| 'SwitchStatement'
| 'ReadInputStatement'
| 'ForStatement'
| 'WhileStatement'
| 'DoWhileStatement'
| 'FunctionDeclaration'
| 'FunctionCall'
| 'StartStatement'
| 'ProcedureDeclaration'
| 'ProcedureCall';
export interface Statement {
type: NodeTypes;
}
export interface Program extends Statement {
type: 'Program';
body: Statement[];
functions: Map<string, FunctionDeclaration>;
procedures: Map<string, ProcedureDeclaration>;
}
export interface FunctionDeclaration extends Statement {
type: 'FunctionDeclaration';
name: string;
body: Statement[];
returnType: string;
arguments: string[];
}
export interface Expression extends Statement {}
export interface BinaryExpression extends Expression {
type: 'BinaryExpression';
operator: string;
left: Expression;
right: Expression;
}
export interface Identifier extends Expression {
type: 'Identifier';
name: string;
}
export interface NumericLiteral extends Expression {
type: 'NumberLiteral';
value: number;
}
export interface StringLiteral extends Expression {
type: 'StringLiteral';
value: string;
}
export interface AssignmentExpression extends Statement {
type: 'AssignmentExpression';
identifier: Identifier;
value: Expression;
}
export interface UnaryExpression extends Expression {
type: 'UnaryExpression';
operator: string;
right: Expression;
}
export interface BooleanLiteral extends Expression {
type: 'BooleanLiteral';
value: boolean;
}
export interface IfStatement extends Statement {
type: 'IfStatement';
condition: Expression;
consequent: Statement;
alternate?: Statement;
}
export interface CaseStatement extends Statement {
type: 'CaseStatement';
test: Expression;
consequent: Statement[];
}
export interface SwitchStatement extends Statement {
type: 'SwitchStatement';
discriminant: Expression;
cases: CaseStatement[];
}
export interface ForStatement extends Statement {
type: 'ForStatement';
identifier: Identifier;
start: NumericLiteral;
end: NumericLiteral;
step: NumericLiteral;
body: Statement[];
}
export interface WhileStatement extends Statement {
type: 'WhileStatement';
condition: Expression;
body: Statement[];
}
export interface DoWhileStatement extends Statement {
type: 'DoWhileStatement';
condition: Expression;
body: Statement[];
}
export interface ProcedureDeclaration extends Statement {
type: 'ProcedureDeclaration';
name: string;
body: Statement[];
arguments: string[];
}
export interface ProcedureCall extends Statement {
type: 'ProcedureCall';
identifier: string;
arguments: Identifier[];
}