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