]>
Commit | Line | Data |
---|---|---|
1dbba6cc | 1 | %code top { |
63b4c5a8 | 2 | #include "Cycript.tab.hh" |
924f67b2 | 3 | int cylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); |
5999c315 | 4 | #define scanner driver.scanner_ |
1dbba6cc JF |
5 | } |
6 | ||
63b4c5a8 JF |
7 | %code requires { |
8 | #include "Parser.hpp" | |
9 | } | |
10 | ||
11 | %union { | |
cf7d4c69 JF |
12 | CYArgument *argument_; |
13 | CYBoolean *boolean_; | |
14 | CYClause *clause_; | |
15 | CYCatch *catch_; | |
16 | CYDeclaration *declaration_; | |
17 | CYDeclarations *declarations_; | |
18 | CYElement *element_; | |
63b4c5a8 | 19 | CYExpression *expression_; |
cf7d4c69 JF |
20 | CYFalse *false_; |
21 | CYForInitialiser *for_; | |
22 | CYForInInitialiser *forin_; | |
23 | CYIdentifier *identifier_; | |
24 | CYLiteral *literal_; | |
25 | CYName *name_; | |
26 | CYNull *null_; | |
27 | CYNumber *number_; | |
28 | CYParameter *parameter_; | |
29 | CYProperty *property_; | |
30 | CYSource *source_; | |
31 | CYStatement *statement_; | |
32 | CYString *string_; | |
33 | CYThis *this_; | |
34 | CYTrue *true_; | |
35 | CYWord *word_; | |
63b4c5a8 JF |
36 | } |
37 | ||
1dbba6cc | 38 | %name-prefix "cy" |
e5332278 | 39 | |
63b4c5a8 | 40 | %language "C++" |
e5332278 | 41 | %locations |
1dbba6cc JF |
42 | %glr-parser |
43 | ||
5999c315 JF |
44 | %initial-action { |
45 | @$.begin.filename = @$.end.filename = &driver.filename_; | |
46 | }; | |
47 | ||
e5332278 | 48 | %defines |
1dbba6cc JF |
49 | |
50 | %debug | |
e5332278 JF |
51 | %error-verbose |
52 | ||
5999c315 | 53 | %parse-param { CYDriver &driver } |
924f67b2 | 54 | %lex-param { void *scanner } |
e5332278 | 55 | |
63b4c5a8 JF |
56 | %token Ampersand "&" |
57 | %token AmpersandAmpersand "&&" | |
58 | %token AmpersandEqual "&=" | |
59 | %token Carrot "^" | |
60 | %token CarrotEqual "^=" | |
61 | %token Equal "=" | |
62 | %token EqualEqual "==" | |
63 | %token EqualEqualEqual "===" | |
64 | %token Exclamation "!" | |
65 | %token ExclamationEqual "!=" | |
66 | %token ExclamationEqualEqual "!==" | |
67 | %token Hyphen "-" | |
68 | %token HyphenEqual "-=" | |
69 | %token HyphenHyphen "--" | |
70 | %token HyphenRight "->" | |
71 | %token Left "<" | |
72 | %token LeftEqual "<=" | |
73 | %token LeftLeft "<<" | |
74 | %token LeftLeftEqual "<<=" | |
75 | %token Percent "%" | |
76 | %token PercentEqual "%=" | |
77 | %token Period "." | |
78 | %token Pipe "|" | |
79 | %token PipeEqual "|=" | |
80 | %token PipePipe "||" | |
81 | %token Plus "+" | |
82 | %token PlusEqual "+=" | |
83 | %token PlusPlus "++" | |
84 | %token Right ">" | |
85 | %token RightEqual ">=" | |
86 | %token RightRight ">>" | |
87 | %token RightRightEqual ">>=" | |
88 | %token RightRightRight ">>>" | |
89 | %token RightRightRightEqual ">>>=" | |
90 | %token Slash "/" | |
91 | %token SlashEqual "/=" | |
92 | %token Star "*" | |
93 | %token StarEqual "*=" | |
94 | %token Tilde "~" | |
95 | ||
96 | %token Colon ":" | |
97 | %token Comma "," | |
98 | %token Question "?" | |
99 | %token SemiColon ";" | |
100 | ||
101 | %token OpenParen "(" | |
102 | %token CloseParen ")" | |
924f67b2 | 103 | |
63b4c5a8 JF |
104 | %token OpenBrace "{" |
105 | %token CloseBrace "}" | |
924f67b2 | 106 | |
63b4c5a8 JF |
107 | %token OpenBracket "[" |
108 | %token CloseBracket "]" | |
109 | ||
cf7d4c69 JF |
110 | %token <word_> Break "break" |
111 | %token <word_> Case "case" | |
112 | %token <word_> Catch "catch" | |
113 | %token <word_> Continue "continue" | |
114 | %token <word_> Default "default" | |
115 | %token <word_> Delete "delete" | |
116 | %token <word_> Do "do" | |
117 | %token <word_> Else "else" | |
118 | %token <false_> False "false" | |
119 | %token <word_> Finally "finally" | |
120 | %token <word_> For "for" | |
121 | %token <word_> Function "function" | |
122 | %token <word_> If "if" | |
123 | %token <word_> In "in" | |
124 | %token <word_> InstanceOf "instanceof" | |
125 | %token <word_> New "new" | |
126 | %token <null_> Null "null" | |
127 | %token <word_> Return "return" | |
128 | %token <word_> Switch "switch" | |
129 | %token <this_> This "this" | |
130 | %token <word_> Throw "throw" | |
131 | %token <true_> True "true" | |
132 | %token <word_> Try "try" | |
133 | %token <word_> TypeOf "typeof" | |
134 | %token <word_> Var "var" | |
135 | %token <word_> Void "void" | |
136 | %token <word_> While "while" | |
137 | %token <word_> With "with" | |
63b4c5a8 JF |
138 | |
139 | %token <identifier_> Identifier | |
140 | %token <number_> NumericLiteral | |
141 | %token <string_> StringLiteral | |
1dbba6cc | 142 | |
cf7d4c69 JF |
143 | %type <expression_> AdditiveExpression |
144 | %type <argument_> ArgumentList | |
145 | %type <argument_> ArgumentList_ | |
146 | %type <argument_> ArgumentListOpt | |
147 | %type <argument_> Arguments | |
148 | %type <literal_> ArrayLiteral | |
149 | %type <expression_> AssignmentExpression | |
150 | %type <expression_> BitwiseANDExpression | |
151 | %type <statement_> Block | |
152 | %type <boolean_> BooleanLiteral | |
153 | %type <expression_> BitwiseORExpression | |
154 | %type <expression_> BitwiseXORExpression | |
155 | %type <statement_> BreakStatement | |
156 | %type <expression_> CallExpression | |
157 | %type <clause_> CaseBlock | |
158 | %type <clause_> CaseClause | |
159 | %type <clause_> CaseClausesOpt | |
160 | %type <catch_> CatchOpt | |
161 | %type <expression_> ConditionalExpression | |
162 | %type <statement_> ContinueStatement | |
163 | %type <clause_> DefaultClause | |
164 | %type <statement_> DoWhileStatement | |
165 | %type <expression_> Element | |
166 | %type <element_> ElementList | |
167 | %type <element_> ElementList_ | |
168 | %type <statement_> ElseStatementOpt | |
169 | %type <statement_> EmptyStatement | |
170 | %type <expression_> EqualityExpression | |
171 | %type <expression_> Expression | |
172 | %type <expression_> Expression_ | |
173 | %type <expression_> ExpressionOpt | |
174 | %type <statement_> ExpressionStatement | |
175 | %type <statement_> FinallyOpt | |
176 | %type <statement_> ForStatement | |
177 | %type <for_> ForStatementInitialiser | |
178 | %type <statement_> ForInStatement | |
179 | %type <forin_> ForInStatementInitialiser | |
180 | %type <parameter_> FormalParameterList | |
181 | %type <parameter_> FormalParameterList_ | |
182 | %type <source_> FunctionBody | |
183 | %type <source_> FunctionDeclaration | |
184 | %type <expression_> FunctionExpression | |
185 | %type <identifier_> IdentifierOpt | |
186 | %type <statement_> IfStatement | |
187 | %type <expression_> Initialiser | |
188 | %type <expression_> InitialiserOpt | |
189 | %type <statement_> IterationStatement | |
190 | %type <statement_> LabelledStatement | |
191 | %type <expression_> LeftHandSideExpression | |
192 | %type <literal_> Literal | |
193 | %type <expression_> LogicalANDExpression | |
194 | %type <expression_> LogicalORExpression | |
195 | %type <expression_> MemberExpression | |
196 | %type <expression_> MultiplicativeExpression | |
197 | %type <expression_> NewExpression | |
198 | %type <null_> NullLiteral | |
199 | %type <literal_> ObjectLiteral | |
200 | %type <expression_> MessageExpression | |
201 | %type <expression_> PostfixExpression | |
202 | %type <expression_> PrimaryExpression | |
203 | %type <source_> Program | |
204 | %type <name_> PropertyName | |
205 | %type <property_> PropertyNameAndValueList | |
206 | %type <property_> PropertyNameAndValueList_ | |
207 | %type <property_> PropertyNameAndValueListOpt | |
208 | %type <expression_> RelationalExpression | |
209 | %type <statement_> ReturnStatement | |
210 | %type <argument_> SelectorCall | |
211 | %type <argument_> SelectorCall_ | |
212 | %type <argument_> SelectorList | |
213 | %type <expression_> ShiftExpression | |
214 | %type <source_> SourceElement | |
215 | %type <source_> SourceElements | |
216 | %type <statement_> Statement | |
217 | %type <statement_> StatementListOpt | |
218 | %type <statement_> SwitchStatement | |
219 | %type <statement_> ThrowStatement | |
220 | %type <statement_> TryStatement | |
221 | %type <expression_> UnaryExpression | |
222 | %type <declaration_> VariableDeclaration | |
223 | %type <declarations_> VariableDeclarationList | |
224 | %type <declarations_> VariableDeclarationList_ | |
225 | %type <statement_> VariableStatement | |
226 | %type <argument_> VariadicCall | |
227 | %type <statement_> WhileStatement | |
228 | %type <statement_> WithStatement | |
229 | %type <word_> Word | |
230 | %type <word_> WordOpt | |
231 | ||
e5332278 JF |
232 | %% |
233 | ||
63b4c5a8 | 234 | %start Program; |
1dbba6cc | 235 | |
2bf24581 | 236 | WordOpt |
cf7d4c69 JF |
237 | : Word { $$ = $1; } |
238 | | { $$ = NULL; } | |
2bf24581 JF |
239 | ; |
240 | ||
241 | Word | |
cf7d4c69 JF |
242 | : Identifier { $$ = $1; } |
243 | | "break" { $$ = $1; } | |
244 | | "case" { $$ = $1; } | |
245 | | "catch" { $$ = $1; } | |
246 | | "continue" { $$ = $1; } | |
247 | | "default" { $$ = $1; } | |
248 | | "delete" { $$ = $1; } | |
249 | | "do" { $$ = $1; } | |
250 | | "else" { $$ = $1; } | |
251 | | "false" { $$ = $1; } | |
252 | | "finally" { $$ = $1; } | |
253 | | "for" { $$ = $1; } | |
254 | | "function" { $$ = $1; } | |
255 | | "if" { $$ = $1; } | |
256 | | "in" { $$ = $1; } | |
257 | | "instanceof" { $$ = $1; } | |
258 | | "new" { $$ = $1; } | |
259 | | "null" { $$ = $1; } | |
260 | | "return" { $$ = $1; } | |
261 | | "switch" { $$ = $1; } | |
262 | | "this" { $$ = $1; } | |
263 | | "throw" { $$ = $1; } | |
264 | | "true" { $$ = $1; } | |
265 | | "try" { $$ = $1; } | |
266 | | "typeof" { $$ = $1; } | |
267 | | "var" { $$ = $1; } | |
268 | | "void" { $$ = $1; } | |
269 | | "while" { $$ = $1; } | |
270 | | "with" { $$ = $1; } | |
2bf24581 JF |
271 | ; |
272 | ||
1dbba6cc | 273 | IdentifierOpt |
cf7d4c69 JF |
274 | : Identifier { $$ = $1; } |
275 | | { $$ = NULL; } | |
1dbba6cc JF |
276 | ; |
277 | ||
1dbba6cc | 278 | Literal |
cf7d4c69 JF |
279 | : NullLiteral { $$ = $1; } |
280 | | BooleanLiteral { $$ = $1; } | |
281 | | NumericLiteral { $$ = $1; } | |
282 | | StringLiteral { $$ = $1; } | |
1dbba6cc JF |
283 | ; |
284 | ||
285 | NullLiteral | |
cf7d4c69 | 286 | : "null" { $$ = $1; } |
1dbba6cc JF |
287 | ; |
288 | ||
289 | BooleanLiteral | |
cf7d4c69 JF |
290 | : "true" { $$ = $1; } |
291 | | "false" { $$ = $1; } | |
1dbba6cc JF |
292 | ; |
293 | ||
1dbba6cc JF |
294 | /* Objective-C Extensions {{{ */ |
295 | VariadicCall | |
cf7d4c69 JF |
296 | : "," AssignmentExpression VariadicCall { $$ = new CYArgument(NULL, $2, $3); } |
297 | | { $$ = NULL; } | |
1dbba6cc JF |
298 | ; |
299 | ||
300 | SelectorCall_ | |
cf7d4c69 JF |
301 | : SelectorCall { $$ = $1; } |
302 | | VariadicCall { $$ = $1; } | |
1dbba6cc JF |
303 | ; |
304 | ||
305 | SelectorCall | |
cf7d4c69 | 306 | : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new CYArgument($1 ?: new CYBlank(), $3, $4); } |
1dbba6cc JF |
307 | ; |
308 | ||
309 | SelectorList | |
cf7d4c69 JF |
310 | : SelectorCall { $$ = $1; } |
311 | | Word { $$ = new CYArgument($1, NULL); } | |
1dbba6cc JF |
312 | ; |
313 | ||
cf7d4c69 JF |
314 | MessageExpression |
315 | : "[" AssignmentExpression SelectorList "]" { $$ = new CYMessage($2, $3); } | |
1dbba6cc JF |
316 | ; |
317 | /* }}} */ | |
318 | ||
319 | /* 11.1 Primary Expressions {{{ */ | |
320 | PrimaryExpression | |
cf7d4c69 JF |
321 | : "this" { $$ = $1; } |
322 | | Identifier { $$ = new CYVariable($1); } | |
323 | | Literal { $$ = $1; } | |
324 | | ArrayLiteral { $$ = $1; } | |
325 | | ObjectLiteral { $$ = $1; } | |
326 | | "(" Expression ")" { $$ = $2; } | |
327 | | MessageExpression { $$ = $1; } | |
1dbba6cc JF |
328 | ; |
329 | /* }}} */ | |
330 | /* 11.1.4 Array Initialiser {{{ */ | |
331 | ArrayLiteral | |
cf7d4c69 | 332 | : "[" ElementList "]" { $$ = $2; } |
1dbba6cc JF |
333 | ; |
334 | ||
335 | Element | |
cf7d4c69 JF |
336 | : AssignmentExpression { $$ = $1; } |
337 | | { $$ = NULL; } | |
1dbba6cc JF |
338 | ; |
339 | ||
340 | ElementList_ | |
cf7d4c69 JF |
341 | : "," ElementList { $$ = $2; } |
342 | | { $$ = NULL; } | |
1dbba6cc JF |
343 | ; |
344 | ||
345 | ElementList | |
cf7d4c69 | 346 | : Element ElementList_ { $$ = new CYElement($1, $2); } |
1dbba6cc JF |
347 | ; |
348 | /* }}} */ | |
349 | /* 11.1.5 Object Initialiser {{{ */ | |
350 | ObjectLiteral | |
cf7d4c69 | 351 | : "{" PropertyNameAndValueListOpt "}" { $$ = $2; } |
1dbba6cc JF |
352 | ; |
353 | ||
354 | PropertyNameAndValueList_ | |
cf7d4c69 JF |
355 | : "," PropertyNameAndValueList { $$ = $2; } |
356 | | { $$ = NULL; } | |
1dbba6cc JF |
357 | ; |
358 | ||
359 | PropertyNameAndValueListOpt | |
cf7d4c69 JF |
360 | : PropertyNameAndValueList { $$ = $1; } |
361 | | { $$ = NULL; } | |
1dbba6cc JF |
362 | ; |
363 | ||
364 | PropertyNameAndValueList | |
cf7d4c69 | 365 | : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new CYProperty($1, $3, $4); } |
1dbba6cc JF |
366 | ; |
367 | ||
368 | PropertyName | |
cf7d4c69 JF |
369 | : Identifier { $$ = $1; } |
370 | | StringLiteral { $$ = $1; } | |
371 | | NumericLiteral { $$ = $1; } | |
1dbba6cc JF |
372 | ; |
373 | /* }}} */ | |
374 | ||
375 | MemberExpression | |
cf7d4c69 JF |
376 | : PrimaryExpression { $$ = $1; } |
377 | | FunctionExpression { $$ = $1; } | |
378 | | MemberExpression "[" Expression "]" { $$ = new CYMember($1, $3); } | |
379 | | MemberExpression "." Identifier { $$ = new CYMember($1, new CYString($3)); } | |
380 | | "new" MemberExpression Arguments { $$ = new CYNew($2, $3); } | |
1dbba6cc JF |
381 | ; |
382 | ||
383 | NewExpression | |
cf7d4c69 JF |
384 | : MemberExpression { $$ = $1; } |
385 | | "new" NewExpression { $$ = new CYNew($2, NULL); } | |
1dbba6cc JF |
386 | ; |
387 | ||
388 | CallExpression | |
cf7d4c69 JF |
389 | : MemberExpression Arguments { $$ = new CYCall($1, $2); } |
390 | | CallExpression Arguments { $$ = new CYCall($1, $2); } | |
391 | | CallExpression "[" Expression "]" { $$ = new CYMember($1, $3); } | |
392 | | CallExpression "." Identifier { $$ = new CYMember($1, new CYString($3)); } | |
1dbba6cc JF |
393 | ; |
394 | ||
395 | ArgumentList_ | |
cf7d4c69 JF |
396 | : "," ArgumentList { $$ = $2; } |
397 | | { $$ = NULL; } | |
1dbba6cc JF |
398 | ; |
399 | ||
400 | ArgumentListOpt | |
cf7d4c69 JF |
401 | : ArgumentList { $$ = $1; } |
402 | | { $$ = NULL; } | |
1dbba6cc JF |
403 | ; |
404 | ||
405 | ArgumentList | |
cf7d4c69 | 406 | : AssignmentExpression ArgumentList_ { $$ = new CYArgument(NULL, $1, $2); } |
1dbba6cc JF |
407 | ; |
408 | ||
409 | Arguments | |
cf7d4c69 | 410 | : "(" ArgumentListOpt ")" { $$ = $2; } |
1dbba6cc JF |
411 | ; |
412 | ||
413 | LeftHandSideExpression | |
cf7d4c69 JF |
414 | : NewExpression { $$ = $1; } |
415 | | CallExpression { $$ = $1; } | |
5999c315 | 416 | | "*" LeftHandSideExpression { $$ = new CYIndirect($2); } |
1dbba6cc JF |
417 | ; |
418 | ||
419 | PostfixExpression | |
cf7d4c69 JF |
420 | : LeftHandSideExpression { $$ = $1; } |
421 | | LeftHandSideExpression "++" { $$ = new CYPostIncrement($1); } | |
422 | | LeftHandSideExpression "--" { $$ = new CYPostDecrement($1); } | |
1dbba6cc JF |
423 | ; |
424 | ||
425 | UnaryExpression | |
cf7d4c69 JF |
426 | : PostfixExpression { $$ = $1; } |
427 | | "delete" UnaryExpression { $$ = new CYDelete($2); } | |
428 | | "void" UnaryExpression { $$ = new CYVoid($2); } | |
429 | | "typeof" UnaryExpression { $$ = new CYTypeOf($2); } | |
430 | | "++" UnaryExpression { $$ = new CYPreIncrement($2); } | |
431 | | "--" UnaryExpression { $$ = new CYPreDecrement($2); } | |
432 | | "+" UnaryExpression { $$ = $2; } | |
433 | | "-" UnaryExpression { $$ = new CYNegate($2); } | |
434 | | "~" UnaryExpression { $$ = new CYBitwiseNot($2); } | |
435 | | "!" UnaryExpression { $$ = new CYLogicalNot($2); } | |
cf7d4c69 | 436 | | "&" UnaryExpression { $$ = new CYAddressOf($2); } |
1dbba6cc JF |
437 | ; |
438 | ||
439 | MultiplicativeExpression | |
cf7d4c69 JF |
440 | : UnaryExpression { $$ = $1; } |
441 | | MultiplicativeExpression "*" UnaryExpression { $$ = new CYMultiply($1, $3); } | |
442 | | MultiplicativeExpression "/" UnaryExpression { $$ = new CYDivide($1, $3); } | |
443 | | MultiplicativeExpression "%" UnaryExpression { $$ = new CYModulus($1, $3); } | |
1dbba6cc JF |
444 | ; |
445 | ||
446 | AdditiveExpression | |
cf7d4c69 JF |
447 | : MultiplicativeExpression { $$ = $1; } |
448 | | AdditiveExpression "+" MultiplicativeExpression { $$ = new CYAdd($1, $3); } | |
449 | | AdditiveExpression "-" MultiplicativeExpression { $$ = new CYSubtract($1, $3); } | |
1dbba6cc JF |
450 | ; |
451 | ||
452 | ShiftExpression | |
cf7d4c69 JF |
453 | : AdditiveExpression { $$ = $1; } |
454 | | ShiftExpression "<<" AdditiveExpression { $$ = new CYShiftLeft($1, $3); } | |
455 | | ShiftExpression ">>" AdditiveExpression { $$ = new CYShiftRightSigned($1, $3); } | |
456 | | ShiftExpression ">>>" AdditiveExpression { $$ = new CYShiftRightUnsigned($1, $3); } | |
1dbba6cc JF |
457 | ; |
458 | ||
459 | RelationalExpression | |
cf7d4c69 JF |
460 | : ShiftExpression { $$ = $1; } |
461 | | RelationalExpression "<" ShiftExpression { $$ = new CYLess($1, $3); } | |
462 | | RelationalExpression ">" ShiftExpression { $$ = new CYGreater($1, $3); } | |
463 | | RelationalExpression "<=" ShiftExpression { $$ = new CYLessOrEqual($1, $3); } | |
464 | | RelationalExpression ">=" ShiftExpression { $$ = new CYGreaterOrEqual($1, $3); } | |
465 | | RelationalExpression "instanceof" ShiftExpression { $$ = new CYInstanceOf($1, $3); } | |
466 | | RelationalExpression "in" ShiftExpression { $$ = new CYIn($1, $3); } | |
1dbba6cc JF |
467 | ; |
468 | ||
469 | EqualityExpression | |
cf7d4c69 JF |
470 | : RelationalExpression { $$ = $1; } |
471 | | EqualityExpression "==" RelationalExpression { $$ = new CYEqual($1, $3); } | |
472 | | EqualityExpression "!=" RelationalExpression { $$ = new CYNotEqual($1, $3); } | |
473 | | EqualityExpression "===" RelationalExpression { $$ = new CYIdentical($1, $3); } | |
474 | | EqualityExpression "!==" RelationalExpression { $$ = new CYNotIdentical($1, $3); } | |
1dbba6cc JF |
475 | ; |
476 | ||
477 | BitwiseANDExpression | |
cf7d4c69 JF |
478 | : EqualityExpression { $$ = $1; } |
479 | | BitwiseANDExpression "&" EqualityExpression { $$ = new CYBitwiseAnd($1, $3); } | |
1dbba6cc JF |
480 | ; |
481 | ||
482 | BitwiseXORExpression | |
cf7d4c69 JF |
483 | : BitwiseANDExpression { $$ = $1; } |
484 | | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new CYBitwiseXOr($1, $3); } | |
1dbba6cc JF |
485 | ; |
486 | ||
487 | BitwiseORExpression | |
cf7d4c69 JF |
488 | : BitwiseXORExpression { $$ = $1; } |
489 | | BitwiseORExpression "|" BitwiseXORExpression { $$ = new CYBitwiseOr($1, $3); } | |
1dbba6cc JF |
490 | ; |
491 | ||
492 | LogicalANDExpression | |
cf7d4c69 JF |
493 | : BitwiseORExpression { $$ = $1; } |
494 | | LogicalANDExpression "&&" BitwiseORExpression { $$ = new CYLogicalAnd($1, $3); } | |
1dbba6cc JF |
495 | ; |
496 | ||
497 | LogicalORExpression | |
cf7d4c69 JF |
498 | : LogicalANDExpression { $$ = $1; } |
499 | | LogicalORExpression "||" LogicalANDExpression { $$ = new CYLogicalOr($1, $3); } | |
1dbba6cc JF |
500 | ; |
501 | ||
502 | ConditionalExpression | |
cf7d4c69 JF |
503 | : LogicalORExpression { $$ = $1; } |
504 | | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new CYCondition($1, $3, $5); } | |
1dbba6cc JF |
505 | ; |
506 | ||
507 | AssignmentExpression | |
cf7d4c69 JF |
508 | : ConditionalExpression { $$ = $1; } |
509 | | LeftHandSideExpression "=" AssignmentExpression { $$ = new CYAssign($1, $3); } | |
510 | | LeftHandSideExpression "*=" AssignmentExpression { $$ = new CYMultiplyAssign($1, $3); } | |
511 | | LeftHandSideExpression "/=" AssignmentExpression { $$ = new CYDivideAssign($1, $3); } | |
512 | | LeftHandSideExpression "%=" AssignmentExpression { $$ = new CYModulusAssign($1, $3); } | |
513 | | LeftHandSideExpression "+=" AssignmentExpression { $$ = new CYAddAssign($1, $3); } | |
514 | | LeftHandSideExpression "-=" AssignmentExpression { $$ = new CYSubtractAssign($1, $3); } | |
515 | | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new CYShiftLeftAssign($1, $3); } | |
516 | | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new CYShiftRightSignedAssign($1, $3); } | |
517 | | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new CYShiftRightUnsignedAssign($1, $3); } | |
518 | | LeftHandSideExpression "&=" AssignmentExpression { $$ = new CYBitwiseAndAssign($1, $3); } | |
519 | | LeftHandSideExpression "^=" AssignmentExpression { $$ = new CYBitwiseXOrAssign($1, $3); } | |
520 | | LeftHandSideExpression "|=" AssignmentExpression { $$ = new CYBitwiseOrAssign($1, $3); } | |
1dbba6cc JF |
521 | ; |
522 | ||
523 | Expression_ | |
cf7d4c69 JF |
524 | : "," Expression { $$ = $2; } |
525 | | { $$ = NULL; } | |
1dbba6cc JF |
526 | ; |
527 | ||
528 | ExpressionOpt | |
cf7d4c69 JF |
529 | : Expression { $$ = $1; } |
530 | | { $$ = NULL; } | |
1dbba6cc JF |
531 | ; |
532 | ||
533 | Expression | |
5999c315 | 534 | : AssignmentExpression Expression_ { if ($1 == NULL) $$ = $2; else { $1->SetNext($2); $$ = $1; } } |
1dbba6cc JF |
535 | ; |
536 | ||
537 | Statement | |
cf7d4c69 JF |
538 | : Block { $$ = $1; } |
539 | | VariableStatement { $$ = $1; } | |
540 | | EmptyStatement { $$ = $1; } | |
541 | | ExpressionStatement { $$ = $1; } | |
542 | | IfStatement { $$ = $1; } | |
543 | | IterationStatement { $$ = $1; } | |
544 | | ContinueStatement { $$ = $1; } | |
545 | | BreakStatement { $$ = $1; } | |
546 | | ReturnStatement { $$ = $1; } | |
547 | | WithStatement { $$ = $1; } | |
548 | | LabelledStatement { $$ = $1; } | |
549 | | SwitchStatement { $$ = $1; } | |
550 | | ThrowStatement { $$ = $1; } | |
551 | | TryStatement { $$ = $1; } | |
1dbba6cc JF |
552 | ; |
553 | ||
554 | Block | |
cf7d4c69 | 555 | : "{" StatementListOpt "}" { $$ = $2 ?: new CYEmpty(); } |
1dbba6cc JF |
556 | ; |
557 | ||
558 | StatementListOpt | |
cf7d4c69 JF |
559 | : Statement StatementListOpt { $1->SetNext($2); $$ = $1; } |
560 | | { $$ = NULL; } | |
1dbba6cc JF |
561 | ; |
562 | ||
563 | VariableStatement | |
cf7d4c69 | 564 | : "var" VariableDeclarationList ";" { $$ = $2; } |
1dbba6cc JF |
565 | ; |
566 | ||
567 | VariableDeclarationList_ | |
cf7d4c69 JF |
568 | : "," VariableDeclarationList { $$ = $2; } |
569 | | { $$ = NULL; } | |
1dbba6cc JF |
570 | ; |
571 | ||
572 | VariableDeclarationList | |
cf7d4c69 | 573 | : VariableDeclaration VariableDeclarationList_ { $$ = new CYDeclarations($1, $2); } |
1dbba6cc JF |
574 | ; |
575 | ||
576 | VariableDeclaration | |
cf7d4c69 | 577 | : Identifier InitialiserOpt { $$ = new CYDeclaration($1, $2); } |
1dbba6cc JF |
578 | ; |
579 | ||
580 | InitialiserOpt | |
cf7d4c69 JF |
581 | : Initialiser { $$ = $1; } |
582 | | { $$ = NULL; } | |
1dbba6cc JF |
583 | ; |
584 | ||
585 | Initialiser | |
cf7d4c69 | 586 | : "=" AssignmentExpression { $$ = $2; } |
1dbba6cc JF |
587 | ; |
588 | ||
589 | EmptyStatement | |
cf7d4c69 | 590 | : ";" { $$ = new CYEmpty(); } |
1dbba6cc JF |
591 | ; |
592 | ||
593 | ExpressionStatement | |
5999c315 | 594 | : Expression ";" { $$ = new CYExpress($1); } |
1dbba6cc JF |
595 | ; |
596 | ||
597 | ElseStatementOpt | |
cf7d4c69 JF |
598 | : "else" Statement { $$ = $2; } |
599 | | { $$ = NULL; } | |
1dbba6cc JF |
600 | ; |
601 | ||
602 | IfStatement | |
cf7d4c69 | 603 | : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new CYIf($3, $5, $6); } |
1dbba6cc JF |
604 | ; |
605 | ||
606 | IterationStatement | |
cf7d4c69 JF |
607 | : DoWhileStatement { $$ = $1; } |
608 | | WhileStatement { $$ = $1; } | |
609 | | ForStatement { $$ = $1; } | |
610 | | ForInStatement { $$ = $1; } | |
1dbba6cc JF |
611 | ; |
612 | ||
613 | DoWhileStatement | |
cf7d4c69 | 614 | : "do" Statement "while" "(" Expression ")" ";" { $$ = new CYDoWhile($5, $2); } |
1dbba6cc JF |
615 | ; |
616 | ||
617 | WhileStatement | |
cf7d4c69 | 618 | : "while" "(" Expression ")" Statement { $$ = new CYWhile($3, $5); } |
1dbba6cc JF |
619 | ; |
620 | ||
621 | ForStatement | |
cf7d4c69 | 622 | : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new CYFor($3, $5, $7, $9); } |
1dbba6cc JF |
623 | ; |
624 | ||
625 | ForStatementInitialiser | |
cf7d4c69 JF |
626 | : ExpressionOpt { $$ = $1; } |
627 | | "var" VariableDeclarationList { $$ = $2; } | |
1dbba6cc JF |
628 | ; |
629 | ||
630 | ForInStatement | |
cf7d4c69 | 631 | : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new CYForIn($3, $5, $7); } |
1dbba6cc JF |
632 | ; |
633 | ||
634 | ForInStatementInitialiser | |
cf7d4c69 JF |
635 | : LeftHandSideExpression { $$ = $1; } |
636 | | "var" VariableDeclaration { $$ = $2; } | |
1dbba6cc JF |
637 | ; |
638 | ||
639 | ContinueStatement | |
cf7d4c69 | 640 | : "continue" IdentifierOpt ";" { $$ = new CYContinue($2); } |
1dbba6cc JF |
641 | ; |
642 | ||
643 | BreakStatement | |
cf7d4c69 | 644 | : "break" IdentifierOpt ";" { $$ = new CYBreak($2); } |
1dbba6cc JF |
645 | ; |
646 | ||
647 | ReturnStatement | |
cf7d4c69 | 648 | : "return" ExpressionOpt ";" { $$ = new CYReturn($2); } |
1dbba6cc JF |
649 | ; |
650 | ||
651 | WithStatement | |
cf7d4c69 | 652 | : "with" "(" Expression ")" Statement { $$ = new CYWith($3, $5); } |
1dbba6cc JF |
653 | ; |
654 | ||
655 | SwitchStatement | |
cf7d4c69 | 656 | : "switch" "(" Expression ")" CaseBlock { $$ = new CYSwitch($3, $5); } |
1dbba6cc JF |
657 | ; |
658 | ||
659 | CaseBlock | |
cf7d4c69 | 660 | : "{" CaseClausesOpt "}" { $$ = $2; } |
1dbba6cc JF |
661 | ; |
662 | ||
663 | CaseClausesOpt | |
cf7d4c69 JF |
664 | : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } |
665 | | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | |
666 | | { $$ = NULL; } | |
1dbba6cc JF |
667 | ; |
668 | ||
669 | CaseClause | |
cf7d4c69 | 670 | : "case" Expression ":" StatementListOpt { $$ = new CYClause($2, $4); } |
1dbba6cc JF |
671 | ; |
672 | ||
673 | DefaultClause | |
cf7d4c69 | 674 | : "default" ":" StatementListOpt { $$ = new CYClause(NULL, $3); } |
1dbba6cc JF |
675 | ; |
676 | ||
677 | LabelledStatement | |
cf7d4c69 | 678 | : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; } |
1dbba6cc JF |
679 | ; |
680 | ||
681 | ThrowStatement | |
cf7d4c69 | 682 | : "throw" Expression ";" { $$ = new CYThrow($2); } |
1dbba6cc JF |
683 | ; |
684 | ||
685 | TryStatement | |
cf7d4c69 | 686 | : "try" Block CatchOpt FinallyOpt { $$ = new CYTry($2, $3, $4); } |
1dbba6cc JF |
687 | ; |
688 | ||
689 | CatchOpt | |
cf7d4c69 JF |
690 | : "catch" "(" Identifier ")" Block { $$ = new CYCatch($3, $5); } |
691 | | { $$ = NULL; } | |
1dbba6cc JF |
692 | ; |
693 | ||
694 | FinallyOpt | |
cf7d4c69 JF |
695 | : "finally" Block { $$ = $2; } |
696 | | { $$ = NULL; } | |
1dbba6cc JF |
697 | ; |
698 | ||
699 | FunctionDeclaration | |
cf7d4c69 | 700 | : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYFunction($2, $4, $7); } |
1dbba6cc JF |
701 | ; |
702 | ||
703 | FunctionExpression | |
cf7d4c69 | 704 | : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYLambda($2, $4, $7); } |
1dbba6cc JF |
705 | ; |
706 | ||
707 | FormalParameterList_ | |
cf7d4c69 JF |
708 | : "," FormalParameterList { $$ = $2; } |
709 | | { $$ = NULL; } | |
1dbba6cc JF |
710 | ; |
711 | ||
712 | FormalParameterList | |
cf7d4c69 JF |
713 | : Identifier FormalParameterList_ { $$ = new CYParameter($1, $2); } |
714 | | { $$ = NULL; } | |
1dbba6cc JF |
715 | ; |
716 | ||
717 | FunctionBody | |
cf7d4c69 | 718 | : SourceElements { $$ = $1; } |
1dbba6cc JF |
719 | ; |
720 | ||
721 | Program | |
5999c315 | 722 | : SourceElements { driver.source_ = $1; $$ = $1; } |
1dbba6cc JF |
723 | ; |
724 | ||
725 | SourceElements | |
cf7d4c69 JF |
726 | : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } |
727 | | { $$ = NULL; } | |
1dbba6cc JF |
728 | ; |
729 | ||
730 | SourceElement | |
cf7d4c69 JF |
731 | : Statement { $$ = $1; } |
732 | | FunctionDeclaration { $$ = $1; } | |
1dbba6cc | 733 | ; |
e5332278 JF |
734 | |
735 | %% |