]> git.saurik.com Git - cycript.git/blob - Cycript.y.in
e770815d4795cb98d9d44f34e8a1abe5d5aff862
[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_> AssigneeExpressionNoBF
293 %type <expression_> AssignmentExpression
294 %type <assignment_> AssignmentExpression_
295 %type <expression_> AssignmentExpressionNoBF
296 %type <expression_> AssignmentExpressionNoIn
297 %type <expression_> BitwiseANDExpression
298 %type <expression_> BitwiseANDExpressionNoBF
299 %type <expression_> BitwiseANDExpressionNoIn
300 %type <statement_> Block
301 %type <statement_> Block_
302 %type <boolean_> BooleanLiteral
303 %type <expression_> BitwiseORExpression
304 %type <expression_> BitwiseORExpressionNoBF
305 %type <expression_> BitwiseORExpressionNoIn
306 %type <expression_> BitwiseXORExpression
307 %type <expression_> BitwiseXORExpressionNoBF
308 %type <expression_> BitwiseXORExpressionNoIn
309 %type <statement_> BreakStatement
310 %type <expression_> CallExpression
311 %type <expression_> CallExpressionNoBF
312 %type <clause_> CaseBlock
313 %type <clause_> CaseClause
314 %type <clause_> CaseClausesOpt
315 %type <catch_> CatchOpt
316 %type <comprehension_> ComprehensionList
317 %type <comprehension_> ComprehensionListOpt
318 %type <expression_> ConditionalExpression
319 %type <expression_> ConditionalExpressionNoBF
320 %type <expression_> ConditionalExpressionNoIn
321 %type <statement_> ContinueStatement
322 %type <clause_> DefaultClause
323 %type <statement_> DoWhileStatement
324 %type <expression_> Element
325 %type <expression_> ElementOpt
326 %type <element_> ElementList
327 %type <element_> ElementListOpt
328 %type <statement_> ElseStatementOpt
329 %type <statement_> EmptyStatement
330 %type <expression_> EqualityExpression
331 %type <expression_> EqualityExpressionNoBF
332 %type <expression_> EqualityExpressionNoIn
333 %type <expression_> Expression
334 %type <expression_> ExpressionOpt
335 %type <compound_> Expression_
336 %type <expression_> ExpressionNoBF
337 %type <expression_> ExpressionNoIn
338 %type <compound_> ExpressionNoIn_
339 %type <expression_> ExpressionNoInOpt
340 %type <statement_> ExpressionStatement
341 %type <finally_> FinallyOpt
342 %type <comprehension_> ForComprehension
343 %type <statement_> ForStatement
344 %type <for_> ForStatementInitialiser
345 %type <statement_> ForInStatement
346 %type <forin_> ForInStatementInitialiser
347 %type <functionParameter_> FormalParameterList
348 %type <functionParameter_> FormalParameterList_
349 %type <statement_> FunctionBody
350 %type <statement_> FunctionDeclaration
351 %type <expression_> FunctionExpression
352 %type <identifier_> Identifier
353 %type <identifier_> IdentifierOpt
354 %type <comprehension_> IfComprehension
355 %type <statement_> IfStatement
356 %type <expression_> Initialiser
357 %type <expression_> InitialiserOpt
358 %type <expression_> InitialiserNoIn
359 %type <expression_> InitialiserNoInOpt
360 %type <statement_> IterationStatement
361 %type <statement_> LabelledStatement
362 %type <expression_> LeftHandSideExpression
363 %type <expression_> LeftHandSideExpressionNoBF
364 //%type <statement_> LetStatement
365 %type <literal_> Literal
366 %type <expression_> LogicalANDExpression
367 %type <expression_> LogicalANDExpressionNoBF
368 %type <expression_> LogicalANDExpressionNoIn
369 %type <expression_> LogicalORExpression
370 %type <expression_> LogicalORExpressionNoBF
371 %type <expression_> LogicalORExpressionNoIn
372 %type <member_> MemberAccess
373 %type <expression_> MemberExpression
374 %type <expression_> MemberExpression_
375 %type <expression_> MemberExpressionNoBF
376 %type <expression_> MultiplicativeExpression
377 %type <expression_> MultiplicativeExpressionNoBF
378 %type <expression_> NewExpression
379 %type <expression_> NewExpression_
380 %type <expression_> NewExpressionNoBF
381 %type <null_> NullLiteral
382 %type <literal_> ObjectLiteral
383 %type <expression_> PostfixExpression
384 %type <expression_> PostfixExpressionNoBF
385 %type <expression_> PrimaryExpression
386 %type <expression_> PrimaryExpression_
387 %type <expression_> PrimaryExpressionNoBF
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 <expression_> RelationalExpression
395 %type <infix_> RelationalExpression_
396 %type <expression_> RelationalExpressionNoBF
397 %type <expression_> RelationalExpressionNoIn
398 %type <infix_> RelationalExpressionNoIn_
399 %type <statement_> ReturnStatement
400 %type <expression_> ShiftExpression
401 %type <expression_> ShiftExpressionNoBF
402 %type <statement_> SourceElement
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_> UnaryAssigneeExpression
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 Literal
590 : NullLiteral { $$ = $1; }
591 | BooleanLiteral { $$ = $1; }
592 | NumericLiteral { $$ = $1; }
593 | StringLiteral { $$ = $1; }
594 | RegularExpressionLiteral { $$ = $1; }
595 ;
596
597 NullLiteral
598 : "null" { $$ = $1; }
599 ;
600
601 BooleanLiteral
602 : "true" { $$ = $1; }
603 | "false" { $$ = $1; }
604 ;
605
606 /* 11.1 Primary Expressions {{{ */
607 PrimaryExpression_
608 : ObjectLiteral { $$ = $1; }
609 | PrimaryExpressionNoBF_ { $$ = $1; }
610 ;
611
612 PrimaryExpressionNoBF_
613 : "this" { $$ = $1; }
614 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
615 | Literal { $$ = $1; }
616 | ArrayLiteral { $$ = $1; }
617 | "(" Expression ")" { $$ = $2; }
618 ;
619
620 LexBeginRegExp
621 : { driver.BeginCondition(CYDriver::RegExpCondition); }
622 ;
623
624 PrimaryExpression
625 : LexBeginRegExp PrimaryExpression_ { $$ = $2; }
626 ;
627
628 PrimaryExpressionNoBF
629 : PrimaryExpressionNoBF_ { $$ = $1; }
630 ;
631 /* }}} */
632 /* 11.1.4 Array Initialiser {{{ */
633 ArrayLiteral
634 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
635 ;
636
637 Element
638 : AssignmentExpression { $$ = $1; }
639 ;
640
641 ElementOpt
642 : Element { $$ = $1; }
643 | LexBeginRegExp { $$ = NULL; }
644 ;
645
646 ElementListOpt
647 : ElementList { $$ = $1; }
648 | LexBeginRegExp { $$ = NULL; }
649 ;
650
651 ElementList
652 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
653 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
654 ;
655 /* }}} */
656 /* 11.1.5 Object Initialiser {{{ */
657 ObjectLiteral
658 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
659 ;
660
661 PropertyNameAndValueList_
662 : "," PropertyNameAndValueList { $$ = $2; }
663 | { $$ = NULL; }
664 ;
665
666 PropertyNameAndValueListOpt
667 : PropertyNameAndValueList { $$ = $1; }
668 | { $$ = NULL; }
669 ;
670
671 PropertyNameAndValueList
672 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
673 ;
674
675 PropertyName
676 : Identifier { $$ = $1; }
677 | StringLiteral { $$ = $1; }
678 | NumericLiteral { $$ = $1; }
679 ;
680 /* }}} */
681
682 /* 11.2 Left-Hand-Side Expressions {{{ */
683 MemberExpression_
684 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
685 ;
686
687 MemberAccess
688 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
689 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
690 ;
691
692 MemberExpression
693 : PrimaryExpression { $$ = $1; }
694 | FunctionExpression { $$ = $1; }
695 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
696 | LexBeginRegExp MemberExpression_ { $$ = $2; }
697 ;
698
699 MemberExpressionNoBF
700 : PrimaryExpressionNoBF { $$ = $1; }
701 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
702 | MemberExpression_ { $$ = $1; }
703 ;
704
705 NewExpression_
706 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
707 ;
708
709 NewExpression
710 : MemberExpression { $$ = $1; }
711 | LexBeginRegExp NewExpression_ { $$ = $2; }
712 ;
713
714 NewExpressionNoBF
715 : MemberExpressionNoBF { $$ = $1; }
716 | NewExpression_ { $$ = $1; }
717 ;
718
719 CallExpression
720 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
721 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
722 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
723 ;
724
725 CallExpressionNoBF
726 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
727 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
728 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
729 ;
730
731 ArgumentList_
732 : "," ArgumentList { $$ = $2; }
733 | { $$ = NULL; }
734 ;
735
736 ArgumentListOpt
737 : ArgumentList { $$ = $1; }
738 | LexBeginRegExp { $$ = NULL; }
739 ;
740
741 ArgumentList
742 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
743 ;
744
745 Arguments
746 : "(" ArgumentListOpt ")" { $$ = $2; }
747 ;
748
749 LeftHandSideExpression
750 : NewExpression { $$ = $1; }
751 | CallExpression { $$ = $1; }
752 ;
753
754 LeftHandSideExpressionNoBF
755 : NewExpressionNoBF { $$ = $1; }
756 | CallExpressionNoBF { $$ = $1; }
757 ;
758 /* }}} */
759 /* 11.3 Postfix Expressions {{{ */
760 PostfixExpression
761 : AssigneeExpression { $$ = $1; }
762 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
763 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
764 ;
765
766 PostfixExpressionNoBF
767 : AssigneeExpressionNoBF { $$ = $1; }
768 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
769 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
770 ;
771 /* }}} */
772 /* 11.4 Unary Operators {{{ */
773 UnaryExpression_
774 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
775 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
776 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
777 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
778 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
779 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
780 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
781 | "+" UnaryExpression { $$ = new(driver.pool_) CYAffirm($2); }
782 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
783 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
784 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
785 ;
786
787 UnaryExpression
788 : PostfixExpression { $$ = $1; }
789 | LexBeginRegExp UnaryExpression_ { $$ = $2; }
790 ;
791
792 UnaryExpressionNoBF
793 : PostfixExpressionNoBF { $$ = $1; }
794 | UnaryExpression_ { $$ = $1; }
795 ;
796 /* }}} */
797 /* 11.5 Multiplicative Operators {{{ */
798 MultiplicativeExpression
799 : UnaryExpression { $$ = $1; }
800 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
801 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
802 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
803 ;
804
805 MultiplicativeExpressionNoBF
806 : UnaryExpressionNoBF { $$ = $1; }
807 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
808 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
809 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
810 ;
811 /* }}} */
812 /* 11.6 Additive Operators {{{ */
813 AdditiveExpression
814 : MultiplicativeExpression { $$ = $1; }
815 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
816 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
817 ;
818
819 AdditiveExpressionNoBF
820 : MultiplicativeExpressionNoBF { $$ = $1; }
821 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
822 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
823 ;
824 /* }}} */
825 /* 11.7 Bitwise Shift Operators {{{ */
826 ShiftExpression
827 : AdditiveExpression { $$ = $1; }
828 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
829 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
830 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
831 ;
832
833 ShiftExpressionNoBF
834 : AdditiveExpressionNoBF { $$ = $1; }
835 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
836 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
837 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
838 ;
839 /* }}} */
840 /* 11.8 Relational Operators {{{ */
841 RelationalExpressionNoIn_
842 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
843 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
844 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
845 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
846 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
847 ;
848
849 RelationalExpression_
850 : RelationalExpressionNoIn_ { $$ = $1; }
851 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
852 ;
853
854 RelationalExpression
855 : ShiftExpression { $$ = $1; }
856 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
857 ;
858
859 RelationalExpressionNoIn
860 : ShiftExpression { $$ = $1; }
861 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
862 ;
863
864 RelationalExpressionNoBF
865 : ShiftExpressionNoBF { $$ = $1; }
866 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
867 ;
868 /* }}} */
869 /* 11.9 Equality Operators {{{ */
870 EqualityExpression
871 : RelationalExpression { $$ = $1; }
872 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
873 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
874 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
875 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
876 ;
877
878 EqualityExpressionNoIn
879 : RelationalExpressionNoIn { $$ = $1; }
880 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
881 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
882 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
883 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
884 ;
885
886 EqualityExpressionNoBF
887 : RelationalExpressionNoBF { $$ = $1; }
888 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
889 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
890 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
891 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
892 ;
893 /* }}} */
894 /* 11.10 Binary Bitwise Operators {{{ */
895 BitwiseANDExpression
896 : EqualityExpression { $$ = $1; }
897 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
898 ;
899
900 BitwiseANDExpressionNoIn
901 : EqualityExpressionNoIn { $$ = $1; }
902 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
903 ;
904
905 BitwiseANDExpressionNoBF
906 : EqualityExpressionNoBF { $$ = $1; }
907 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
908 ;
909
910 BitwiseXORExpression
911 : BitwiseANDExpression { $$ = $1; }
912 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
913 ;
914
915 BitwiseXORExpressionNoIn
916 : BitwiseANDExpressionNoIn { $$ = $1; }
917 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
918 ;
919
920 BitwiseXORExpressionNoBF
921 : BitwiseANDExpressionNoBF { $$ = $1; }
922 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
923 ;
924
925 BitwiseORExpression
926 : BitwiseXORExpression { $$ = $1; }
927 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
928 ;
929
930 BitwiseORExpressionNoIn
931 : BitwiseXORExpressionNoIn { $$ = $1; }
932 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
933 ;
934
935 BitwiseORExpressionNoBF
936 : BitwiseXORExpressionNoBF { $$ = $1; }
937 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
938 ;
939 /* }}} */
940 /* 11.11 Binary Logical Operators {{{ */
941 LogicalANDExpression
942 : BitwiseORExpression { $$ = $1; }
943 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
944 ;
945
946 LogicalANDExpressionNoIn
947 : BitwiseORExpressionNoIn { $$ = $1; }
948 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
949 ;
950
951 LogicalANDExpressionNoBF
952 : BitwiseORExpressionNoBF { $$ = $1; }
953 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
954 ;
955
956 LogicalORExpression
957 : LogicalANDExpression { $$ = $1; }
958 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
959 ;
960
961 LogicalORExpressionNoIn
962 : LogicalANDExpressionNoIn { $$ = $1; }
963 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
964 ;
965
966 LogicalORExpressionNoBF
967 : LogicalANDExpressionNoBF { $$ = $1; }
968 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
969 ;
970 /* }}} */
971 /* 11.12 Conditional Operator ( ? : ) {{{ */
972 ConditionalExpression
973 : LogicalORExpression { $$ = $1; }
974 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
975 ;
976
977 ConditionalExpressionNoIn
978 : LogicalORExpressionNoIn { $$ = $1; }
979 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
980 ;
981
982 ConditionalExpressionNoBF
983 : LogicalORExpressionNoBF { $$ = $1; }
984 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
985 ;
986 /* }}} */
987 /* 11.13 Assignment Operators {{{ */
988 AssignmentExpression_
989 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
990 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
991 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
992 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
993 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
994 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
995 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
996 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
997 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
998 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
999 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
1000 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
1001 ;
1002
1003 AssigneeExpression
1004 : LeftHandSideExpression { $$ = $1; }
1005 | LexBeginRegExp UnaryAssigneeExpression { $$ = $2; }
1006 ;
1007
1008 AssigneeExpressionNoBF
1009 : LeftHandSideExpressionNoBF { $$ = $1; }
1010 | UnaryAssigneeExpression { $$ = $1; }
1011 ;
1012
1013 AssignmentExpression
1014 : ConditionalExpression { $$ = $1; }
1015 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
1016 ;
1017
1018 AssignmentExpressionNoIn
1019 : ConditionalExpressionNoIn { $$ = $1; }
1020 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
1021 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
1022 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
1023 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
1024 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
1025 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
1026 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
1027 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
1028 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
1029 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
1030 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
1031 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
1032 ;
1033
1034 AssignmentExpressionNoBF
1035 : ConditionalExpressionNoBF { $$ = $1; }
1036 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
1037 ;
1038 /* }}} */
1039 /* 11.14 Comma Operator {{{ */
1040 Expression_
1041 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
1042 | { $$ = NULL; }
1043 ;
1044
1045 ExpressionNoIn_
1046 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
1047 | { $$ = NULL; }
1048 ;
1049
1050 ExpressionOpt
1051 : Expression { $$ = $1; }
1052 | LexBeginRegExp { $$ = NULL; }
1053 ;
1054
1055 ExpressionNoInOpt
1056 : ExpressionNoIn { $$ = $1; }
1057 | LexBeginRegExp { $$ = NULL; }
1058 ;
1059
1060 Expression
1061 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1062 ;
1063
1064 ExpressionNoIn
1065 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1066 ;
1067
1068 ExpressionNoBF
1069 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1070 ;
1071 /* }}} */
1072
1073 /* 12 Statements {{{ */
1074 Statement_
1075 : Block { $$ = $1; }
1076 | VariableStatement { $$ = $1; }
1077 | EmptyStatement { $$ = $1; }
1078 | ExpressionStatement { $$ = $1; }
1079 | IfStatement { $$ = $1; }
1080 | IterationStatement { $$ = $1; }
1081 | ContinueStatement { $$ = $1; }
1082 | BreakStatement { $$ = $1; }
1083 | ReturnStatement { $$ = $1; }
1084 | WithStatement { $$ = $1; }
1085 | LabelledStatement { $$ = $1; }
1086 | SwitchStatement { $$ = $1; }
1087 | ThrowStatement { $$ = $1; }
1088 | TryStatement { $$ = $1; }
1089 ;
1090
1091 Statement
1092 : LexBeginRegExp Statement_ { $$ = $2; }
1093 ;
1094 /* }}} */
1095 /* 12.1 Block {{{ */
1096 Block_
1097 : "{" StatementListOpt "}" { $$ = $2; }
1098 ;
1099
1100 Block
1101 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1102 ;
1103
1104 StatementList
1105 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
1106 ;
1107
1108 StatementListOpt
1109 : StatementList { $$ = $1; }
1110 | LexBeginRegExp { $$ = NULL; }
1111 ;
1112 /* }}} */
1113 /* 12.2 Variable Statement {{{ */
1114 VariableStatement
1115 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1116 ;
1117
1118 VariableDeclarationList_
1119 : "," VariableDeclarationList { $$ = $2; }
1120 | { $$ = NULL; }
1121 ;
1122
1123 VariableDeclarationListNoIn_
1124 : "," VariableDeclarationListNoIn { $$ = $2; }
1125 | { $$ = NULL; }
1126 ;
1127
1128 VariableDeclarationList
1129 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1130 ;
1131
1132 VariableDeclarationListNoIn
1133 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1134 ;
1135
1136 VariableDeclaration
1137 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1138 ;
1139
1140 VariableDeclarationNoIn
1141 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1142 ;
1143
1144 InitialiserOpt
1145 : Initialiser { $$ = $1; }
1146 | { $$ = NULL; }
1147 ;
1148
1149 InitialiserNoInOpt
1150 : InitialiserNoIn { $$ = $1; }
1151 | { $$ = NULL; }
1152 ;
1153
1154 Initialiser
1155 : "=" AssignmentExpression { $$ = $2; }
1156 ;
1157
1158 InitialiserNoIn
1159 : "=" AssignmentExpressionNoIn { $$ = $2; }
1160 ;
1161 /* }}} */
1162 /* 12.3 Empty Statement {{{ */
1163 EmptyStatement
1164 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1165 ;
1166 /* }}} */
1167 /* 12.4 Expression Statement {{{ */
1168 ExpressionStatement
1169 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1170 ;
1171 /* }}} */
1172 /* 12.5 The if Statement {{{ */
1173 ElseStatementOpt
1174 : "else" Statement { $$ = $2; }
1175 | %prec "if" { $$ = NULL; }
1176 ;
1177
1178 IfStatement
1179 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1180 ;
1181 /* }}} */
1182
1183 /* 12.6 Iteration Statements {{{ */
1184 IterationStatement
1185 : DoWhileStatement { $$ = $1; }
1186 | WhileStatement { $$ = $1; }
1187 | ForStatement { $$ = $1; }
1188 | ForInStatement { $$ = $1; }
1189 ;
1190 /* }}} */
1191 /* 12.6.1 The do-while Statement {{{ */
1192 DoWhileStatement
1193 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1194 ;
1195 /* }}} */
1196 /* 12.6.2 The while Statement {{{ */
1197 WhileStatement
1198 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1199 ;
1200 /* }}} */
1201 /* 12.6.3 The for Statement {{{ */
1202 ForStatement
1203 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1204 ;
1205
1206 ForStatementInitialiser
1207 : ExpressionNoInOpt { $$ = $1; }
1208 | LexBeginRegExp "var" VariableDeclarationListNoIn { $$ = $3; }
1209 ;
1210 /* }}} */
1211 /* 12.6.4 The for-in Statement {{{ */
1212 ForInStatement
1213 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1214 ;
1215
1216 ForInStatementInitialiser
1217 : LeftHandSideExpression { $$ = $1; }
1218 | LexBeginRegExp "var" VariableDeclarationNoIn { $$ = $3; }
1219 ;
1220 /* }}} */
1221
1222 /* 12.7 The continue Statement {{{ */
1223 ContinueStatement
1224 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1225 ;
1226 /* }}} */
1227 /* 12.8 The break Statement {{{ */
1228 BreakStatement
1229 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1230 ;
1231 /* }}} */
1232 /* 12.9 The return Statement {{{ */
1233 ReturnStatement
1234 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1235 ;
1236 /* }}} */
1237 /* 12.10 The with Statement {{{ */
1238 WithStatement
1239 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1240 ;
1241 /* }}} */
1242
1243 /* 12.11 The switch Statement {{{ */
1244 SwitchStatement
1245 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1246 ;
1247
1248 CaseBlock
1249 : "{" CaseClausesOpt "}" { $$ = $2; }
1250 ;
1251
1252 CaseClausesOpt
1253 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1254 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1255 | { $$ = NULL; }
1256 ;
1257
1258 CaseClause
1259 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1260 ;
1261
1262 DefaultClause
1263 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1264 ;
1265 /* }}} */
1266 /* 12.12 Labelled Statements {{{ */
1267 LabelledStatement
1268 : Identifier ":" Statement { $$ = new(driver.pool_) CYLabel($1, $3); }
1269 ;
1270 /* }}} */
1271 /* 12.13 The throw Statement {{{ */
1272 ThrowStatement
1273 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1274 ;
1275 /* }}} */
1276 /* 12.14 The try Statement {{{ */
1277 TryStatement
1278 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1279 ;
1280
1281 CatchOpt
1282 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
1283 | { $$ = NULL; }
1284 ;
1285
1286 FinallyOpt
1287 : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); }
1288 | { $$ = NULL; }
1289 ;
1290 /* }}} */
1291
1292 /* 13 Function Definition {{{ */
1293 FunctionDeclaration
1294 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
1295 ;
1296
1297 FunctionExpression
1298 : LexBeginRegExp "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($3, $5, $8); }
1299 ;
1300
1301 FormalParameterList_
1302 : "," FormalParameterList { $$ = $2; }
1303 | { $$ = NULL; }
1304 ;
1305
1306 FormalParameterList
1307 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1308 | { $$ = NULL; }
1309 ;
1310
1311 FunctionBody
1312 : SourceElements { $$ = $1; }
1313 ;
1314 /* }}} */
1315 /* 14 Program {{{ */
1316 Program
1317 : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); }
1318 ;
1319
1320 SourceElements
1321 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1322 | LexBeginRegExp { $$ = NULL; }
1323 ;
1324
1325 SourceElement_
1326 : Statement_ { $$ = $1; }
1327 | FunctionDeclaration { $$ = $1; }
1328 ;
1329
1330 SourceElement
1331 : LexBeginRegExp SourceElement_ { $$ = $2; }
1332 ;
1333 /* }}} */
1334
1335 @begin ObjectiveC
1336 /* Cycript (Objective-C): @class Declaration {{{ */
1337 ClassSuperOpt
1338 /* XXX: why the hell did I choose MemberExpressionNoBF? */
1339 : ":" LexBeginRegExp MemberExpressionNoBF { $$ = $3; }
1340 | { $$ = NULL; }
1341 ;
1342
1343 ClassFieldList
1344 : "{" "}" { $$ = NULL; }
1345 ;
1346
1347 MessageScope
1348 : "+" { $$ = false; }
1349 | "-" { $$ = true; }
1350 ;
1351
1352 TypeOpt
1353 : "(" Expression ")" { $$ = $2; }
1354 | { $$ = NULL; }
1355 ;
1356
1357 MessageParameter
1358 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
1359 ;
1360
1361 MessageParameterListOpt
1362 : MessageParameterList { $$ = $1; }
1363 | { $$ = NULL; }
1364 ;
1365
1366 MessageParameterList
1367 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1368 ;
1369
1370 MessageParameters
1371 : MessageParameterList { $$ = $1; }
1372 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
1373 ;
1374
1375 ClassMessageDeclaration
1376 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
1377 ;
1378
1379 ClassMessageDeclarationListOpt
1380 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1381 | { $$ = NULL; }
1382 ;
1383
1384 ClassName
1385 : Identifier { $$ = $1; }
1386 | "(" AssignmentExpression ")" { $$ = $2; }
1387 ;
1388
1389 ClassNameOpt
1390 : ClassName { $$ = $1; }
1391 | { $$ = NULL; }
1392 ;
1393
1394 ClassExpression
1395 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); }
1396 ;
1397
1398 ClassStatement
1399 : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); }
1400 ;
1401
1402 CategoryStatement
1403 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
1404 ;
1405
1406 PrimaryExpression_
1407 : ClassExpression { $$ = $1; }
1408 ;
1409
1410 Statement_
1411 : ClassStatement { $$ = $1; }
1412 | CategoryStatement { $$ = $1; }
1413 ;
1414 /* }}} */
1415 /* Cycript (Objective-C): Send Message {{{ */
1416 VariadicCall
1417 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1418 | { $$ = NULL; }
1419 ;
1420
1421 SelectorCall_
1422 : SelectorCall { $$ = $1; }
1423 | VariadicCall { $$ = $1; }
1424 ;
1425
1426 SelectorCall
1427 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1428 ;
1429
1430 SelectorList
1431 : SelectorCall { $$ = $1; }
1432 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1433 ;
1434
1435 MessageExpression
1436 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
1437 | "[" LexBeginRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); }
1438 ;
1439
1440 SelectorExpressionOpt
1441 : SelectorExpression_ { $$ = $1; }
1442 | { $$ = NULL; }
1443 ;
1444
1445 SelectorExpression_
1446 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1447 ;
1448
1449 SelectorExpression
1450 : SelectorExpression_ { $$ = $1; }
1451 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1452 ;
1453
1454 PrimaryExpressionNoBF_
1455 : MessageExpression { $$ = $1; }
1456 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
1457 ;
1458 /* }}} */
1459 @end
1460
1461 @begin C
1462 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1463 UnaryAssigneeExpression
1464 : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
1465 ;
1466
1467 UnaryExpression_
1468 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1469 ;
1470
1471 MemberAccess
1472 : "->" "[" Expression "]" { $$ = new(driver.pool_) CYIndirectMember(NULL, $3); }
1473 | "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
1474 ;
1475 /* }}} */
1476 @end
1477
1478 @begin E4X
1479 /* 8.3 XML Initialiser Input Elements {{{ */
1480 XMLMarkup
1481 : XMLComment
1482 | XMLCDATA
1483 | XMLPI
1484 ;
1485 /* }}} */
1486 /* 11.1 Primary Expressions {{{ */
1487 PrimaryExpressionNoBF_
1488 : PropertyIdentifier
1489 | XMLInitialiser
1490 | XMLListInitialiser
1491 ;
1492
1493 PropertyIdentifier
1494 : AttributeIdentifier
1495 | QualifiedIdentifier
1496 | WildcardIdentifier
1497 ;
1498 /* }}} */
1499 /* 11.1.1 Attribute Identifiers {{{ */
1500 AttributeIdentifier
1501 : "@" PropertySelector
1502 | "@" QualifiedIdentifier
1503 | "@" "[" Expression "]"
1504 ;
1505
1506 PropertySelector
1507 : Identifier
1508 | WildcardIdentifier
1509 ;
1510 /* }}} */
1511 /* 11.1.2 Qualified Identifiers {{{ */
1512 QualifiedIdentifier
1513 : PropertySelector "::" PropertySelector
1514 | PropertySelector "::" "[" Expression "]"
1515 ;
1516 /* }}} */
1517 /* 11.1.3 Wildcard Identifiers {{{ */
1518 WildcardIdentifier
1519 : "*"
1520 ;
1521 /* }}} */
1522 /* 11.1.4 XML Initialiser {{{ */
1523 XMLInitialiser
1524 : XMLMarkup
1525 | XMLElement
1526 ;
1527
1528 XMLElement
1529 : "<" XMLTagContent XMLWhitespaceOpt "/>"
1530 | "<" XMLTagContent XMLWhitespace ">" XMLElementContentOpt "</" XMLTagName XMLWhitespaceOpt ">"
1531 ;
1532
1533 XMLTagContent
1534 : XMLTagName XMLAttributesOpt
1535 ;
1536
1537 XMLTagName
1538 : "{" Expression "}"
1539 | XMLName
1540 ;
1541
1542 XMLAttributes
1543 : XMLWhitespace "{" Expression "}"
1544 | XMLAttributeOpt XMLAttributes
1545 ;
1546
1547 XMLAttributesOpt
1548 : XMLAttributes
1549 |
1550 ;
1551
1552 XMLAttribute
1553 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt "{" Expression "}"
1554 | XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue
1555 ;
1556
1557 XMLAttributeOpt
1558 : XMLAttribute
1559 |
1560 ;
1561
1562 XMLElementContent
1563 : "{" Expression "}" XMLElementContentOpt
1564 | XMLMarkup XMLElementContentOpt
1565 | XMLText XMLElementContentOpt
1566 | XMLElement XMLElementContentOpt
1567 ;
1568
1569 XMLElementContentOpt
1570 : XMLElementContent
1571 |
1572 ;
1573 /* }}} */
1574 /* 11.1.5 XMLList Initialiser {{{ */
1575 XMLListInitialiser
1576 : "<>" XMLElementContent "</>"
1577 ;
1578 /* }}} */
1579 @end
1580
1581 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1582 PropertyNameAndValueList_
1583 : "," { $$ = NULL; }
1584 ;
1585 /* }}} */
1586 /* JavaScript 1.7: Array Comprehensions {{{ */
1587 IfComprehension
1588 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
1589 ;
1590
1591 ForComprehension
1592 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1593 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
1594 ;
1595
1596 ComprehensionListOpt
1597 : ComprehensionList { $$ = $1; }
1598 | IfComprehension { $$ = $1; }
1599 | { $$ = NULL; }
1600 ;
1601
1602 ComprehensionList
1603 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1604 ;
1605
1606 PrimaryExpressionNoBF_
1607 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
1608 ;
1609 /* }}} */
1610 /* JavaScript 1.7: for each {{{ */
1611 ForInStatement
1612 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1613 ;
1614 /* }}} */
1615 /* JavaScript 1.7: let Statements {{{ *//*
1616 LetStatement
1617 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
1618 ;
1619
1620 Statement_
1621 : LetStatement
1622 ;
1623 *//* }}} */
1624 /* JavaScript FTW: Function Statements {{{ */
1625 Statement
1626 : LexBeginRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; }
1627 ;
1628 /* }}} */
1629
1630 %%