]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
Reorganize typed identifier storage for other uses.
[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 CYProgram *program_;
77 CYProperty *property_;
78 CYPropertyName *propertyName_;
79 CYRubyProc *rubyProc_;
80 CYStatement *statement_;
81 CYString *string_;
82 CYThis *this_;
83 CYTrue *true_;
84 CYTypeModifier *type_;
85 CYTypedIdentifier *typed_;
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_> EncodedType
475 %type <expression_> MessageExpression
476 %type <messageParameter_> MessageParameter
477 %type <messageParameter_> MessageParameters
478 %type <messageParameter_> MessageParameterList
479 %type <messageParameter_> MessageParameterListOpt
480 %type <bool_> MessageScope
481 %type <type_> ModifiedType
482 %type <typed_> PrefixedType
483 %type <argument_> SelectorCall_
484 %type <argument_> SelectorCall
485 %type <selector_> SelectorExpression_
486 %type <selector_> SelectorExpression
487 %type <selector_> SelectorExpressionOpt
488 %type <argument_> SelectorList
489 %type <word_> SelectorWordOpt
490 %type <typed_> SuffixedType
491 %type <expression_> TypeOpt
492 %type <typed_> TypedIdentifier
493 %type <argument_> VariadicCall
494 @end
495
496 @begin E4X
497 %type <propertyIdentifier_> PropertyIdentifier_
498 %type <selector_> PropertySelector_
499 %type <selector_> PropertySelector
500 %type <identifier_> QualifiedIdentifier_
501 %type <identifier_> QualifiedIdentifier
502 %type <identifier_> WildcardIdentifier
503 %type <identifier_> XMLComment
504 %type <identifier_> XMLCDATA
505 %type <identifier_> XMLElement
506 %type <identifier_> XMLElementContent
507 %type <identifier_> XMLMarkup
508 %type <identifier_> XMLPI
509
510 %type <attribute_> AttributeIdentifier
511 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
512 %type <expression_> PropertyIdentifier
513 %type <expression_> XMLListInitialiser
514 %type <expression_> XMLInitialiser
515 @end
516 /* }}} */
517 /* Token Priorities {{{ */
518 %nonassoc ""
519 %left "++" "--"
520
521 %nonassoc "if"
522 %nonassoc "else"
523 /* }}} */
524
525 %start Program
526
527 %%
528
529 /* Lexer State {{{ */
530 LexPushInOn
531 : { driver.in_.push(true); }
532 ;
533
534 LexPushInOff
535 : { driver.in_.push(false); }
536 ;
537
538 LexPopIn
539 : { driver.in_.pop(); }
540 ;
541
542 LexSetRegExp
543 : { driver.SetCondition(CYDriver::RegExpCondition); }
544 ;
545
546 LexNoBrace
547 : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
548 ;
549
550 LexNoFunction
551 : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
552 ;
553
554 LexNoAtImplementation
555 : { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
556 ;
557
558 LexSetStatement
559 : LexNoBrace LexNoFunction LexNoAtImplementation
560 ;
561 /* }}} */
562 /* Virtual Tokens {{{ */
563 BRACE
564 : "{"
565 | "\n{"
566 ;
567
568 Var_
569 : "var"
570 ;
571 /* }}} */
572
573 /* 7.6 Identifier Names and Identifiers {{{ */
574 IdentifierName
575 : Word { $$ = $1; }
576 ;
577
578 NewLineOpt
579 : "\n"
580 |
581 ;
582
583 Word
584 : Identifier { $$ = $1; }
585 | "auto" { $$ = $1; }
586 | "break" NewLineOpt { $$ = $1; }
587 | "case" { $$ = $1; }
588 | "catch" { $$ = $1; }
589 | "class" { $$ = $1; }
590 | "const" { $$ = $1; }
591 | "continue" NewLineOpt { $$ = $1; }
592 | "debugger" { $$ = $1; }
593 | "default" { $$ = $1; }
594 | "delete" { $$ = $1; }
595 | "do" { $$ = $1; }
596 | "else" { $$ = $1; }
597 | "enum" { $$ = $1; }
598 | "export" { $$ = $1; }
599 | "extends" { $$ = $1; }
600 | "false" { $$ = $1; }
601 | "finally" { $$ = $1; }
602 /* XXX: | "for" { $$ = $1; } */
603 | "function" { $$ = $1; }
604 | "if" { $$ = $1; }
605 | "import" { $$ = $1; }
606 /* XXX: | "in" { $$ = $1; } */
607 | "!in" { $$ = $1; }
608 /* XXX: | "instanceof" { $$ = $1; } */
609
610 // XXX: as it currently is not an Identifier
611 | "let" { $$ = $1; }
612
613 | "new" { $$ = $1; }
614 | "null" { $$ = $1; }
615 | "return" NewLineOpt { $$ = $1; }
616 | "super" { $$ = $1; }
617 | "switch" { $$ = $1; }
618 | "this" { $$ = $1; }
619 | "throw" NewLineOpt { $$ = $1; }
620 | "true" { $$ = $1; }
621 | "try" { $$ = $1; }
622 | "typeof" { $$ = $1; }
623 | "var" { $$ = $1; }
624 | "void" { $$ = $1; }
625 | "while" { $$ = $1; }
626 | "with" { $$ = $1; }
627 ;
628
629 WordOpt
630 : Word { $$ = $1; }
631 | { $$ = NULL; }
632 ;
633
634 Identifier
635 : Identifier_ { $$ = $1; }
636
637 | "implements" { $$ = $1; }
638 | "interface" { $$ = $1; }
639 | "package" { $$ = $1; }
640 | "private" { $$ = $1; }
641 | "protected" { $$ = $1; }
642 | "public" { $$ = $1; }
643 | "static" { $$ = $1; }
644
645 | "abstract" { $$ = $1; }
646 | "boolean" { $$ = $1; }
647 | "byte" { $$ = $1; }
648 | "char" { $$ = $1; }
649 | "double" { $$ = $1; }
650 | "final" { $$ = $1; }
651 | "float" { $$ = $1; }
652 | "goto" { $$ = $1; }
653 | "int" { $$ = $1; }
654 | "long" { $$ = $1; }
655 | "native" { $$ = $1; }
656 | "short" { $$ = $1; }
657 | "synchronized" { $$ = $1; }
658 | "throws" { $$ = $1; }
659 | "transient" { $$ = $1; }
660 | "volatile" { $$ = $1; }
661
662 // XXX: currently I only have this as Word
663 // | "let" { $$ = $1; }
664
665 | "yield" { $$ = $1; }
666
667 | "each" { $$ = $1; }
668 | "of" { $$ = $1; }
669 ;
670
671 IdentifierOpt
672 : Identifier { $$ = $1; }
673 | { $$ = NULL; }
674 ;
675 /* }}} */
676
677 /* 7.8 Literals {{{ */
678 Literal
679 : NullLiteral { $$ = $1; }
680 | ValueLiteral { $$ = $1; }
681 ;
682
683 ValueLiteral
684 : BooleanLiteral { $$ = $1; }
685 | NumericLiteral { $$ = $1; }
686 | StringLiteral { $$ = $1; }
687 | RegularExpressionLiteral { $$ = $1; }
688 ;
689 /* }}} */
690 /* 7.8.1 Null Literals {{{ */
691 NullLiteral
692 : "null" { $$ = $1; }
693 ;
694 /* }}} */
695 /* 7.8.2 Boolean Literals {{{ */
696 BooleanLiteral
697 : "true" { $$ = $1; }
698 | "false" { $$ = $1; }
699 ;
700 /* }}} */
701
702 /* 7.9 Automatic Semicolon Insertion {{{ */
703 StrictSemi
704 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
705 ;
706
707 Terminator
708 : ";"
709 | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
710 ;
711
712 TerminatorOpt
713 : ";"
714 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
715 ;
716 /* }}} */
717
718 /* 11.1 Primary Expressions {{{ */
719 Parenthetical
720 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
721 ;
722
723 ParentheticalOpt
724 : Parenthetical { $$ = $1; }
725 | { $$ = NULL; }
726 ;
727
728 Variable
729 : Identifier { $$ = CYNew CYVariable($1); }
730 ;
731
732 PrimaryExpression
733 : "this" { $$ = $1; }
734 | Variable { $$ = $1; }
735 | Literal { $$ = $1; }
736 | ArrayLiteral { $$ = $1; }
737 | ObjectLiteral { $$ = $1; }
738 | FunctionExpression { $$ = $1; }
739 | Parenthetical { $$ = $1; }
740 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
741 ;
742 /* }}} */
743 /* 11.1.4.1 Array Initialiser {{{ */
744 ArrayLiteral
745 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
746 ;
747
748 Element
749 : AssignmentExpression { $$ = $1; }
750 ;
751
752 ElementOpt
753 : Element { $$ = $1; }
754 | LexSetRegExp { $$ = NULL; }
755 ;
756
757 ElementList
758 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
759 | Element { $$ = CYNew CYElement($1, NULL); }
760 ;
761
762 ElementListOpt
763 : ElementList { $$ = $1; }
764 | LexSetRegExp { $$ = NULL; }
765 ;
766 /* }}} */
767 /* 11.1.4.2 Array Comprehension {{{ */
768 PrimaryExpression
769 : "[" LexPushInOff AssignmentExpression ComprehensionForList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
770 ;
771
772 ComprehensionForList
773 : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); }
774 | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); }
775 ;
776
777 ComprehensionForListOpt
778 : ComprehensionForList { $$ = $1; }
779 | "if" Expression { $$ = CYNew CYIfComprehension($2); }
780 | { $$ = NULL; }
781 ;
782 /* }}} */
783 /* 11.1.5 Object Initialiser {{{ */
784 ObjectLiteral
785 : BRACE LexPushInOff PropertyDefinitionListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
786 ;
787
788 PropertyDefinitionList_
789 : "," PropertyDefinitionList { $$ = $2; }
790 | "," { $$ = NULL; }
791 | { $$ = NULL; }
792 ;
793
794 PropertyDefinitionList
795 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
796 ;
797
798 PropertyDefinitionListOpt
799 : PropertyDefinitionList { $$ = $1; }
800 | { $$ = NULL; }
801 ;
802
803 PropertyDefinition
804 // XXX: this should be IdentifierName
805 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
806 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
807 //| MethodDefinition
808 ;
809
810 PropertyName_
811 : IdentifierName { $$ = $1; }
812 | StringLiteral { $$ = $1; }
813 | NumericLiteral { $$ = $1; }
814 ;
815
816 PropertyName
817 : LexSetRegExp PropertyName_ { $$ = $2; }
818 ;
819 /* }}} */
820
821 /* 11.2 Left-Hand-Side Expressions {{{ */
822 MemberAccess
823 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
824 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
825 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
826 ;
827
828 MemberExpression_
829 : MemberExpression { $$ = $1; }
830 //| "super" { $$ = $1; }
831 ;
832
833 MemberExpression
834 : LexSetRegExp PrimaryExpression { $$ = $2; }
835 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
836 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
837 ;
838
839 NewExpression
840 : MemberExpression { $$ = $1; }
841 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
842 ;
843
844 CallExpression_
845 : MemberExpression_
846 | CallExpression
847 ;
848
849 CallExpression
850 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
851 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
852 ;
853
854 Arguments
855 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
856 ;
857
858 ArgumentList_
859 : "," ArgumentList { $$ = $2; }
860 | { $$ = NULL; }
861 ;
862
863 ArgumentList
864 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
865 ;
866
867 ArgumentListOpt
868 : ArgumentList { $$ = $1; }
869 | LexSetRegExp { $$ = NULL; }
870 ;
871
872 LeftHandSideExpression
873 : NewExpression { $$ = $1; }
874 | CallExpression { $$ = $1; }
875 ;
876 /* }}} */
877 /* 11.3 Postfix Expressions {{{ */
878 PostfixExpression
879 : %prec "" LeftHandSideExpression { $$ = $1; }
880 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
881 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
882 ;
883 /* }}} */
884 /* 11.4 Unary Operators {{{ */
885 UnaryExpression_
886 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
887 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
888 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
889 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
890 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
891 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
892 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
893 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
894 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
895 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
896 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
897 ;
898
899 UnaryExpression
900 : PostfixExpression { $$ = $1; }
901 | LexSetRegExp UnaryExpression_ { $$ = $2; }
902 ;
903 /* }}} */
904 /* 11.5 Multiplicative Operators {{{ */
905 MultiplicativeExpression
906 : UnaryExpression { $$ = $1; }
907 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
908 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
909 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
910 ;
911 /* }}} */
912 /* 11.6 Additive Operators {{{ */
913 AdditiveExpression
914 : MultiplicativeExpression { $$ = $1; }
915 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
916 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
917 ;
918 /* }}} */
919 /* 11.7 Bitwise Shift Operators {{{ */
920 ShiftExpression
921 : AdditiveExpression { $$ = $1; }
922 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
923 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
924 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
925 ;
926 /* }}} */
927 /* 11.8 Relational Operators {{{ */
928 RelationalExpression
929 : ShiftExpression { $$ = $1; }
930 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
931 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
932 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
933 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
934 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
935 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
936 ;
937 /* }}} */
938 /* 11.9 Equality Operators {{{ */
939 EqualityExpression
940 : RelationalExpression { $$ = $1; }
941 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
942 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
943 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
944 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
945 ;
946 /* }}} */
947 /* 11.10 Binary Bitwise Operators {{{ */
948 BitwiseANDExpression
949 : EqualityExpression { $$ = $1; }
950 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
951 ;
952
953 BitwiseXORExpression
954 : BitwiseANDExpression { $$ = $1; }
955 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
956 ;
957
958 BitwiseORExpression
959 : BitwiseXORExpression { $$ = $1; }
960 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
961 ;
962 /* }}} */
963 /* 11.11 Binary Logical Operators {{{ */
964 LogicalANDExpression
965 : BitwiseORExpression { $$ = $1; }
966 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
967 ;
968
969 LogicalORExpression
970 : LogicalANDExpression { $$ = $1; }
971 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
972 ;
973 /* }}} */
974 /* 11.12 Conditional Operator ( ? : ) {{{ */
975 ConditionalExpression
976 : LogicalORExpression { $$ = $1; }
977 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
978 ;
979 /* }}} */
980 /* 11.13 Assignment Operators {{{ */
981 AssignmentExpression
982 : ConditionalExpression { $$ = $1; }
983 | ArrowFunction { $$ = $1; }
984 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
985 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
986 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
987 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
988 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
989 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
990 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
991 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
992 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
993 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
994 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
995 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
996 ;
997 /* }}} */
998 /* 11.14 Comma Operator {{{ */
999 Expression_
1000 : "," Expression { $$ = $2; }
1001 | { $$ = CYNew CYCompound(); }
1002 ;
1003
1004 Expression
1005 : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
1006 ;
1007
1008 ExpressionOpt
1009 : Expression { $$ = $1; }
1010 | LexSetRegExp { $$ = NULL; }
1011 ;
1012 /* }}} */
1013
1014 /* 12 Statements {{{ */
1015 Statement__
1016 : Block { $$ = $1; }
1017 | VariableStatement { $$ = $1; }
1018 | EmptyStatement { $$ = $1; }
1019 | IfStatement { $$ = $1; }
1020 | BreakableStatement { $$ = $1; }
1021 | ContinueStatement { $$ = $1; }
1022 | BreakStatement { $$ = $1; }
1023 | ReturnStatement { $$ = $1; }
1024 | WithStatement { $$ = $1; }
1025 | LabelledStatement { $$ = $1; }
1026 | ThrowStatement { $$ = $1; }
1027 | TryStatement { $$ = $1; }
1028 | DebuggerStatement { $$ = $1; }
1029 ;
1030
1031 Statement_
1032 : LexSetRegExp Statement__ { $$ = $2; }
1033 | ExpressionStatement { $$ = $1; }
1034 ;
1035
1036 Statement
1037 : LexSetStatement Statement_ { $$ = $2; }
1038 ;
1039
1040 Declaration__
1041 : FunctionDeclaration { $$ = $1; }
1042 | LexicalDeclaration { $$ = $1; }
1043 ;
1044
1045 Declaration_
1046 : LexSetRegExp Declaration__ { $$ = $2; }
1047 ;
1048
1049 Declaration
1050 : LexSetStatement Declaration_ { $$ = $2; }
1051 ;
1052
1053 BreakableStatement
1054 : IterationStatement { $$ = $1; }
1055 | SwitchStatement { $$ = $1; }
1056 ;
1057 /* }}} */
1058 /* 12.1 Block {{{ */
1059 Block_
1060 : BRACE StatementListOpt "}" { $$ = $2; }
1061 ;
1062
1063 Block
1064 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1065 ;
1066
1067 StatementList
1068 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1069 ;
1070
1071 StatementListOpt
1072 : StatementList { $$ = $1; }
1073 | LexSetStatement LexSetRegExp { $$ = NULL; }
1074 ;
1075
1076 StatementListItem
1077 : Statement { $$ = $1; }
1078 | Declaration { $$ = $1; }
1079 ;
1080 /* }}} */
1081
1082 /* 12.2 Declarations {{{ */
1083 BindingIdentifier
1084 : Identifier { $$ = $1; }
1085 ;
1086
1087 Binding
1088 : BindingIdentifier
1089 ;
1090
1091 // XXX: BindingPattern
1092 /* }}} */
1093 /* 12.2.1 Let and Const Declarations {{{ */
1094 LexicalDeclaration
1095 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1096 ;
1097
1098 LetOrConst
1099 : "let"
1100 | "const"
1101 ;
1102 /* }}} */
1103 /* 12.2.2 Variable Statement {{{ */
1104 VariableStatement
1105 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1106 ;
1107
1108 VariableDeclarationList_
1109 : "," VariableDeclarationList { $$ = $2; }
1110 | { $$ = NULL; }
1111 ;
1112
1113 VariableDeclarationList
1114 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1115 ;
1116
1117 VariableDeclaration
1118 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1119 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1120 ;
1121
1122 Initialiser
1123 : "=" AssignmentExpression { $$ = $2; }
1124 ;
1125
1126 InitialiserOpt
1127 : Initialiser { $$ = $1; }
1128 | { $$ = NULL; }
1129 ;
1130 /* }}} */
1131 /* 12.2.4 Destructuring Binding Patterns {{{ */
1132 // XXX: *
1133
1134 BindingElement
1135 : SingleNameBinding { $$ = $1; }
1136 ;
1137
1138 SingleNameBinding
1139 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1140 ;
1141 /* }}} */
1142
1143 /* 12.3 Empty Statement {{{ */
1144 EmptyStatement
1145 : ";" { $$ = CYNew CYEmpty(); }
1146 ;
1147 /* }}} */
1148 /* 12.4 Expression Statement {{{ */
1149 ExpressionStatement
1150 : Expression Terminator { $$ = CYNew CYExpress($1); }
1151 ;
1152 /* }}} */
1153 /* 12.5 The if Statement {{{ */
1154 ElseStatementOpt
1155 : "else" Statement { $$ = $2; }
1156 | %prec "if" { $$ = NULL; }
1157 ;
1158
1159 IfStatement
1160 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1161 ;
1162 /* }}} */
1163
1164 /* 12.6.1 The do-while Statement {{{ */
1165 IterationStatement
1166 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1167 ;
1168 /* }}} */
1169 /* 12.6.2 The while Statement {{{ */
1170 IterationStatement
1171 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1172 ;
1173 /* }}} */
1174 /* 12.6.3 The for Statement {{{ */
1175 IterationStatement
1176 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1177 ;
1178
1179 ForStatementInitialiser
1180 : ExpressionOpt { $$ = $1; }
1181 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1182 ;
1183 /* }}} */
1184 /* 12.6.4 The for-in and for-of Statements {{{ */
1185 IterationStatement
1186 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1187 | "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "of" Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1188 ;
1189
1190 ForInStatementInitialiser
1191 : LeftHandSideExpression { $$ = $1; }
1192 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1193 ;
1194 /* }}} */
1195
1196 /* 12.7 The continue Statement {{{ */
1197 ContinueStatement
1198 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1199 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1200 ;
1201 /* }}} */
1202 /* 12.8 The break Statement {{{ */
1203 BreakStatement
1204 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1205 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1206 ;
1207 /* }}} */
1208 /* 12.9 The return Statement {{{ */
1209 ReturnStatement
1210 : "return" "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1211 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1212 ;
1213 /* }}} */
1214 /* 12.10 The with Statement {{{ */
1215 WithStatement
1216 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1217 ;
1218 /* }}} */
1219
1220 /* 12.11 The switch Statement {{{ */
1221 SwitchStatement
1222 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1223 ;
1224
1225 CaseBlock
1226 : BRACE CaseClausesOpt "}" { $$ = $2; }
1227 ;
1228
1229 CaseClause
1230 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1231 ;
1232
1233 CaseClausesOpt
1234 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1235 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1236 | { $$ = NULL; }
1237 ;
1238
1239 DefaultClause
1240 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1241 ;
1242 /* }}} */
1243 /* 12.12 Labelled Statements {{{ */
1244 LabelledStatement
1245 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1246 ;
1247 /* }}} */
1248 /* 12.13 The throw Statement {{{ */
1249 ThrowStatement
1250 : "throw" "\n" StrictSemi { YYABORT; }
1251 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1252 ;
1253 /* }}} */
1254 /* 12.14 The try Statement {{{ */
1255 TryStatement
1256 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1257 ;
1258
1259 CatchOpt
1260 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1261 | { $$ = NULL; }
1262 ;
1263
1264 FinallyOpt
1265 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1266 | { $$ = NULL; }
1267 ;
1268 /* }}} */
1269 /* 12.14 The debugger Statement {{{ */
1270 DebuggerStatement
1271 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1272 ;
1273 /* }}} */
1274
1275 /* 13.1 Function Definitions {{{ */
1276 FunctionDeclaration
1277 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1278 ;
1279
1280 FunctionExpression
1281 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1282 ;
1283
1284 FormalParameterList_
1285 : "," FormalParameterList { $$ = $2; }
1286 | { $$ = NULL; }
1287 ;
1288
1289 FormalParameterList
1290 // XXX: : FunctionRestParameter { $$ = $1; }
1291 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1292 ;
1293
1294 FormalParameterListOpt
1295 : FormalParameterList
1296 | { $$ = NULL; }
1297 ;
1298
1299 /* XXX: FunctionRestParameter
1300 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1301 ;*/
1302
1303 FormalParameter
1304 : BindingElement { $$ = $1; }
1305 ;
1306
1307 FunctionBody
1308 : StatementListOpt { $$ = $1; }
1309 ;
1310 /* }}} */
1311 /* 13.2 Arrow Function Definitions {{{ */
1312 ArrowFunction
1313 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1314 ;
1315
1316 ArrowParameters
1317 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1318 //| ParentheticalOpt { $$ = $1; }
1319 ;
1320
1321 ConciseBody
1322 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1323 | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; }
1324 ;
1325 /* }}} */
1326 /* 14 Program {{{ */
1327 Program
1328 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1329 ;
1330
1331 ProgramBody
1332 : StatementList { $$ = $1; }
1333 ;
1334
1335 ProgramBodyOpt
1336 : ProgramBody { $$ = $1; }
1337 | LexSetStatement LexSetRegExp { $$ = NULL; }
1338 ;
1339 /* }}} */
1340
1341 @begin ObjectiveC
1342 /* Cycript (Objective-C): Type Encoding {{{ */
1343 SuffixedType
1344 : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
1345 | "(" PrefixedType ")" { $$ = $2; }
1346 | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
1347 ;
1348
1349 PrefixedType
1350 : SuffixedType { $$ = $1; }
1351 | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; }
1352 | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
1353 ;
1354
1355 ModifiedType
1356 : Variable { $$ = CYNew CYTypeVariable($1); }
1357 | "const" ModifiedType { $$ = CYNew CYTypeConstant($2); }
1358 ;
1359
1360 TypedIdentifier
1361 : ModifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
1362 ;
1363
1364 EncodedType
1365 : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
1366 ;
1367
1368 PrimaryExpression
1369 : AtEncode "(" EncodedType ")" { $$ = $3; }
1370 ;
1371 /* }}} */
1372 /* Cycript (Objective-C): @class Declaration {{{ */
1373 ClassSuperOpt
1374 /* XXX: why the hell did I choose MemberExpression? */
1375 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1376 | { $$ = NULL; }
1377 ;
1378
1379 ClassFieldListOpt
1380 : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
1381 | { $$ = NULL; }
1382 ;
1383
1384 ClassFields
1385 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1386 ;
1387
1388 MessageScope
1389 : "+" { $$ = false; }
1390 | "-" { $$ = true; }
1391 ;
1392
1393 TypeOpt
1394 : "(" EncodedType ")" { $$ = $2; }
1395 | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
1396 | { $$ = NULL; }
1397 ;
1398
1399 MessageParameter
1400 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1401 ;
1402
1403 MessageParameterList
1404 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1405 ;
1406
1407 MessageParameterListOpt
1408 : MessageParameterList { $$ = $1; }
1409 | { $$ = NULL; }
1410 ;
1411
1412 MessageParameters
1413 : MessageParameterList { $$ = $1; }
1414 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1415 ;
1416
1417 ClassMessageDeclaration
1418 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1419 ;
1420
1421 ClassMessageDeclarationListOpt
1422 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1423 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1424 | { $$ = NULL; }
1425 ;
1426
1427 ClassName
1428 : Identifier { $$ = $1; }
1429 | "(" AssignmentExpression ")" { $$ = $2; }
1430 ;
1431
1432 ClassNameOpt
1433 : ClassName { $$ = $1; }
1434 | { $$ = NULL; }
1435 ;
1436
1437 // XXX: this should be AssignmentExpressionNoRight
1438 ClassProtocols
1439 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1440 ;
1441
1442 ClassProtocolsOpt
1443 : "," ClassProtocols { $$ = $2; }
1444 | { $$ = NULL; }
1445 ;
1446
1447 ClassProtocolListOpt
1448 : "<" ClassProtocols ">" { $$ = $2; }
1449 | { $$ = NULL; }
1450 ;
1451
1452 ClassExpression
1453 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1454 ;
1455
1456 ClassStatement
1457 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1458 ;
1459
1460 CategoryName
1461 : "(" WordOpt ")"
1462 ;
1463
1464 CategoryStatement
1465 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1466 ;
1467
1468 PrimaryExpression
1469 : ClassExpression { $$ = $1; }
1470 ;
1471
1472 Statement__
1473 : ClassStatement { $$ = $1; }
1474 | CategoryStatement { $$ = $1; }
1475 ;
1476 /* }}} */
1477 /* Cycript (Objective-C): Send Message {{{ */
1478 VariadicCall
1479 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1480 | { $$ = NULL; }
1481 ;
1482
1483 SelectorWordOpt
1484 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1485 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1486 ;
1487
1488 SelectorCall_
1489 : SelectorCall { $$ = $1; }
1490 | VariadicCall { $$ = $1; }
1491 ;
1492
1493 SelectorCall
1494 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1495 ;
1496
1497 SelectorList
1498 : SelectorCall { $$ = $1; }
1499 | Word { $$ = CYNew CYArgument($1, NULL); }
1500 ;
1501
1502 MessageExpression
1503 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1504 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1505 ;
1506
1507 SelectorExpression_
1508 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1509 ;
1510
1511 SelectorExpression
1512 : SelectorExpression_ { $$ = $1; }
1513 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1514 ;
1515
1516 SelectorExpressionOpt
1517 : SelectorExpression_ { $$ = $1; }
1518 | { $$ = NULL; }
1519 ;
1520
1521 PrimaryExpression
1522 : MessageExpression { $$ = $1; }
1523 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1524 ;
1525 /* }}} */
1526 /* Cycript (Objective-C): @import Directive {{{ */
1527 PathName
1528 : "/" PathName
1529 | "." PathName
1530 | Word PathName
1531 |
1532 ;
1533
1534 ImportPath
1535 : "<" PathName ">"
1536 | StringLiteral
1537 ;
1538
1539 StatementListItem
1540 : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); }
1541 ;
1542 /* }}} */
1543 /* Cycript (Objective-C): Boxed Expressions {{{ */
1544 BoxableExpression
1545 : NullLiteral { $$ = $1; }
1546 | BooleanLiteral { $$ = $1; }
1547 | NumericLiteral { $$ = $1; }
1548 | StringLiteral { $$ = $1; }
1549 | ArrayLiteral { $$ = $1; }
1550 | ObjectLiteral { $$ = $1; }
1551 | Parenthetical { $$ = $1; }
1552 ;
1553
1554 PrimaryExpression
1555 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1556 ;
1557 /* }}} */
1558 @end
1559
1560 @begin C
1561 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1562 LeftHandSideExpression
1563 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1564 ;
1565
1566 UnaryExpression_
1567 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1568 ;
1569
1570 MemberAccess
1571 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1572 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1573 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1574 ;
1575 /* }}} */
1576 /* Cycript (C): auto Compatibility {{{ */
1577 Var_
1578 : "auto"
1579 ;
1580 /* }}} */
1581 @end
1582
1583 /* YUI: Documentation Comments {{{ */
1584 Statement__
1585 : Comment { $$ = $1; }
1586 ;
1587 /* }}} */
1588
1589 @begin E4X
1590 /* Lexer State {{{ */
1591 LexPushRegExp
1592 : { driver.PushCondition(CYDriver::RegExpCondition); }
1593 ;
1594
1595 LexPushXMLContent
1596 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1597 ;
1598
1599 LexPushXMLTag
1600 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1601 ;
1602
1603 LexPop
1604 : { driver.PopCondition(); }
1605 ;
1606
1607 LexSetXMLContent
1608 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1609 ;
1610
1611 LexSetXMLTag
1612 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1613 ;
1614 /* }}} */
1615 /* Virtual Tokens {{{ */
1616 XMLWhitespaceOpt
1617 : XMLWhitespace
1618 |
1619 ;
1620 /* }}} */
1621
1622 /* 8.1 Context Keywords {{{ */
1623 Identifier
1624 : "namespace" { $$ = $1; }
1625 | "xml" { $$ = $1; }
1626 ;
1627 /* }}} */
1628 /* 8.3 XML Initialiser Input Elements {{{ */
1629 XMLMarkup
1630 : XMLComment { $$ = $1; }
1631 | XMLCDATA { $$ = $1; }
1632 | XMLPI { $$ = $1; }
1633 ;
1634 /* }}} */
1635
1636 /* 11.1 Primary Expressions {{{ */
1637 PrimaryExpression
1638 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1639 | XMLInitialiser { $$ = $1; }
1640 | XMLListInitialiser { $$ = $1; }
1641 ;
1642
1643 PropertyIdentifier
1644 : AttributeIdentifier { $$ = $1; }
1645 | QualifiedIdentifier { $$ = $1; }
1646 | WildcardIdentifier { $$ = $1; }
1647 ;
1648 /* }}} */
1649 /* 11.1.1 Attribute Identifiers {{{ */
1650 AttributeIdentifier
1651 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1652 ;
1653
1654 PropertySelector_
1655 : PropertySelector { $$ = $1; }
1656 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1657 ;
1658
1659 PropertySelector
1660 : Identifier { $$ = CYNew CYSelector($1); }
1661 | WildcardIdentifier { $$ = $1; }
1662 ;
1663 /* }}} */
1664 /* 11.1.2 Qualified Identifiers {{{ */
1665 QualifiedIdentifier_
1666 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1667 | QualifiedIdentifier { $$ = $1; }
1668 ;
1669
1670 QualifiedIdentifier
1671 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1672 ;
1673 /* }}} */
1674 /* 11.1.3 Wildcard Identifiers {{{ */
1675 WildcardIdentifier
1676 : "*" { $$ = CYNew CYWildcard(); }
1677 ;
1678 /* }}} */
1679 /* 11.1.4 XML Initialiser {{{ */
1680 XMLInitialiser
1681 : XMLMarkup { $$ = $1; }
1682 | XMLElement { $$ = $1; }
1683 ;
1684
1685 XMLElement
1686 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1687 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1688 ;
1689
1690 XMLTagContent
1691 : LexPushXMLTag XMLTagName XMLAttributes
1692 ;
1693
1694 XMLExpression
1695 : BRACE LexPushRegExp Expression LexPop "}"
1696 ;
1697
1698 XMLTagName
1699 : XMLExpression
1700 | XMLName
1701 ;
1702
1703 XMLAttributes_
1704 : XMLAttributes_ XMLAttribute
1705 |
1706 ;
1707
1708 XMLAttributes
1709 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1710 | XMLAttributes_ XMLWhitespaceOpt
1711 ;
1712
1713 XMLAttributeValue_
1714 : XMLExpression
1715 | XMLAttributeValue
1716 ;
1717
1718 XMLAttribute
1719 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1720 ;
1721
1722 XMLElementContent
1723 : XMLExpression XMLElementContentOpt
1724 | XMLMarkup XMLElementContentOpt
1725 | XMLText XMLElementContentOpt
1726 | XMLElement XMLElementContentOpt
1727 ;
1728
1729 XMLElementContentOpt
1730 : XMLElementContent
1731 |
1732 ;
1733 /* }}} */
1734 /* 11.1.5 XMLList Initialiser {{{ */
1735 XMLListInitialiser
1736 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1737 ;
1738 /* }}} */
1739
1740 /* 11.2 Left-Hand-Side Expressions {{{ */
1741 PropertyIdentifier_
1742 : Identifier { $$ = $1; }
1743 | PropertyIdentifier { $$ = $1; }
1744 ;
1745
1746 MemberAccess
1747 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1748 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1749 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1750 ;
1751 /* }}} */
1752 /* 12.1 The default xml namespace Statement {{{ */
1753 /* XXX: DefaultXMLNamespaceStatement
1754 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1755 ;
1756
1757 Statement__
1758 : DefaultXMLNamespaceStatement { $$ = $1; }
1759 ; */
1760 /* }}} */
1761 @end
1762
1763 /* JavaScript 1.7: Array Comprehensions {{{ */
1764 IfComprehension
1765 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1766 ;
1767
1768 ForComprehension
1769 : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1770 | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1771 ;
1772
1773 ComprehensionList
1774 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1775 ;
1776
1777 ComprehensionListOpt
1778 : ComprehensionList { $$ = $1; }
1779 | IfComprehension { $$ = $1; }
1780 | { $$ = NULL; }
1781 ;
1782
1783 PrimaryExpression
1784 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1785 ;
1786 /* }}} */
1787 /* JavaScript 1.7: for each {{{ */
1788 IterationStatement
1789 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1790 ;
1791 /* }}} */
1792 /* JavaScript 1.7: let Statements {{{ */
1793 LetStatement
1794 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1795 ;
1796
1797 Statement__
1798 : LetStatement
1799 ;
1800 /* }}} */
1801
1802 /* JavaScript FTW: Ruby Blocks {{{ */
1803 RubyProcParameterList_
1804 : "," RubyProcParameterList { $$ = $2; }
1805 | { $$ = NULL; }
1806 ;
1807
1808 RubyProcParameterList
1809 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1810 | { $$ = NULL; }
1811 ;
1812
1813 RubyProcParameters
1814 : "|" RubyProcParameterList "|" { $$ = $2; }
1815 | "||" { $$ = NULL; }
1816 ;
1817
1818 RubyProcParametersOpt
1819 : RubyProcParameters
1820 | { $$ = NULL; }
1821 ;
1822
1823 RubyProcExpression
1824 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1825 ;
1826
1827 PrimaryExpression
1828 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1829 ;
1830
1831 CallExpression
1832 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
1833 ;
1834 /* }}} */
1835
1836 %%