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