]> git.saurik.com Git - cycript.git/blame_incremental - Cycript.y
Fixed some corner cases in flags propogation.
[cycript.git] / Cycript.y
... / ...
CommitLineData
1/* Cycript - Remove Execution Server and Disassembler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3*/
4
5/* Modified BSD License {{{ */
6/*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37*/
38/* }}} */
39
40%code top {
41#include "Cycript.tab.hh"
42#define scanner driver.scanner_
43#define YYSTACKEXPANDABLE 1
44}
45
46%code requires {
47#include "Parser.hpp"
48
49typedef struct {
50 bool newline_;
51
52 union {
53 bool bool_;
54
55 CYDriver::Condition condition_;
56
57 CYArgument *argument_;
58 CYAssignment *assignment_;
59 CYBoolean *boolean_;
60 CYClause *clause_;
61 CYCatch *catch_;
62 CYClassName *className_;
63 CYComprehension *comprehension_;
64 CYCompound *compound_;
65 CYDeclaration *declaration_;
66 CYDeclarations *declarations_;
67 CYElement *element_;
68 CYExpression *expression_;
69 CYFalse *false_;
70 CYField *field_;
71 CYFinally *finally_;
72 CYForInitialiser *for_;
73 CYForInInitialiser *forin_;
74 CYFunctionParameter *functionParameter_;
75 CYIdentifier *identifier_;
76 CYInfix *infix_;
77 CYLiteral *literal_;
78 CYMember *member_;
79 CYMessage *message_;
80 CYMessageParameter *messageParameter_;
81 CYNull *null_;
82 CYNumber *number_;
83 CYProperty *property_;
84 CYPropertyName *propertyName_;
85 CYSelectorPart *selector_;
86 CYStatement *statement_;
87 CYString *string_;
88 CYThis *this_;
89 CYTrue *true_;
90 CYWord *word_;
91 };
92} YYSTYPE;
93
94}
95
96%code provides {
97int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
98}
99
100%name-prefix "cy"
101
102%language "C++"
103%locations
104
105%initial-action {
106 @$.begin.filename = @$.end.filename = &driver.filename_;
107};
108
109%defines
110
111//%glr-parser
112//%expect 1
113
114%error-verbose
115
116%parse-param { CYDriver &driver }
117%lex-param { void *scanner }
118
119%token At "@"
120
121%token Ampersand "&"
122%token AmpersandAmpersand "&&"
123%token AmpersandEqual "&="
124%token Carrot "^"
125%token CarrotEqual "^="
126%token Equal "="
127%token EqualEqual "=="
128%token EqualEqualEqual "==="
129%token Exclamation "!"
130%token ExclamationEqual "!="
131%token ExclamationEqualEqual "!=="
132%token Hyphen "-"
133%token HyphenEqual "-="
134%token HyphenHyphen "--"
135%token HyphenHyphen_ "\n--"
136%token HyphenRight "->"
137%token Left "<"
138%token LeftEqual "<="
139%token LeftLeft "<<"
140%token LeftLeftEqual "<<="
141%token Percent "%"
142%token PercentEqual "%="
143%token Period "."
144%token Pipe "|"
145%token PipeEqual "|="
146%token PipePipe "||"
147%token Plus "+"
148%token PlusEqual "+="
149%token PlusPlus "++"
150%token PlusPlus_ "\n++"
151%token Right ">"
152%token RightEqual ">="
153%token RightRight ">>"
154%token RightRightEqual ">>="
155%token RightRightRight ">>>"
156%token RightRightRightEqual ">>>="
157%token Slash "/"
158%token SlashEqual "/="
159%token Star "*"
160%token StarEqual "*="
161%token Tilde "~"
162
163%token Colon ":"
164%token Comma ","
165%token Question "?"
166%token SemiColon ";"
167%token NewLine "\n"
168
169%token OpenParen "("
170%token CloseParen ")"
171
172%token OpenBrace "{"
173%token CloseBrace "}"
174
175%token OpenBracket "["
176%token CloseBracket "]"
177
178%token AtClass "@class"
179%token AtSelector "@selector"
180%token AtEnd "@end"
181
182%token <false_> False "false"
183%token <null_> Null "null"
184%token <true_> True "true"
185
186// ES3/ES5/WIE/JSC Reserved
187%token <word_> Break "break"
188%token <word_> Case "case"
189%token <word_> Catch "catch"
190%token <word_> Continue "continue"
191%token <word_> Default "default"
192%token <word_> Delete "delete"
193%token <word_> Do "do"
194%token <word_> Else "else"
195%token <word_> Finally "finally"
196%token <word_> For "for"
197%token <word_> Function "function"
198%token <word_> If "if"
199%token <word_> In "in"
200%token <word_> InstanceOf "instanceof"
201%token <word_> New "new"
202%token <word_> Return "return"
203%token <word_> Switch "switch"
204%token <this_> This "this"
205%token <word_> Throw "throw"
206%token <word_> Try "try"
207%token <word_> TypeOf "typeof"
208%token <word_> Var "var"
209%token <word_> Void "void"
210%token <word_> While "while"
211%token <word_> With "with"
212
213// ES3/IE6 Future, ES5/JSC Reserved
214%token <word_> Debugger "debugger"
215
216// ES3/ES5/IE6 Future, JSC Reserved
217%token <word_> Const "const"
218
219// ES3/ES5/IE6/JSC Future
220%token <word_> Class "class"
221%token <word_> Enum "enum"
222%token <word_> Export "export"
223%token <word_> Extends "extends"
224%token <word_> Import "import"
225%token <word_> Super "super"
226
227// ES3 Future, ES5 Strict Future
228%token <identifier_> Implements "implements"
229%token <identifier_> Interface "interface"
230%token <identifier_> Package "package"
231%token <identifier_> Private "private"
232%token <identifier_> Protected "protected"
233%token <identifier_> Public "public"
234%token <identifier_> Static "static"
235
236// ES3 Future
237%token <identifier_> Abstract "abstract"
238%token <identifier_> Boolean "boolean"
239%token <identifier_> Byte "byte"
240%token <identifier_> Char "char"
241%token <identifier_> Double "double"
242%token <identifier_> Final "final"
243%token <identifier_> Float "float"
244%token <identifier_> Goto "goto"
245%token <identifier_> Int "int"
246%token <identifier_> Long "long"
247%token <identifier_> Native "native"
248%token <identifier_> Short "short"
249%token <identifier_> Synchronized "synchronized"
250%token <identifier_> Throws "throws"
251%token <identifier_> Transient "transient"
252%token <identifier_> Volatile "volatile"
253
254// ES5 Strict
255%token <identifier_> Let "let"
256%token <identifier_> Yield "yield"
257
258// Woah?!
259%token <identifier_> Each "each"
260
261%token <identifier_> Identifier_
262%token <number_> NumericLiteral
263%token <string_> StringLiteral
264%token <literal_> RegularExpressionLiteral
265
266%type <expression_> AdditiveExpression
267%type <expression_> AdditiveExpressionNoBF
268%type <argument_> ArgumentList
269%type <argument_> ArgumentList_
270%type <argument_> ArgumentListOpt
271%type <argument_> Arguments
272%type <literal_> ArrayLiteral
273%type <expression_> AssigneeExpression
274%type <expression_> AssigneeExpression_
275%type <expression_> AssigneeExpressionNoBF
276%type <expression_> AssignmentExpression
277%type <assignment_> AssignmentExpression_
278%type <expression_> AssignmentExpressionNoBF
279%type <expression_> AssignmentExpressionNoIn
280%type <expression_> BitwiseANDExpression
281%type <expression_> BitwiseANDExpressionNoBF
282%type <expression_> BitwiseANDExpressionNoIn
283%type <statement_> Block
284%type <statement_> Block_
285%type <boolean_> BooleanLiteral
286%type <expression_> BitwiseORExpression
287%type <expression_> BitwiseORExpressionNoBF
288%type <expression_> BitwiseORExpressionNoIn
289%type <expression_> BitwiseXORExpression
290%type <expression_> BitwiseXORExpressionNoBF
291%type <expression_> BitwiseXORExpressionNoIn
292%type <statement_> BreakStatement
293%type <expression_> CallExpression
294%type <expression_> CallExpressionNoBF
295%type <clause_> CaseBlock
296%type <clause_> CaseClause
297%type <clause_> CaseClausesOpt
298%type <catch_> CatchOpt
299%type <statement_> CategoryStatement
300%type <expression_> ClassExpression
301%type <message_> ClassMessageDeclaration
302%type <message_> ClassMessageDeclarationListOpt
303%type <className_> ClassName
304%type <className_> ClassNameOpt
305%type <statement_> ClassStatement
306%type <expression_> ClassSuperOpt
307%type <field_> ClassFieldList
308%type <comprehension_> ComprehensionList
309%type <comprehension_> ComprehensionListOpt
310%type <expression_> ConditionalExpression
311%type <expression_> ConditionalExpressionNoBF
312%type <expression_> ConditionalExpressionNoIn
313%type <statement_> ContinueStatement
314%type <clause_> DefaultClause
315%type <statement_> DoWhileStatement
316%type <expression_> Element
317%type <expression_> ElementOpt
318%type <element_> ElementList
319%type <element_> ElementListOpt
320%type <statement_> ElseStatementOpt
321%type <statement_> EmptyStatement
322%type <expression_> EqualityExpression
323%type <expression_> EqualityExpressionNoBF
324%type <expression_> EqualityExpressionNoIn
325%type <expression_> Expression
326%type <expression_> ExpressionOpt
327%type <compound_> Expression_
328%type <expression_> ExpressionNoBF
329%type <expression_> ExpressionNoIn
330%type <compound_> ExpressionNoIn_
331%type <expression_> ExpressionNoInOpt
332%type <statement_> ExpressionStatement
333%type <finally_> FinallyOpt
334%type <comprehension_> ForComprehension
335%type <statement_> ForStatement
336%type <for_> ForStatementInitialiser
337%type <statement_> ForInStatement
338%type <forin_> ForInStatementInitialiser
339%type <functionParameter_> FormalParameterList
340%type <functionParameter_> FormalParameterList_
341%type <statement_> FunctionBody
342%type <statement_> FunctionDeclaration
343%type <expression_> FunctionExpression
344%type <identifier_> Identifier
345%type <identifier_> IdentifierOpt
346%type <comprehension_> IfComprehension
347%type <statement_> IfStatement
348%type <expression_> Initialiser
349%type <expression_> InitialiserOpt
350%type <expression_> InitialiserNoIn
351%type <expression_> InitialiserNoInOpt
352%type <statement_> IterationStatement
353%type <statement_> LabelledStatement
354%type <expression_> LeftHandSideExpression
355%type <expression_> LeftHandSideExpressionNoBF
356//%type <statement_> LetStatement
357%type <literal_> Literal
358%type <expression_> LogicalANDExpression
359%type <expression_> LogicalANDExpressionNoBF
360%type <expression_> LogicalANDExpressionNoIn
361%type <expression_> LogicalORExpression
362%type <expression_> LogicalORExpressionNoBF
363%type <expression_> LogicalORExpressionNoIn
364%type <member_> MemberAccess
365%type <expression_> MemberExpression
366%type <expression_> MemberExpression_
367%type <expression_> MemberExpressionNoBF
368%type <messageParameter_> MessageParameter
369%type <messageParameter_> MessageParameters
370%type <messageParameter_> MessageParameterList
371%type <messageParameter_> MessageParameterListOpt
372%type <bool_> MessageScope
373%type <expression_> MultiplicativeExpression
374%type <expression_> MultiplicativeExpressionNoBF
375%type <expression_> NewExpression
376%type <expression_> NewExpression_
377%type <expression_> NewExpressionNoBF
378%type <null_> NullLiteral
379%type <literal_> ObjectLiteral
380%type <expression_> PostfixExpression
381%type <expression_> PostfixExpressionNoBF
382%type <expression_> PrimaryExpression
383%type <expression_> PrimaryExpression_
384%type <expression_> PrimaryExpressionNoBF
385%type <statement_> Program
386%type <propertyName_> PropertyName
387%type <property_> PropertyNameAndValueList
388%type <property_> PropertyNameAndValueList_
389%type <property_> PropertyNameAndValueListOpt
390%type <literal_> RegularExpressionLiteral_
391%type <condition_> RegularExpressionToken
392%type <expression_> RelationalExpression
393%type <infix_> RelationalExpression_
394%type <expression_> RelationalExpressionNoBF
395%type <expression_> RelationalExpressionNoIn
396%type <infix_> RelationalExpressionNoIn_
397%type <statement_> ReturnStatement
398%type <selector_> SelectorExpression
399%type <selector_> SelectorExpression_
400%type <selector_> SelectorExpressionOpt
401%type <expression_> ShiftExpression
402%type <expression_> ShiftExpressionNoBF
403%type <statement_> SourceElement
404%type <statement_> SourceElements
405%type <statement_> Statement
406%type <statement_> Statement_
407%type <statement_> StatementList
408%type <statement_> StatementListOpt
409%type <statement_> SwitchStatement
410%type <statement_> ThrowStatement
411%type <statement_> TryStatement
412%type <expression_> TypeOpt
413%type <expression_> UnaryExpression
414%type <expression_> UnaryExpression_
415%type <expression_> UnaryExpressionNoBF
416%type <declaration_> VariableDeclaration
417%type <declaration_> VariableDeclarationNoIn
418%type <declarations_> VariableDeclarationList
419%type <declarations_> VariableDeclarationList_
420%type <declarations_> VariableDeclarationListNoIn
421%type <declarations_> VariableDeclarationListNoIn_
422%type <statement_> VariableStatement
423%type <statement_> WhileStatement
424%type <statement_> WithStatement
425%type <word_> Word
426%type <word_> WordOpt
427
428%type <expression_> MessageExpression
429%type <argument_> SelectorCall
430%type <argument_> SelectorCall_
431%type <argument_> SelectorList
432%type <argument_> VariadicCall
433
434%left "*" "/" "%"
435%left "+" "-"
436%left "<<" ">>" ">>>"
437%left "<" ">" "<=" ">=" "instanceof" "in"
438%left "==" "!=" "===" "!=="
439%left "&"
440%left "^"
441%left "|"
442%left "&&"
443%left "||"
444
445%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
446
447%nonassoc "if"
448%nonassoc "else"
449
450%start Program
451
452%%
453
454StrictSemi
455 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
456 ;
457
458Terminator_
459 : ";"
460 | "\n" StrictSemi
461 ;
462
463TerminatorOpt
464 : Terminator_
465 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
466 ;
467
468Terminator
469 : Terminator_
470 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
471 ;
472
473/*CommaOpt
474 : ","
475 |
476 ;*/
477
478NewLineOpt
479 : "\n"
480 |
481 ;
482
483WordOpt
484 : Word { $$ = $1; }
485 | { $$ = NULL; }
486 ;
487
488Word
489 : Identifier { $$ = $1; }
490 | "break" NewLineOpt { $$ = $1; }
491 | "case" { $$ = $1; }
492 | "catch" { $$ = $1; }
493 | "class" { $$ = $1; }
494 | "const" { $$ = $1; }
495 | "continue" NewLineOpt { $$ = $1; }
496 | "debugger" { $$ = $1; }
497 | "default" { $$ = $1; }
498 | "delete" { $$ = $1; }
499 | "do" { $$ = $1; }
500 | "else" { $$ = $1; }
501 | "enum" { $$ = $1; }
502 | "export" { $$ = $1; }
503 | "extends" { $$ = $1; }
504 | "false" { $$ = $1; }
505 | "finally" { $$ = $1; }
506 | "for" { $$ = $1; }
507 | "function" { $$ = $1; }
508 | "if" { $$ = $1; }
509 | "import" { $$ = $1; }
510 /* XXX: | "in" { $$ = $1; } */
511 /* XXX: | "instanceof" { $$ = $1; } */
512 | "new" { $$ = $1; }
513 | "null" { $$ = $1; }
514 | "return" NewLineOpt { $$ = $1; }
515 | "super" { $$ = $1; }
516 | "switch" { $$ = $1; }
517 | "this" { $$ = $1; }
518 | "throw" NewLineOpt { $$ = $1; }
519 | "true" { $$ = $1; }
520 | "try" { $$ = $1; }
521 | "typeof" { $$ = $1; }
522 | "var" { $$ = $1; }
523 | "void" { $$ = $1; }
524 | "while" { $$ = $1; }
525 | "with" { $$ = $1; }
526 ;
527
528Identifier
529 : Identifier_ { $$ = $1; }
530
531 | "implements" { $$ = $1; }
532 | "interface" { $$ = $1; }
533 | "package" { $$ = $1; }
534 | "private" { $$ = $1; }
535 | "protected" { $$ = $1; }
536 | "public" { $$ = $1; }
537 | "static" { $$ = $1; }
538
539 | "abstract" { $$ = $1; }
540 | "boolean" { $$ = $1; }
541 | "byte" { $$ = $1; }
542 | "char" { $$ = $1; }
543 | "double" { $$ = $1; }
544 | "final" { $$ = $1; }
545 | "float" { $$ = $1; }
546 | "goto" { $$ = $1; }
547 | "int" { $$ = $1; }
548 | "long" { $$ = $1; }
549 | "native" { $$ = $1; }
550 | "short" { $$ = $1; }
551 | "synchronized" { $$ = $1; }
552 | "throws" { $$ = $1; }
553 | "transient" { $$ = $1; }
554 | "volatile" { $$ = $1; }
555
556 | "let" { $$ = $1; }
557 | "yield" { $$ = $1; }
558
559 | "each" { $$ = $1; }
560 ;
561
562IdentifierOpt
563 : Identifier { $$ = $1; }
564 | { $$ = NULL; }
565 ;
566
567RegularExpressionToken
568 : "/" { $$ = CYDriver::RegExStart; }
569 | "/=" { $$ = CYDriver::RegExRest; }
570 ;
571
572RegularExpressionLiteral_
573 : RegularExpressionToken { driver.SetCondition($1); } RegularExpressionLiteral { $$ = $3; }
574 ;
575
576Literal
577 : NullLiteral { $$ = $1; }
578 | BooleanLiteral { $$ = $1; }
579 | NumericLiteral { $$ = $1; }
580 | StringLiteral { $$ = $1; }
581 | RegularExpressionLiteral_ { $$ = $1; }
582 ;
583
584NullLiteral
585 : "null" { $$ = $1; }
586 ;
587
588BooleanLiteral
589 : "true" { $$ = $1; }
590 | "false" { $$ = $1; }
591 ;
592
593/* 11.1 Primary Expressions {{{ */
594PrimaryExpression_
595 : "this" { $$ = $1; }
596 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
597 | Literal { $$ = $1; }
598 | ArrayLiteral { $$ = $1; }
599 | "(" Expression ")" { $$ = $2; }
600 ;
601
602PrimaryExpression
603 : ObjectLiteral { $$ = $1; }
604 | PrimaryExpression_ { $$ = $1; }
605 ;
606
607PrimaryExpressionNoBF
608 : PrimaryExpression_ { $$ = $1; }
609 ;
610/* }}} */
611/* 11.1.4 Array Initialiser {{{ */
612ArrayLiteral
613 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
614 ;
615
616Element
617 : AssignmentExpression { $$ = $1; }
618 ;
619
620ElementOpt
621 : Element { $$ = $1; }
622 | { $$ = NULL; }
623 ;
624
625ElementListOpt
626 : ElementList { $$ = $1; }
627 | { $$ = NULL; }
628 ;
629
630ElementList
631 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
632 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
633 ;
634/* }}} */
635/* 11.1.5 Object Initialiser {{{ */
636ObjectLiteral
637 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
638 ;
639
640PropertyNameAndValueList_
641 : "," PropertyNameAndValueList { $$ = $2; }
642 | { $$ = NULL; }
643 ;
644
645PropertyNameAndValueListOpt
646 : PropertyNameAndValueList { $$ = $1; }
647 | { $$ = NULL; }
648 ;
649
650PropertyNameAndValueList
651 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
652 ;
653
654PropertyName
655 : Identifier { $$ = $1; }
656 | StringLiteral { $$ = $1; }
657 | NumericLiteral { $$ = $1; }
658 ;
659/* }}} */
660
661/* 11.2 Left-Hand-Side Expressions {{{ */
662MemberExpression_
663 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
664 ;
665
666MemberAccess
667 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
668 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
669 ;
670
671MemberExpression
672 : PrimaryExpression { $$ = $1; }
673 | FunctionExpression { $$ = $1; }
674 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
675 | MemberExpression_ { $$ = $1; }
676 ;
677
678MemberExpressionNoBF
679 : PrimaryExpressionNoBF { $$ = $1; }
680 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
681 | MemberExpression_ { $$ = $1; }
682 ;
683
684NewExpression_
685 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
686 ;
687
688NewExpression
689 : MemberExpression { $$ = $1; }
690 | NewExpression_ { $$ = $1; }
691 ;
692
693NewExpressionNoBF
694 : MemberExpressionNoBF { $$ = $1; }
695 | NewExpression_ { $$ = $1; }
696 ;
697
698CallExpression
699 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
700 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
701 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
702 ;
703
704CallExpressionNoBF
705 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
706 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
707 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
708 ;
709
710ArgumentList_
711 : "," ArgumentList { $$ = $2; }
712 | { $$ = NULL; }
713 ;
714
715ArgumentListOpt
716 : ArgumentList { $$ = $1; }
717 | { $$ = NULL; }
718 ;
719
720ArgumentList
721 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
722 ;
723
724Arguments
725 : "(" ArgumentListOpt ")" { $$ = $2; }
726 ;
727
728LeftHandSideExpression
729 : NewExpression { $$ = $1; }
730 | CallExpression { $$ = $1; }
731 ;
732
733LeftHandSideExpressionNoBF
734 : NewExpressionNoBF { $$ = $1; }
735 | CallExpressionNoBF { $$ = $1; }
736 ;
737/* }}} */
738/* 11.3 Postfix Expressions {{{ */
739PostfixExpression
740 : AssigneeExpression { $$ = $1; }
741 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
742 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
743 ;
744
745PostfixExpressionNoBF
746 : AssigneeExpressionNoBF { $$ = $1; }
747 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
748 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
749 ;
750/* }}} */
751/* 11.4 Unary Operators {{{ */
752UnaryExpression_
753 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
754 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
755 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
756 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
757 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
758 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
759 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
760 | "+" UnaryExpression { $$ = $2; }
761 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
762 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
763 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
764 ;
765
766UnaryExpression
767 : PostfixExpression { $$ = $1; }
768 | UnaryExpression_ { $$ = $1; }
769 ;
770
771UnaryExpressionNoBF
772 : PostfixExpressionNoBF { $$ = $1; }
773 | UnaryExpression_ { $$ = $1; }
774 ;
775/* }}} */
776/* 11.5 Multiplicative Operators {{{ */
777MultiplicativeExpression
778 : UnaryExpression { $$ = $1; }
779 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
780 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
781 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
782 ;
783
784MultiplicativeExpressionNoBF
785 : UnaryExpressionNoBF { $$ = $1; }
786 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
787 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
788 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
789 ;
790/* }}} */
791/* 11.6 Additive Operators {{{ */
792AdditiveExpression
793 : MultiplicativeExpression { $$ = $1; }
794 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
795 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
796 ;
797
798AdditiveExpressionNoBF
799 : MultiplicativeExpressionNoBF { $$ = $1; }
800 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
801 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
802 ;
803/* }}} */
804/* 11.7 Bitwise Shift Operators {{{ */
805ShiftExpression
806 : AdditiveExpression { $$ = $1; }
807 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
808 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
809 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
810 ;
811
812ShiftExpressionNoBF
813 : AdditiveExpressionNoBF { $$ = $1; }
814 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
815 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
816 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
817 ;
818/* }}} */
819/* 11.8 Relational Operators {{{ */
820RelationalExpressionNoIn_
821 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
822 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
823 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
824 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
825 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
826 ;
827
828RelationalExpression_
829 : RelationalExpressionNoIn_ { $$ = $1; }
830 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
831 ;
832
833RelationalExpression
834 : ShiftExpression { $$ = $1; }
835 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
836 ;
837
838RelationalExpressionNoIn
839 : ShiftExpression { $$ = $1; }
840 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
841 ;
842
843RelationalExpressionNoBF
844 : ShiftExpressionNoBF { $$ = $1; }
845 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
846 ;
847/* }}} */
848/* 11.9 Equality Operators {{{ */
849EqualityExpression
850 : RelationalExpression { $$ = $1; }
851 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
852 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
853 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
854 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
855 ;
856
857EqualityExpressionNoIn
858 : RelationalExpressionNoIn { $$ = $1; }
859 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
860 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
861 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
862 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
863 ;
864
865EqualityExpressionNoBF
866 : RelationalExpressionNoBF { $$ = $1; }
867 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
868 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
869 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
870 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
871 ;
872/* }}} */
873/* 11.10 Binary Bitwise Operators {{{ */
874BitwiseANDExpression
875 : EqualityExpression { $$ = $1; }
876 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
877 ;
878
879BitwiseANDExpressionNoIn
880 : EqualityExpressionNoIn { $$ = $1; }
881 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
882 ;
883
884BitwiseANDExpressionNoBF
885 : EqualityExpressionNoBF { $$ = $1; }
886 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
887 ;
888
889BitwiseXORExpression
890 : BitwiseANDExpression { $$ = $1; }
891 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
892 ;
893
894BitwiseXORExpressionNoIn
895 : BitwiseANDExpressionNoIn { $$ = $1; }
896 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
897 ;
898
899BitwiseXORExpressionNoBF
900 : BitwiseANDExpressionNoBF { $$ = $1; }
901 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
902 ;
903
904BitwiseORExpression
905 : BitwiseXORExpression { $$ = $1; }
906 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
907 ;
908
909BitwiseORExpressionNoIn
910 : BitwiseXORExpressionNoIn { $$ = $1; }
911 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
912 ;
913
914BitwiseORExpressionNoBF
915 : BitwiseXORExpressionNoBF { $$ = $1; }
916 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
917 ;
918/* }}} */
919/* 11.11 Binary Logical Operators {{{ */
920LogicalANDExpression
921 : BitwiseORExpression { $$ = $1; }
922 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
923 ;
924
925LogicalANDExpressionNoIn
926 : BitwiseORExpressionNoIn { $$ = $1; }
927 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
928 ;
929
930LogicalANDExpressionNoBF
931 : BitwiseORExpressionNoBF { $$ = $1; }
932 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
933 ;
934
935LogicalORExpression
936 : LogicalANDExpression { $$ = $1; }
937 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
938 ;
939
940LogicalORExpressionNoIn
941 : LogicalANDExpressionNoIn { $$ = $1; }
942 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
943 ;
944
945LogicalORExpressionNoBF
946 : LogicalANDExpressionNoBF { $$ = $1; }
947 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
948 ;
949/* }}} */
950/* 11.12 Conditional Operator ( ? : ) {{{ */
951ConditionalExpression
952 : LogicalORExpression { $$ = $1; }
953 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
954 ;
955
956ConditionalExpressionNoIn
957 : LogicalORExpressionNoIn { $$ = $1; }
958 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
959 ;
960
961ConditionalExpressionNoBF
962 : LogicalORExpressionNoBF { $$ = $1; }
963 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
964 ;
965/* }}} */
966/* 11.13 Assignment Operators {{{ */
967AssignmentExpression_
968 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
969 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
970 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
971 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
972 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
973 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
974 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
975 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
976 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
977 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
978 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
979 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
980 ;
981
982AssigneeExpression
983 : LeftHandSideExpression { $$ = $1; }
984 | AssigneeExpression_ { $$ = $1; }
985 ;
986
987AssigneeExpressionNoBF
988 : LeftHandSideExpressionNoBF { $$ = $1; }
989 | AssigneeExpression_ { $$ = $1; }
990 ;
991
992AssignmentExpression
993 : ConditionalExpression { $$ = $1; }
994 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
995 ;
996
997AssignmentExpressionNoIn
998 : ConditionalExpressionNoIn { $$ = $1; }
999 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
1000 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
1001 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
1002 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
1003 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
1004 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
1005 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
1006 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
1007 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
1008 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
1009 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
1010 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
1011 ;
1012
1013AssignmentExpressionNoBF
1014 : ConditionalExpressionNoBF { $$ = $1; }
1015 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
1016 ;
1017/* }}} */
1018/* 11.14 Comma Operator {{{ */
1019Expression_
1020 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
1021 | { $$ = NULL; }
1022 ;
1023
1024ExpressionNoIn_
1025 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
1026 | { $$ = NULL; }
1027 ;
1028
1029ExpressionOpt
1030 : Expression { $$ = $1; }
1031 | { $$ = NULL; }
1032 ;
1033
1034ExpressionNoInOpt
1035 : ExpressionNoIn { $$ = $1; }
1036 | { $$ = NULL; }
1037 ;
1038
1039Expression
1040 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1041 ;
1042
1043ExpressionNoIn
1044 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1045 ;
1046
1047ExpressionNoBF
1048 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1049 ;
1050/* }}} */
1051
1052/* 12 Statements {{{ */
1053Statement_
1054 : Block { $$ = $1; }
1055 | VariableStatement { $$ = $1; }
1056 | EmptyStatement { $$ = $1; }
1057 | ExpressionStatement { $$ = $1; }
1058 | IfStatement { $$ = $1; }
1059 | IterationStatement { $$ = $1; }
1060 | ContinueStatement { $$ = $1; }
1061 | BreakStatement { $$ = $1; }
1062 | ReturnStatement { $$ = $1; }
1063 | WithStatement { $$ = $1; }
1064 | LabelledStatement { $$ = $1; }
1065 | SwitchStatement { $$ = $1; }
1066 | ThrowStatement { $$ = $1; }
1067 | TryStatement { $$ = $1; }
1068 ;
1069
1070Statement
1071 : Statement_ { $$ = $1; }
1072 ;
1073/* }}} */
1074/* 12.1 Block {{{ */
1075Block_
1076 : "{" StatementListOpt "}" { $$ = $2; }
1077 ;
1078
1079Block
1080 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1081 ;
1082
1083StatementList
1084 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
1085 ;
1086
1087StatementListOpt
1088 : StatementList { $$ = $1; }
1089 | { $$ = NULL; }
1090 ;
1091/* }}} */
1092/* 12.2 Variable Statement {{{ */
1093VariableStatement
1094 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1095 ;
1096
1097VariableDeclarationList_
1098 : "," VariableDeclarationList { $$ = $2; }
1099 | { $$ = NULL; }
1100 ;
1101
1102VariableDeclarationListNoIn_
1103 : "," VariableDeclarationListNoIn { $$ = $2; }
1104 | { $$ = NULL; }
1105 ;
1106
1107VariableDeclarationList
1108 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1109 ;
1110
1111VariableDeclarationListNoIn
1112 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1113 ;
1114
1115VariableDeclaration
1116 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1117 ;
1118
1119VariableDeclarationNoIn
1120 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1121 ;
1122
1123InitialiserOpt
1124 : Initialiser { $$ = $1; }
1125 | { $$ = NULL; }
1126 ;
1127
1128InitialiserNoInOpt
1129 : InitialiserNoIn { $$ = $1; }
1130 | { $$ = NULL; }
1131 ;
1132
1133Initialiser
1134 : "=" AssignmentExpression { $$ = $2; }
1135 ;
1136
1137InitialiserNoIn
1138 : "=" AssignmentExpressionNoIn { $$ = $2; }
1139 ;
1140/* }}} */
1141/* 12.3 Empty Statement {{{ */
1142EmptyStatement
1143 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1144 ;
1145/* }}} */
1146/* 12.4 Expression Statement {{{ */
1147ExpressionStatement
1148 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1149 ;
1150/* }}} */
1151/* 12.5 The if Statement {{{ */
1152ElseStatementOpt
1153 : "else" Statement { $$ = $2; }
1154 | %prec "if" { $$ = NULL; }
1155 ;
1156
1157IfStatement
1158 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1159 ;
1160/* }}} */
1161
1162/* 12.6 Iteration Statements {{{ */
1163IterationStatement
1164 : DoWhileStatement { $$ = $1; }
1165 | WhileStatement { $$ = $1; }
1166 | ForStatement { $$ = $1; }
1167 | ForInStatement { $$ = $1; }
1168 ;
1169/* }}} */
1170/* 12.6.1 The do-while Statement {{{ */
1171DoWhileStatement
1172 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1173 ;
1174/* }}} */
1175/* 12.6.2 The while Statement {{{ */
1176WhileStatement
1177 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1178 ;
1179/* }}} */
1180/* 12.6.3 The for Statement {{{ */
1181ForStatement
1182 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1183 ;
1184
1185ForStatementInitialiser
1186 : ExpressionNoInOpt { $$ = $1; }
1187 | "var" VariableDeclarationListNoIn { $$ = $2; }
1188 ;
1189/* }}} */
1190/* 12.6.4 The for-in Statement {{{ */
1191ForInStatement
1192 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1193 ;
1194
1195ForInStatementInitialiser
1196 : LeftHandSideExpression { $$ = $1; }
1197 | "var" VariableDeclarationNoIn { $$ = $2; }
1198 ;
1199/* }}} */
1200
1201/* 12.7 The continue Statement {{{ */
1202ContinueStatement
1203 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1204 ;
1205/* }}} */
1206/* 12.8 The break Statement {{{ */
1207BreakStatement
1208 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1209 ;
1210/* }}} */
1211/* 12.9 The return Statement {{{ */
1212ReturnStatement
1213 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1214 ;
1215/* }}} */
1216/* 12.10 The with Statement {{{ */
1217WithStatement
1218 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1219 ;
1220/* }}} */
1221
1222/* 12.11 The switch Statement {{{ */
1223SwitchStatement
1224 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1225 ;
1226
1227CaseBlock
1228 : "{" CaseClausesOpt "}" { $$ = $2; }
1229 ;
1230
1231CaseClausesOpt
1232 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1233 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1234 | { $$ = NULL; }
1235 ;
1236
1237CaseClause
1238 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1239 ;
1240
1241DefaultClause
1242 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1243 ;
1244/* }}} */
1245/* 12.12 Labelled Statements {{{ */
1246LabelledStatement
1247 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1248 ;
1249/* }}} */
1250/* 12.13 The throw Statement {{{ */
1251ThrowStatement
1252 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1253 ;
1254/* }}} */
1255/* 12.14 The try Statement {{{ */
1256TryStatement
1257 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1258 ;
1259
1260CatchOpt
1261 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
1262 | { $$ = NULL; }
1263 ;
1264
1265FinallyOpt
1266 : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); }
1267 | { $$ = NULL; }
1268 ;
1269/* }}} */
1270
1271/* 13 Function Definition {{{ */
1272FunctionDeclaration
1273 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
1274 ;
1275
1276FunctionExpression
1277 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
1278 ;
1279
1280FormalParameterList_
1281 : "," FormalParameterList { $$ = $2; }
1282 | { $$ = NULL; }
1283 ;
1284
1285FormalParameterList
1286 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1287 | { $$ = NULL; }
1288 ;
1289
1290FunctionBody
1291 : SourceElements { $$ = $1; }
1292 ;
1293/* }}} */
1294/* 14 Program {{{ */
1295Program
1296 : SourceElements { driver.program_ = $1; }
1297 ;
1298
1299SourceElements
1300 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1301 | { $$ = NULL; }
1302 ;
1303
1304SourceElement
1305 : Statement_ { $$ = $1; }
1306 | FunctionDeclaration { $$ = $1; }
1307 ;
1308/* }}} */
1309
1310/* Cycript: @class Declaration {{{ */
1311ClassSuperOpt
1312 : ":" MemberExpressionNoBF { $$ = $2; }
1313 | { $$ = NULL; }
1314 ;
1315
1316ClassFieldList
1317 : "{" "}" { $$ = NULL; }
1318 ;
1319
1320MessageScope
1321 : "+" { $$ = false; }
1322 | "-" { $$ = true; }
1323 ;
1324
1325TypeOpt
1326 : "(" Expression ")" { $$ = $2; }
1327 | { $$ = NULL; }
1328 ;
1329
1330MessageParameter
1331 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
1332 ;
1333
1334MessageParameterListOpt
1335 : MessageParameterList { $$ = $1; }
1336 | { $$ = NULL; }
1337 ;
1338
1339MessageParameterList
1340 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1341 ;
1342
1343MessageParameters
1344 : MessageParameterList { $$ = $1; }
1345 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
1346 ;
1347
1348ClassMessageDeclaration
1349 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
1350 ;
1351
1352ClassMessageDeclarationListOpt
1353 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1354 | { $$ = NULL; }
1355 ;
1356
1357ClassName
1358 : Identifier { $$ = $1; }
1359 | "(" AssignmentExpression ")" { $$ = $2; }
1360 ;
1361
1362ClassNameOpt
1363 : ClassName { $$ = $1; }
1364 | { $$ = NULL; }
1365 ;
1366
1367ClassExpression
1368 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); }
1369 ;
1370
1371ClassStatement
1372 : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); }
1373 ;
1374
1375CategoryStatement
1376 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
1377 ;
1378
1379PrimaryExpression
1380 : ClassExpression { $$ = $1; }
1381 ;
1382
1383Statement_
1384 : ClassStatement { $$ = $1; }
1385 | CategoryStatement { $$ = $1; }
1386 ;
1387/* }}} */
1388/* Cycript: Send Message {{{ */
1389VariadicCall
1390 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1391 | { $$ = NULL; }
1392 ;
1393
1394SelectorCall_
1395 : SelectorCall { $$ = $1; }
1396 | VariadicCall { $$ = $1; }
1397 ;
1398
1399SelectorCall
1400 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1401 ;
1402
1403SelectorList
1404 : SelectorCall { $$ = $1; }
1405 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1406 ;
1407
1408MessageExpression
1409 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
1410 ;
1411
1412SelectorExpressionOpt
1413 : SelectorExpression_ { $$ = $1; }
1414 | { $$ = NULL; }
1415 ;
1416
1417SelectorExpression_
1418 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1419 ;
1420
1421SelectorExpression
1422 : SelectorExpression_ { $$ = $1; }
1423 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1424 ;
1425
1426PrimaryExpression_
1427 : MessageExpression { $$ = $1; }
1428 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
1429 ;
1430/* }}} */
1431/* Cycript: Pointer Indirection/Addressing {{{ */
1432AssigneeExpression_
1433 : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
1434 ;
1435
1436UnaryExpression_
1437 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1438 ;
1439
1440MemberAccess
1441 : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
1442 ;
1443/* }}} */
1444/* ECMAScript5: Object Literal Trailing Comma {{{ */
1445PropertyNameAndValueList_
1446 : "," { $$ = NULL; }
1447 ;
1448/* }}} */
1449/* JavaScript 1.7: Array Comprehensions {{{ */
1450IfComprehension
1451 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
1452 ;
1453
1454ForComprehension
1455 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1456 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
1457 ;
1458
1459ComprehensionListOpt
1460 : ComprehensionList { $$ = $1; }
1461 | IfComprehension { $$ = $1; }
1462 | { $$ = NULL; }
1463 ;
1464
1465ComprehensionList
1466 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1467 ;
1468
1469PrimaryExpression_
1470 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
1471 ;
1472/* }}} */
1473/* JavaScript 1.7: for each {{{ */
1474ForInStatement
1475 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1476 ;
1477/* }}} */
1478/* JavaScript 1.7: let Statements {{{ *//*
1479LetStatement
1480 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
1481 ;
1482
1483Statement
1484 : LetStatement
1485 ;
1486*//* }}} */
1487/* JavaScript FTW: Function Statements {{{ */
1488Statement
1489 : FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $1; }
1490 ;
1491/* }}} */
1492
1493%%