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