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