]> git.saurik.com Git - cycript.git/blob - Cycript.y
c7084b5e2bd3a6764819dbc1467909941c83b371
[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 %initial-action {
45 @$.begin.filename = @$.end.filename = &driver.filename_;
46 };
47
48 %defines
49
50 %debug
51 %error-verbose
52
53 %parse-param { CYDriver &driver }
54 %lex-param { void *scanner }
55
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 ")"
103
104 %token OpenBrace "{"
105 %token CloseBrace "}"
106
107 %token OpenBracket "["
108 %token CloseBracket "]"
109
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"
138
139 %token <identifier_> Identifier
140 %token <number_> NumericLiteral
141 %token <string_> StringLiteral
142
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
232 %%
233
234 %start Program;
235
236 WordOpt
237 : Word { $$ = $1; }
238 | { $$ = NULL; }
239 ;
240
241 Word
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; }
271 ;
272
273 IdentifierOpt
274 : Identifier { $$ = $1; }
275 | { $$ = NULL; }
276 ;
277
278 Literal
279 : NullLiteral { $$ = $1; }
280 | BooleanLiteral { $$ = $1; }
281 | NumericLiteral { $$ = $1; }
282 | StringLiteral { $$ = $1; }
283 ;
284
285 NullLiteral
286 : "null" { $$ = $1; }
287 ;
288
289 BooleanLiteral
290 : "true" { $$ = $1; }
291 | "false" { $$ = $1; }
292 ;
293
294 /* Objective-C Extensions {{{ */
295 VariadicCall
296 : "," AssignmentExpression VariadicCall { $$ = new CYArgument(NULL, $2, $3); }
297 | { $$ = NULL; }
298 ;
299
300 SelectorCall_
301 : SelectorCall { $$ = $1; }
302 | VariadicCall { $$ = $1; }
303 ;
304
305 SelectorCall
306 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new CYArgument($1 ?: new CYBlank(), $3, $4); }
307 ;
308
309 SelectorList
310 : SelectorCall { $$ = $1; }
311 | Word { $$ = new CYArgument($1, NULL); }
312 ;
313
314 MessageExpression
315 : "[" AssignmentExpression SelectorList "]" { $$ = new CYMessage($2, $3); }
316 ;
317 /* }}} */
318
319 /* 11.1 Primary Expressions {{{ */
320 PrimaryExpression
321 : "this" { $$ = $1; }
322 | Identifier { $$ = new CYVariable($1); }
323 | Literal { $$ = $1; }
324 | ArrayLiteral { $$ = $1; }
325 | ObjectLiteral { $$ = $1; }
326 | "(" Expression ")" { $$ = $2; }
327 | MessageExpression { $$ = $1; }
328 ;
329 /* }}} */
330 /* 11.1.4 Array Initialiser {{{ */
331 ArrayLiteral
332 : "[" ElementList "]" { $$ = $2; }
333 ;
334
335 Element
336 : AssignmentExpression { $$ = $1; }
337 | { $$ = NULL; }
338 ;
339
340 ElementList_
341 : "," ElementList { $$ = $2; }
342 | { $$ = NULL; }
343 ;
344
345 ElementList
346 : Element ElementList_ { $$ = new CYElement($1, $2); }
347 ;
348 /* }}} */
349 /* 11.1.5 Object Initialiser {{{ */
350 ObjectLiteral
351 : "{" PropertyNameAndValueListOpt "}" { $$ = $2; }
352 ;
353
354 PropertyNameAndValueList_
355 : "," PropertyNameAndValueList { $$ = $2; }
356 | { $$ = NULL; }
357 ;
358
359 PropertyNameAndValueListOpt
360 : PropertyNameAndValueList { $$ = $1; }
361 | { $$ = NULL; }
362 ;
363
364 PropertyNameAndValueList
365 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new CYProperty($1, $3, $4); }
366 ;
367
368 PropertyName
369 : Identifier { $$ = $1; }
370 | StringLiteral { $$ = $1; }
371 | NumericLiteral { $$ = $1; }
372 ;
373 /* }}} */
374
375 MemberExpression
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); }
381 ;
382
383 NewExpression
384 : MemberExpression { $$ = $1; }
385 | "new" NewExpression { $$ = new CYNew($2, NULL); }
386 ;
387
388 CallExpression
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)); }
393 ;
394
395 ArgumentList_
396 : "," ArgumentList { $$ = $2; }
397 | { $$ = NULL; }
398 ;
399
400 ArgumentListOpt
401 : ArgumentList { $$ = $1; }
402 | { $$ = NULL; }
403 ;
404
405 ArgumentList
406 : AssignmentExpression ArgumentList_ { $$ = new CYArgument(NULL, $1, $2); }
407 ;
408
409 Arguments
410 : "(" ArgumentListOpt ")" { $$ = $2; }
411 ;
412
413 LeftHandSideExpression
414 : NewExpression { $$ = $1; }
415 | CallExpression { $$ = $1; }
416 | "*" LeftHandSideExpression { $$ = new CYIndirect($2); }
417 ;
418
419 PostfixExpression
420 : LeftHandSideExpression { $$ = $1; }
421 | LeftHandSideExpression "++" { $$ = new CYPostIncrement($1); }
422 | LeftHandSideExpression "--" { $$ = new CYPostDecrement($1); }
423 ;
424
425 UnaryExpression
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); }
436 | "&" UnaryExpression { $$ = new CYAddressOf($2); }
437 ;
438
439 MultiplicativeExpression
440 : UnaryExpression { $$ = $1; }
441 | MultiplicativeExpression "*" UnaryExpression { $$ = new CYMultiply($1, $3); }
442 | MultiplicativeExpression "/" UnaryExpression { $$ = new CYDivide($1, $3); }
443 | MultiplicativeExpression "%" UnaryExpression { $$ = new CYModulus($1, $3); }
444 ;
445
446 AdditiveExpression
447 : MultiplicativeExpression { $$ = $1; }
448 | AdditiveExpression "+" MultiplicativeExpression { $$ = new CYAdd($1, $3); }
449 | AdditiveExpression "-" MultiplicativeExpression { $$ = new CYSubtract($1, $3); }
450 ;
451
452 ShiftExpression
453 : AdditiveExpression { $$ = $1; }
454 | ShiftExpression "<<" AdditiveExpression { $$ = new CYShiftLeft($1, $3); }
455 | ShiftExpression ">>" AdditiveExpression { $$ = new CYShiftRightSigned($1, $3); }
456 | ShiftExpression ">>>" AdditiveExpression { $$ = new CYShiftRightUnsigned($1, $3); }
457 ;
458
459 RelationalExpression
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); }
467 ;
468
469 EqualityExpression
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); }
475 ;
476
477 BitwiseANDExpression
478 : EqualityExpression { $$ = $1; }
479 | BitwiseANDExpression "&" EqualityExpression { $$ = new CYBitwiseAnd($1, $3); }
480 ;
481
482 BitwiseXORExpression
483 : BitwiseANDExpression { $$ = $1; }
484 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new CYBitwiseXOr($1, $3); }
485 ;
486
487 BitwiseORExpression
488 : BitwiseXORExpression { $$ = $1; }
489 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new CYBitwiseOr($1, $3); }
490 ;
491
492 LogicalANDExpression
493 : BitwiseORExpression { $$ = $1; }
494 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new CYLogicalAnd($1, $3); }
495 ;
496
497 LogicalORExpression
498 : LogicalANDExpression { $$ = $1; }
499 | LogicalORExpression "||" LogicalANDExpression { $$ = new CYLogicalOr($1, $3); }
500 ;
501
502 ConditionalExpression
503 : LogicalORExpression { $$ = $1; }
504 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new CYCondition($1, $3, $5); }
505 ;
506
507 AssignmentExpression
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); }
521 ;
522
523 Expression_
524 : "," Expression { $$ = $2; }
525 | { $$ = NULL; }
526 ;
527
528 ExpressionOpt
529 : Expression { $$ = $1; }
530 | { $$ = NULL; }
531 ;
532
533 Expression
534 : AssignmentExpression Expression_ { if ($1 == NULL) $$ = $2; else { $1->SetNext($2); $$ = $1; } }
535 ;
536
537 Statement
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; }
552 ;
553
554 Block
555 : "{" StatementListOpt "}" { $$ = $2 ?: new CYEmpty(); }
556 ;
557
558 StatementListOpt
559 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
560 | { $$ = NULL; }
561 ;
562
563 VariableStatement
564 : "var" VariableDeclarationList ";" { $$ = $2; }
565 ;
566
567 VariableDeclarationList_
568 : "," VariableDeclarationList { $$ = $2; }
569 | { $$ = NULL; }
570 ;
571
572 VariableDeclarationList
573 : VariableDeclaration VariableDeclarationList_ { $$ = new CYDeclarations($1, $2); }
574 ;
575
576 VariableDeclaration
577 : Identifier InitialiserOpt { $$ = new CYDeclaration($1, $2); }
578 ;
579
580 InitialiserOpt
581 : Initialiser { $$ = $1; }
582 | { $$ = NULL; }
583 ;
584
585 Initialiser
586 : "=" AssignmentExpression { $$ = $2; }
587 ;
588
589 EmptyStatement
590 : ";" { $$ = new CYEmpty(); }
591 ;
592
593 ExpressionStatement
594 : Expression ";" { $$ = new CYExpress($1); }
595 ;
596
597 ElseStatementOpt
598 : "else" Statement { $$ = $2; }
599 | { $$ = NULL; }
600 ;
601
602 IfStatement
603 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new CYIf($3, $5, $6); }
604 ;
605
606 IterationStatement
607 : DoWhileStatement { $$ = $1; }
608 | WhileStatement { $$ = $1; }
609 | ForStatement { $$ = $1; }
610 | ForInStatement { $$ = $1; }
611 ;
612
613 DoWhileStatement
614 : "do" Statement "while" "(" Expression ")" ";" { $$ = new CYDoWhile($5, $2); }
615 ;
616
617 WhileStatement
618 : "while" "(" Expression ")" Statement { $$ = new CYWhile($3, $5); }
619 ;
620
621 ForStatement
622 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new CYFor($3, $5, $7, $9); }
623 ;
624
625 ForStatementInitialiser
626 : ExpressionOpt { $$ = $1; }
627 | "var" VariableDeclarationList { $$ = $2; }
628 ;
629
630 ForInStatement
631 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new CYForIn($3, $5, $7); }
632 ;
633
634 ForInStatementInitialiser
635 : LeftHandSideExpression { $$ = $1; }
636 | "var" VariableDeclaration { $$ = $2; }
637 ;
638
639 ContinueStatement
640 : "continue" IdentifierOpt ";" { $$ = new CYContinue($2); }
641 ;
642
643 BreakStatement
644 : "break" IdentifierOpt ";" { $$ = new CYBreak($2); }
645 ;
646
647 ReturnStatement
648 : "return" ExpressionOpt ";" { $$ = new CYReturn($2); }
649 ;
650
651 WithStatement
652 : "with" "(" Expression ")" Statement { $$ = new CYWith($3, $5); }
653 ;
654
655 SwitchStatement
656 : "switch" "(" Expression ")" CaseBlock { $$ = new CYSwitch($3, $5); }
657 ;
658
659 CaseBlock
660 : "{" CaseClausesOpt "}" { $$ = $2; }
661 ;
662
663 CaseClausesOpt
664 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
665 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
666 | { $$ = NULL; }
667 ;
668
669 CaseClause
670 : "case" Expression ":" StatementListOpt { $$ = new CYClause($2, $4); }
671 ;
672
673 DefaultClause
674 : "default" ":" StatementListOpt { $$ = new CYClause(NULL, $3); }
675 ;
676
677 LabelledStatement
678 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
679 ;
680
681 ThrowStatement
682 : "throw" Expression ";" { $$ = new CYThrow($2); }
683 ;
684
685 TryStatement
686 : "try" Block CatchOpt FinallyOpt { $$ = new CYTry($2, $3, $4); }
687 ;
688
689 CatchOpt
690 : "catch" "(" Identifier ")" Block { $$ = new CYCatch($3, $5); }
691 | { $$ = NULL; }
692 ;
693
694 FinallyOpt
695 : "finally" Block { $$ = $2; }
696 | { $$ = NULL; }
697 ;
698
699 FunctionDeclaration
700 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYFunction($2, $4, $7); }
701 ;
702
703 FunctionExpression
704 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYLambda($2, $4, $7); }
705 ;
706
707 FormalParameterList_
708 : "," FormalParameterList { $$ = $2; }
709 | { $$ = NULL; }
710 ;
711
712 FormalParameterList
713 : Identifier FormalParameterList_ { $$ = new CYParameter($1, $2); }
714 | { $$ = NULL; }
715 ;
716
717 FunctionBody
718 : SourceElements { $$ = $1; }
719 ;
720
721 Program
722 : SourceElements { driver.source_ = $1; $$ = $1; }
723 ;
724
725 SourceElements
726 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
727 | { $$ = NULL; }
728 ;
729
730 SourceElement
731 : Statement { $$ = $1; }
732 | FunctionDeclaration { $$ = $1; }
733 ;
734
735 %%