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