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