-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.txt
More file actions
243 lines (189 loc) · 11.5 KB
/
grammar.txt
File metadata and controls
243 lines (189 loc) · 11.5 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
% Official Wickit Language Grammar
INCLUDE "symbol/locator.h";
INCLUDE "ast/include.h";
USING "wckt::ast";
START #TranslationUnit;
% General Rules ----------------------------------------------------------------------------------------------------------------------------------
#TranslationUnit -> #ImportStatement #TranslationUnit; { $1->insertImportStatement($0); return $1; }
#TranslationUnit -> #DeclarationSet; { return $NEW($0); }
#ImportStatement -> $KEYW_IMPORT #StaticSymbol #ImportSuffix $DELIM_SEMICOLON; { return $NEW($1->get(), $2 != $NULL); }
#ImportStatement -> $KEYW_IMPORT $ERROR $DELIM_SEMICOLON;
#ImportSuffix -> $DELIM_DOT $OPERATOR_MUL; { return $NEW(); }
#ImportSuffix -> ; { return $NULL; }
#DeclarationSet -> #DeclarationSet #Declaration; { $0->addDeclaration($1); return $0; }
#DeclarationSet -> #DeclarationSet $ERROR; { return $0; }
#DeclarationSet -> ; { return $NEW(); }
TYPEOF #ImportSuffix "DummyObject";
% Static Declarations ----------------------------------------------------------------------------------------------------------------------------
#Declaration -> #NamespaceDeclaration; { return $0; }
#Declaration -> #TypeDeclaration; { return $0; }
#Declaration -> #PropertyDeclaration { return $0; }
#NamespaceDeclaration -> $KEYW_NAMESPACE #Identifier $DELIM_LBRACE
#DeclarationSet $DELIM_RBRACE; { return $NEW($1->get(), $3); }
#NamespaceDeclaration -> $KEYW_NAMESPACE $ERROR $DELIM_LBRACE
#DeclarationSet $DELIM_RBRACE; { return $NEW("?", $3); }
#TypeDeclaration -> $KEYW_TYPE #Identifier #OptionalGenericTypeDeclarator
$KEYW_AS #Type $DELIM_SEMICOLON; { return $NEW($1->get(), $2, $4); }
#TypeDeclaration -> $KEYW_TYPE $ERROR $DELIM_SEMICOLON; { return $NULL; }
#PropertyDeclaration -> #Declarator $DELIM_SEMICOLON;
% Type Expressions -------------------------------------------------------------------------------------------------------------------------------
#Type -> #TypeUnion; { return $0; }
#TypeUnion -> #TypeIntersection $OPERATOR_OR #TypeUnion; { return $NEWOF(UnionExpression, $0, $2); }
#TypeUnion -> #TypeIntersection; { return $0; }
#TypeIntersection -> #FunctionType $OPERATOR_AND #TypeIntersection; { return $NEWOF(IntersectExpression, $0, $2); }
#TypeIntersection -> #FunctionType; { return $0; }
#FunctionType -> #GenericTypeDeclarator $DELIM_LPAREN #OptionalTypeList
$DELIM_RPAREN $OPERATOR_ARROW #ReturnPostfixType; { return $NEWOF(FunctionType, $0, $2->get(), $5); }
#FunctionType -> $DELIM_LPAREN #OptionalTypeList $DELIM_RPAREN
$OPERATOR_ARROW #ReturnPostfixType; { return $NEWOF(FunctionType, $NULL, $1->get(), $4); }
#FunctionType -> #PostfixType $OPERATOR_ARROW #ReturnPostfixType; { std::vector<UPTR(TypeExpression)> vec; vec.push_back($0);
return $NEWOF(FunctionType, $NULL, vec, $2); }
#FunctionType -> #PostfixType; { return $0; }
#PostfixType -> #UnitType $DELIM_LBRACKET $DELIM_RBRACKET; { return $NEWOF(ArrayPostfixExpression, $0); }
#PostfixType -> #UnitType $OPERATOR_OPTIONAL; { return $NEWOF(OptionalPostfixExpression, $0); }
#PostfixType -> #UnitType; { return $0; }
#UnitType -> #StaticSymbol #GenericTypeSpecifier; { return $NEWOF(TypeReference, $0->get(), $1); }
#UnitType -> #StaticSymbol; { return $NEWOF(TypeReference, $0->get(), $NULL); }
#UnitType -> $DELIM_LPAREN #Type $DELIM_RPAREN; { return $1; }
#UnitType -> $DELIM_LPAREN $ERROR $DELIM_RPAREN; { return $NEWOF(ErrorType); }
#GenericTypeDeclarator -> $OPERATOR_LESS #GenericTypeDeclaratorImpl $OPERATOR_GREATER; { return $1; }
#GenericTypeDeclaratorImpl -> #GenericType $DELIM_COMMA #GenericTypeDeclaratorImpl; { $2->insertType($0); return $2; }
#GenericTypeDeclaratorImpl -> #GenericType; { return $NEW($0); }
#OptionalGenericTypeDeclarator -> #GenericTypeDeclarator; { return $0; }
#OptionalGenericTypeDeclarator -> ; { return $NULL; }
#GenericType -> #Identifier; { return $NEW($0->get(), $NULL); }
#GenericType -> #Identifier $KEYW_SATISFIES #Type; { return $NEW($0->get(), $2); }
#GenericTypeSpecifier -> $OPERATOR_LESS #OptionalTypeList $OPERATOR_GREATER; { return $NEW($1->get()); }
#OptionalGenericTypeSpecifier -> #GenericTypeSpecifier; { return $0; }
#OptionalGenericTypeSpecifier -> ; { return $NULL; }
#ReturnType -> #Type; { return $0; }
#ReturnType -> $KEYW_VOID; { return $NULL; }
#ReturnPostfixType -> #PostfixType; { return $0; }
#ReturnPostfixType -> $KEYW_VOID; { return $NULL; }
TYPEOF #Type "TypeExpression";
TYPEOF #TypeUnion "TypeExpression";
TYPEOF #TypeIntersection "TypeExpression";
TYPEOF #FunctionType "TypeExpression";
TYPEOF #PostfixType "TypeExpression";
TYPEOF #UnitType "TypeExpression";
TYPEOF #GenericTypeDeclaratorImpl "GenericTypeDeclarator";
TYPEOF #OptionalGenericTypeDeclarator "GenericTypeDeclarator";
TYPEOF #OptionalGenericTypeSpecifier "GenericTypeSpecifier";
TYPEOF #PostfixType "TypeExpression";
TYPEOF #ReturnPostfixType "TypeExpression";
% Expressions ------------------------------------------------------------------------------------------------------------------------------------
#Expression -> #Expression1 $OPERATOR_ASSIGN #Expression;
#Expression -> #Expression1 $OPERATOR_OTHER_ASSIGN #Expression;
#Expression -> #Expression1;
#Expression1 -> #Expression2 $OPERATOR_OPTIONAL #Expression $DELIM_COLON #Expression1;
#Expression1 -> #Expression2;
#Expression2 -> #Expression2 $OPERATOR_LAZY_OR #Expression3;
#Expression2 -> #Expression3;
#Expression3 -> #Expression3 $OPERATOR_LAZY_AND #Expression4;
#Expression3 -> #Expression4;
#Expression4 -> #Expression4 $OPERATOR_OR #Expression5;
#Expression4 -> #Expression5;
#Expression5 -> #Expression5 $OPERATOR_XOR #Expression6;
#Expression5 -> #Expression6;
#Expression6 -> #Expression6 $OPERATOR_AND #Expression7;
#Expression6 -> #Expression7;
#Expression7 -> #Expression7 $OPERATOR_EQUALS #Expression8;
#Expression7 -> #Expression7 $OPERATOR_NOT_EQUALS #Expression8;
#Expression7 -> #Expression7 $OPERATOR_STRICT_EQUALS #Expression8;
#Expression7 -> #Expression7 $OPERATOR_STRICT_NOT_EQUALS #Expression8;
#Expression7 -> #Expression8;
#Expression8 -> #Expression8 $OPERATOR_GREATER #Expression9;
#Expression8 -> #Expression8 $OPERATOR_LESS #Expression9;
#Expression8 -> #Expression8 $OPERATOR_GREATER_OR_EQUAL #Expression9;
#Expression8 -> #Expression8 $OPERATOR_LESS_OR_EQUAL #Expression9;
#Expression8 -> #Expression8 $KEYW_SATISFIES #PostfixType;
#Expression8 -> #Expression9;
#Expression9 -> #Expression9 $OPERATOR_SHL #Expression10;
#Expression9 -> #Expression9 $OPERATOR_SHR #Expression10;
#Expression9 -> #Expression10;
#Expression10 -> #Expression10 $OPERATOR_ADD #Expression11;
#Expression10 -> #Expression10 $OPERATOR_SUB #Expression11;
#Expression10 -> #Expression11;
#Expression11 -> #Expression11 $OPERATOR_MUL #Expression12;
#Expression11 -> #Expression11 $OPERATOR_DIV #Expression12;
#Expression11 -> #Expression11 $OPERATOR_MOD #Expression12;
#Expression11 -> #Expression12;
#Expression12 -> $DELIM_LPAREN #Type $DELIM_RPAREN #Expression12;
#Expression12 -> #Expression13;
#Expression13 -> $OPERATOR_ADD #Expression13;
#Expression13 -> $OPERATOR_SUB #Expression13;
#Expression13 -> $OPERATOR_BITWISE_NOT #Expression13;
#Expression13 -> $OPERATOR_LOGICAL_NOT #Expression13;
#Expression13 -> $OPERATOR_INC #Expression13;
#Expression13 -> $OPERATOR_DEC #Expression13;
#Expression13 -> #Expression14;
#Expression14 -> #Expression14 $OPERATOR_INC;
#Expression14 -> #Expression14 $OPERATOR_DEC;
#Expression14 -> #Expression15;
#Expression15 -> #Expression15 $DELIM_DOT #Identifier;
#Expression15 -> #Expression15 #OptionalGenericTypeSpecifier $DELIM_LPAREN
#OptionalExpressionList $DELIM_RPAREN;
#Expression15 -> #Expression15 $DELIM_LBRACKET #OptionalExpressionList $DELIM_RBRACKET;
#Expression15 -> #Expression16;
#Expression16 -> $DELIM_LPAREN #Expression $DELIM_RPAREN;
#Expression16 -> $DELIM_LPAREN $ERROR $DELIM_RPAREN;
#Expression16 -> $KEYW_THIS;
#Expression16 -> $INT_LITERAL;
#Expression16 -> $FLOAT_LITERAL;
#Expression16 -> $BOOL_LITERAL;
#Expression16 -> $CHARACTER_LITERAL;
#Expression16 -> $STRING_LITERAL;
#Expression16 -> #Identifier;
#Expression16 -> $DELIM_LBRACKET #OptionalExpressionList $DELIM_RBRACKET;
#Expression16 -> $DELIM_LBRACE #ObjectDeclarationSet $DELIM_RBRACE;
#Expression16 -> #ConstructorInvocation;
#Expression16 -> #AnonymousFunction;
#Expression16 -> #ArrowFunction;
#ObjectDeclarationSet -> #ObjectDeclarationSet #ObjectDeclaration;
#ObjectDeclarationSet -> ;
#ObjectDeclaration -> #Initializer $DELIM_SEMICOLON;
#ConstructorInvocation -> $KEYW_NEW #StaticSymbol #OptionalGenericTypeSpecifier
$DELIM_LPAREN #OptionalExpressionList $DELIM_RPAREN;
#ConstructorInvocation -> $KEYW_NEW #StaticSymbol #OptionalGenericTypeSpecifier;
#AnonymousFunction -> $KEYW_FUNCTION #Identifier #OptionalGenericTypeDeclarator
$DELIM_LPAREN #OptionalParameterList $DELIM_RPAREN
#AnonymousFunctionReturn $DELIM_LBRACE $DELIM_RBRACE;
#AnonymousFunctionReturn -> $DELIM_COLON #ReturnType;
#AnonymousFunctionReturn -> ;
#ArrowFunction -> #OptionalGenericTypeDeclarator $DELIM_LPAREN #OptionalParameterList
$DELIM_RPAREN #ArrowFunctionReturn #ArrowFunctionRest;
#ArrowFunction -> #Identifier #ArrowFunctionRest;
#ArrowFunctionReturn -> $DELIM_COLON #ReturnPostfixType;
#ArrowFunctionReturn -> ;
#ArrowFunctionRest -> $OPERATOR_ARROW #Expression;
#ArrowFunctionRest -> $OPERATOR_ARROW $DELIM_LBRACE $DELIM_RBRACE;
% Miscellanious Rules ----------------------------------------------------------------------------------------------------------------------------
#StaticSymbol -> #StaticSymbol $DELIM_DOT #Identifier; { return $NEW($0->get() + $2->get()); }
#StaticSymbol -> #Identifier; { return $NEW($0->get()); }
#Identifier -> $IDENTIFIER; { return $NEW($0->get().getValue()); }
#Identifier -> $NO_NAME; { return $NEW("---"); }
#TypeList -> #Type $DELIM_COMMA #TypeList; { $2->get().insert($2->get().begin(), $0); return $2; }
PRECEDENCE LOW
#TypeList -> #Type; { std::vector<UPTR(TypeExpression)> vec;
vec.push_back($0); return $NEW(std::move(vec)); }
#OptionalTypeList -> #TypeList; { return $0; }
#OptionalTypeList -> ; { return $NEW(std::vector<UPTR(TypeExpression)>()); }
#ExpressionList -> #Expression $DELIM_COMMA #ExpressionList;
#ExpressionList -> #Expression;
#OptionalExpressionList -> #ExpressionList;
#OptionalExpressionList -> ;
#Parameter -> #Identifier $DELIM_COLON #Type;
#Parameter -> #Identifier;
#Declarator -> #Identifier $DELIM_COLON #Type $OPERATOR_ASSIGN #Expression;
#Declarator -> #Identifier $DELIM_COLON #Type;
#Declarator -> #Identifier $OPERATOR_ASSIGN #Expression;
#Initializer -> #Identifier $DELIM_COLON #Type $OPERATOR_ASSIGN #Expression;
#Initializer -> #Identifier $OPERATOR_ASSIGN #Expression;
#ParameterList -> #Parameter $DELIM_COMMA #ParameterList;
#ParameterList -> #Parameter;
#OptionalParameterList -> #ParameterList;
#OptionalParameterList -> ;
TYPEOF #StaticSymbol "ContainerObject<sym::Locator>";
TYPEOF #Identifier "ContainerObject<std::string>";
TYPEOF #TypeList "ContainerObject<std::vector<UPTR(TypeExpression)>>";
TYPEOF #OptionalTypeList "ContainerObject<std::vector<UPTR(TypeExpression)>>";