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