]> git.saurik.com Git - cycript.git/blob - Parser.ypp.in
4b7751d6576bf4ac85cc3431b9482dc00ad9a5a6
[cycript.git] / Parser.ypp.in
1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 %code top {
23 #define YYSTACKEXPANDABLE 1
24 }
25
26 %code requires {
27 #include "Driver.hpp"
28 #include "Parser.hpp"
29 #include "Stack.hpp"
30 #include "Syntax.hpp"
31 #define CYNew new(driver.pool_)
32
33 @begin ObjectiveC
34 #include "ObjectiveC/Syntax.hpp"
35 @end
36
37 @begin E4X
38 #include "E4X/Syntax.hpp"
39 @end
40
41 #include "Highlight.hpp"
42 }
43
44 %union { bool bool_; }
45
46 %union { CYMember *access_; }
47 %union { CYArgument *argument_; }
48 %union { CYAssignment *assignment_; }
49 %union { CYBinding *binding_; }
50 %union { CYBindings *bindings_; }
51 %union { CYBoolean *boolean_; }
52 %union { CYBraced *braced_; }
53 %union { CYClause *clause_; }
54 %union { cy::Syntax::Catch *catch_; }
55 %union { CYClassTail *classTail_; }
56 %union { CYComprehension *comprehension_; }
57 %union { CYElement *element_; }
58 %union { CYEnumConstant *constant_; }
59 %union { CYExpression *expression_; }
60 %union { CYFalse *false_; }
61 %union { CYVariable *variable_; }
62 %union { CYFinally *finally_; }
63 %union { CYForInitializer *for_; }
64 %union { CYForInInitializer *forin_; }
65 %union { CYFunctionParameter *functionParameter_; }
66 %union { CYIdentifier *identifier_; }
67 %union { CYImportSpecifier *import_; }
68 %union { CYInfix *infix_; }
69 %union { CYLiteral *literal_; }
70 %union { CYMethod *method_; }
71 %union { CYModule *module_; }
72 %union { CYNull *null_; }
73 %union { CYNumber *number_; }
74 %union { CYParenthetical *parenthetical_; }
75 %union { CYProperty *property_; }
76 %union { CYPropertyName *propertyName_; }
77 %union { CYTypeSigning signing_; }
78 %union { CYSpan *span_; }
79 %union { CYStatement *statement_; }
80 %union { CYString *string_; }
81 %union { CYTarget *target_; }
82 %union { CYThis *this_; }
83 %union { CYTrue *true_; }
84 %union { CYWord *word_; }
85
86 @begin C
87 %union { CYTypeIntegral *integral_; }
88 %union { CYTypeStructField *structField_; }
89 %union { CYTypeModifier *modifier_; }
90 %union { CYTypeSpecifier *specifier_; }
91 %union { CYTypedFormal *typedFormal_; }
92 %union { CYTypedIdentifier *typedIdentifier_; }
93 %union { CYTypedParameter *typedParameter_; }
94 @end
95
96 @begin ObjectiveC
97 %union { CYObjCKeyValue *keyValue_; }
98 %union { CYImplementationField *implementationField_; }
99 %union { CYMessage *message_; }
100 %union { CYMessageParameter *messageParameter_; }
101 %union { CYProtocol *protocol_; }
102 %union { CYSelectorPart *selector_; }
103 @end
104
105 @begin E4X
106 %union { CYAttribute *attribute_; }
107 %union { CYPropertyIdentifier *propertyIdentifier_; }
108 %union { CYSelector *selector_; }
109 @end
110
111 %code provides {
112
113 struct YYSTYPE {
114 cy::parser::semantic_type semantic_;
115 hi::Value highlight_;
116 };
117
118 int cylex(YYSTYPE *, CYLocation *, void *);
119
120 }
121
122 %code {
123
124 #undef yylex
125
126 typedef cy::parser::token tk;
127
128 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
129 driver.newline_ = false;
130 lex:
131 YYSTYPE data;
132 int token(cylex(&data, location, driver.scanner_));
133 *semantic = data.semantic_;
134
135 switch (token) {
136 case tk::OpenBrace:
137 case tk::OpenBracket:
138 case tk::OpenParen:
139 driver.in_.push(false);
140 break;
141
142 case tk::_in_:
143 if (driver.in_.top())
144 token = tk::_in__;
145 break;
146
147 case tk::CloseBrace:
148 case tk::CloseBracket:
149 case tk::CloseParen:
150 driver.in_.pop();
151 break;
152
153
154 case tk::_yield_:
155 if (driver.yield_.top())
156 token = tk::_yield__;
157 break;
158
159 case tk::NewLine:
160 driver.newline_ = true;
161 goto lex;
162 break;
163 }
164
165 return token;
166 }
167
168 #define yylex_(semantic, location, driver) ({ \
169 int type; \
170 if (driver.hold_ == cy::parser::empty_symbol) \
171 type = yytranslate_(cylex_(semantic, location, driver)); \
172 else { \
173 type = driver.hold_; \
174 driver.hold_ = cy::parser::empty_symbol; \
175 } \
176 type; })
177
178 #define CYLEX() do if (yyla.empty()) { \
179 YYCDEBUG << "Mapping a token: "; \
180 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
181 YY_SYMBOL_PRINT("Next token is", yyla); \
182 } while (false)
183
184 #define CYMAP(to, from) do { \
185 CYLEX(); \
186 if (yyla.type == yytranslate_(token::from)) \
187 yyla.type = yytranslate_(token::to); \
188 } while (false)
189
190 #define CYHLD(location, token) do { \
191 if (driver.hold_ != empty_symbol) \
192 CYERR(location, "unexpected hold"); \
193 driver.hold_ = yyla.type; \
194 yyla.type = yytranslate_(token); \
195 } while (false)
196
197 #define CYERR(location, message) do { \
198 error(location, message); \
199 YYABORT; \
200 } while (false)
201
202 #define CYEOK() do { \
203 yyerrok; \
204 driver.errors_.pop_back(); \
205 } while (false)
206
207 #define CYNOT(location) \
208 CYERR(location, "unimplemented feature")
209
210 #define CYMPT(location) do { \
211 if (!yyla.empty() && yyla.type_get() != yyeof_) \
212 CYERR(location, "unexpected lookahead"); \
213 } while (false)
214
215 }
216
217 %name-prefix "cy"
218
219 %language "C++"
220
221 %initial-action {
222 @$.begin.filename = @$.end.filename = &driver.filename_;
223
224 switch (driver.mark_) {
225 case CYMarkScript:
226 driver.hold_ = yytranslate_(token::MarkScript);
227 break;
228 case CYMarkModule:
229 driver.hold_ = yytranslate_(token::MarkModule);
230 break;
231 }
232 };
233
234 %locations
235 %defines
236
237 %define api.location.type { CYLocation }
238
239 //%glr-parser
240 //%expect 1
241
242 %error-verbose
243
244 %param { CYDriver &driver }
245
246 /* Token Declarations {{{ */
247 @begin E4X
248 %token XMLCDATA
249 %token XMLComment
250 %token XMLPI
251
252 %token XMLAttributeValue
253 %token XMLName
254 %token XMLTagCharacters
255 %token XMLText
256 %token XMLWhitespace
257 @end
258
259 @begin E4X
260 %token LeftRight "<>"
261 %token LeftSlashRight "</>"
262
263 %token SlashRight "/>"
264 %token LeftSlash "</"
265
266 %token PeriodPeriod ".."
267 @end
268
269 @begin E4X ObjectiveC
270 %token At "@"
271 @end
272
273 %token Ampersand "&"
274 %token AmpersandAmpersand "&&"
275 %token AmpersandEqual "&="
276 %token Carrot "^"
277 %token CarrotEqual "^="
278 %token Equal "="
279 %token EqualEqual "=="
280 %token EqualEqualEqual "==="
281 %token EqualRight "=>"
282 %token Exclamation "!"
283 %token ExclamationEqual "!="
284 %token ExclamationEqualEqual "!=="
285 %token Hyphen "-"
286 %token HyphenEqual "-="
287 %token HyphenHyphen "--"
288 %token HyphenRight "->"
289 %token Left "<"
290 %token LeftEqual "<="
291 %token LeftLeft "<<"
292 %token LeftLeftEqual "<<="
293 %token Percent "%"
294 %token PercentEqual "%="
295 %token Period "."
296 %token PeriodPeriodPeriod "..."
297 %token Pipe "|"
298 %token PipeEqual "|="
299 %token PipePipe "||"
300 %token Plus "+"
301 %token PlusEqual "+="
302 %token PlusPlus "++"
303 %token Right ">"
304 %token RightEqual ">="
305 %token RightRight ">>"
306 %token RightRightEqual ">>="
307 %token RightRightRight ">>>"
308 %token RightRightRightEqual ">>>="
309 %token Slash "/"
310 %token SlashEqual "/="
311 %token Star "*"
312 %token StarEqual "*="
313 %token Tilde "~"
314
315 %token Colon ":"
316 %token ColonColon "::"
317 %token Comma ","
318 %token Question "?"
319 %token SemiColon ";"
320 %token Pound "#"
321 %token NewLine "\n"
322 %token __ ""
323
324 %token Comment
325
326 %token OpenParen "("
327 %token CloseParen ")"
328
329 %token OpenBrace "{"
330 %token OpenBrace_ ";{"
331 %token OpenBrace_let "let {"
332 %token CloseBrace "}"
333
334 %token OpenBracket "["
335 %token OpenBracket_let "let ["
336 %token CloseBracket "]"
337
338 %token At_error_ "@error"
339
340 @begin Java
341 %token At_class_ "@class"
342 @end
343
344 @begin C
345 %token _typedef_ "typedef"
346 %token _unsigned_ "unsigned"
347 %token _signed_ "signed"
348 %token _struct_ "struct"
349 %token _extern_ "extern"
350 @end
351
352 @begin C
353 %token At_encode_ "@encode"
354 @end
355
356 @begin ObjectiveC
357 %token At_implementation_ "@implementation"
358 %token At_import_ "@import"
359 %token At_end_ "@end"
360 %token At_selector_ "@selector"
361 %token At_null_ "@null"
362 %token At_YES_ "@YES"
363 %token At_NO_ "@NO"
364 %token At_true_ "@true"
365 %token At_false_ "@false"
366 %token _YES_ "YES"
367 %token _NO_ "NO"
368 @end
369
370 %token _false_ "false"
371 %token _null_ "null"
372 %token _true_ "true"
373
374 %token _as_ "as"
375 %token _break_ "break"
376 %token _case_ "case"
377 %token _catch_ "catch"
378 %token _class_ "class"
379 %token _class__ ";class"
380 %token _const_ "const"
381 %token _continue_ "continue"
382 %token _debugger_ "debugger"
383 %token _default_ "default"
384 %token _delete_ "delete"
385 %token _do_ "do"
386 %token _else_ "else"
387 %token _enum_ "enum"
388 %token _export_ "export"
389 %token _extends_ "extends"
390 %token _finally_ "finally"
391 %token _for_ "for"
392 %token _function_ "function"
393 %token _function__ ";function"
394 %token _if_ "if"
395 %token _import_ "import"
396 %token _in_ "in"
397 %token _in__ "!in"
398 %token _Infinity_ "Infinity"
399 %token _instanceof_ "instanceof"
400 %token _new_ "new"
401 %token _return_ "return"
402 %token _super_ "super"
403 %token _switch_ "switch"
404 %token _target_ "target"
405 %token _this_ "this"
406 %token _throw_ "throw"
407 %token _try_ "try"
408 %token _typeof_ "typeof"
409 %token _var_ "var"
410 %token _void_ "void"
411 %token _while_ "while"
412 %token _with_ "with"
413
414 %token _abstract_ "abstract"
415 %token _await_ "await"
416 %token _boolean_ "boolean"
417 %token _byte_ "byte"
418 %token _char_ "char"
419 %token _constructor_ "constructor"
420 %token _double_ "double"
421 %token _eval_ "eval"
422 %token _final_ "final"
423 %token _float_ "float"
424 %token _from_ "from"
425 %token _get_ "get"
426 %token _goto_ "goto"
427 %token _implements_ "implements"
428 %token _int_ "int"
429 %token ___int128_ "__int128"
430 %token _interface_ "interface"
431 %token _let_ "let"
432 %token _let__ "!let"
433 %token _long_ "long"
434 %token _native_ "native"
435 %token _package_ "package"
436 %token _private_ "private"
437 %token _protected_ "protected"
438 %token ___proto___ "__proto__"
439 %token _prototype_ "prototype"
440 %token _public_ "public"
441 %token ___restrict_ "__restrict"
442 %token _restrict_ "restrict"
443 %token _set_ "set"
444 %token _short_ "short"
445 %token _static_ "static"
446 %token _synchronized_ "synchronized"
447 %token _throws_ "throws"
448 %token _transient_ "transient"
449 %token _typeid_ "typeid"
450 %token _volatile_ "volatile"
451 %token _yield_ "yield"
452 %token _yield__ "!yield"
453
454 %token _undefined_ "undefined"
455
456 @begin ObjectiveC
457 %token _bool_ "bool"
458 %token _BOOL_ "BOOL"
459 %token _id_ "id"
460 %token _nil_ "nil"
461 %token _NULL_ "NULL"
462 %token _SEL_ "SEL"
463 @end
464
465 %token _each_ "each"
466 %token _of_ "of"
467 %token _of__ "!of"
468
469 @begin E4X
470 %token _namespace_ "namespace"
471 %token _xml_ "xml"
472 @end
473
474 %token AutoComplete
475 %token YieldStar "yield *"
476
477 %token <identifier_> Identifier_
478 %token <number_> NumericLiteral
479 %token <string_> StringLiteral
480 %token <literal_> RegularExpressionLiteral_
481
482 %token <string_> NoSubstitutionTemplate
483 %token <string_> TemplateHead
484 %token <string_> TemplateMiddle
485 %token <string_> TemplateTail
486
487 %type <target_> AccessExpression
488 %type <expression_> AdditiveExpression
489 %type <argument_> ArgumentList_
490 %type <argument_> ArgumentList
491 %type <argument_> ArgumentListOpt
492 %type <argument_> Arguments
493 %type <target_> ArrayComprehension
494 %type <element_> ArrayElement
495 %type <literal_> ArrayLiteral
496 %type <expression_> ArrowFunction
497 %type <functionParameter_> ArrowParameters
498 %type <expression_> AssignmentExpression
499 %type <identifier_> BindingIdentifier
500 %type <identifier_> BindingIdentifierOpt
501 %type <bindings_> BindingList_
502 %type <bindings_> BindingList
503 %type <expression_> BitwiseANDExpression
504 %type <statement_> Block
505 %type <statement_> BlockStatement
506 %type <boolean_> BooleanLiteral
507 %type <binding_> BindingElement
508 %type <expression_> BitwiseORExpression
509 %type <expression_> BitwiseXORExpression
510 %type <target_> BracedExpression_
511 %type <target_> BracedExpression
512 %type <statement_> BreakStatement
513 %type <statement_> BreakableStatement
514 %type <expression_> CallExpression_
515 %type <target_> CallExpression
516 %type <clause_> CaseBlock
517 %type <clause_> CaseClause
518 %type <clause_> CaseClausesOpt
519 %type <catch_> Catch
520 %type <identifier_> CatchParameter
521 %type <statement_> ClassDeclaration
522 %type <target_> ClassExpression
523 %type <classTail_> ClassHeritage
524 %type <classTail_> ClassHeritageOpt
525 %type <classTail_> ClassTail
526 %type <target_> Comprehension
527 %type <comprehension_> ComprehensionFor
528 %type <comprehension_> ComprehensionIf
529 %type <comprehension_> ComprehensionTail
530 %type <propertyName_> ComputedPropertyName
531 %type <expression_> ConditionalExpression
532 %type <statement_> ContinueStatement
533 %type <statement_> ConciseBody
534 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
535 %type <statement_> DebuggerStatement
536 %type <statement_> Declaration_
537 %type <statement_> Declaration
538 %type <clause_> DefaultClause
539 %type <element_> ElementList_
540 %type <element_> ElementList
541 %type <element_> ElementListOpt
542 %type <statement_> ElseStatementOpt
543 %type <for_> EmptyStatement
544 %type <expression_> EqualityExpression
545 %type <expression_> Expression
546 %type <expression_> ExpressionOpt
547 %type <for_> ExpressionStatement_
548 %type <statement_> ExpressionStatement
549 %type <statement_> ExternC
550 %type <statement_> ExternCStatement
551 %type <statement_> ExternCStatementListOpt
552 %type <finally_> Finally
553 %type <binding_> ForBinding
554 %type <forin_> ForDeclaration
555 %type <forin_> ForInStatementInitializer
556 %type <for_> ForStatementInitializer
557 %type <binding_> FormalParameter
558 %type <functionParameter_> FormalParameterList_
559 %type <functionParameter_> FormalParameterList
560 %type <functionParameter_> FormalParameters
561 %type <string_> FromClause
562 %type <statement_> FunctionBody
563 %type <statement_> FunctionDeclaration
564 %type <target_> FunctionExpression
565 %type <statement_> FunctionStatementList
566 %type <statement_> GeneratorBody
567 %type <statement_> GeneratorDeclaration
568 %type <target_> GeneratorExpression
569 %type <method_> GeneratorMethod
570 %type <statement_> HoistableDeclaration
571 %type <identifier_> Identifier
572 %type <identifier_> IdentifierNoOf
573 %type <identifier_> IdentifierType
574 %type <identifier_> IdentifierTypeNoOf
575 %type <identifier_> IdentifierTypeOpt
576 %type <word_> IdentifierName
577 %type <variable_> IdentifierReference
578 %type <statement_> IfStatement
579 %type <import_> ImportClause
580 %type <statement_> ImportDeclaration
581 %type <import_> ImportSpecifier
582 %type <identifier_> ImportedBinding
583 %type <import_> ImportedDefaultBinding
584 %type <import_> ImportsList_
585 %type <import_> ImportsList
586 %type <import_> ImportsListOpt
587 %type <target_> IndirectExpression
588 %type <expression_> Initializer
589 %type <expression_> InitializerOpt
590 %type <statement_> IterationStatement
591 %type <identifier_> LabelIdentifier
592 %type <statement_> LabelledItem
593 %type <statement_> LabelledStatement
594 %type <assignment_> LeftHandSideAssignment
595 %type <target_> LeftHandSideExpression
596 %type <bool_> LetOrConst
597 %type <binding_> LexicalBinding
598 %type <for_> LexicalDeclaration_
599 %type <statement_> LexicalDeclaration
600 %type <literal_> Literal
601 %type <propertyName_> LiteralPropertyName
602 %type <expression_> LogicalANDExpression
603 %type <expression_> LogicalORExpression
604 %type <access_> MemberAccess
605 %type <target_> MemberExpression
606 %type <method_> MethodDefinition
607 %type <statement_> ModuleBody
608 %type <statement_> ModuleBodyOpt
609 %type <statement_> ModuleItem
610 %type <statement_> ModuleItemList
611 %type <statement_> ModuleItemListOpt
612 %type <module_> ModulePath
613 %type <string_> ModuleSpecifier
614 %type <expression_> MultiplicativeExpression
615 %type <import_> NameSpaceImport
616 %type <import_> NamedImports
617 %type <target_> NewExpression
618 %type <null_> NullLiteral
619 %type <literal_> ObjectLiteral
620 %type <expression_> PostfixExpression
621 %type <target_> PrimaryExpression
622 %type <propertyName_> PropertyName
623 %type <property_> PropertyDefinition
624 %type <property_> PropertyDefinitionList_
625 %type <property_> PropertyDefinitionList
626 %type <property_> PropertyDefinitionListOpt
627 %type <functionParameter_> PropertySetParameterList
628 %type <literal_> RegularExpressionLiteral
629 %type <bool_> RegularExpressionSlash
630 %type <expression_> RelationalExpression
631 %type <statement_> ReturnStatement
632 %type <braced_> BracedParameter
633 %type <functionParameter_> RubyProcParameterList_
634 %type <functionParameter_> RubyProcParameterList
635 %type <functionParameter_> RubyProcParameters
636 %type <functionParameter_> RubyProcParametersOpt
637 %type <statement_> Script
638 %type <statement_> ScriptBody
639 %type <statement_> ScriptBodyOpt
640 %type <expression_> ShiftExpression
641 %type <binding_> SingleNameBinding
642 %type <statement_> Statement__
643 %type <statement_> Statement_
644 %type <statement_> Statement
645 %type <statement_> StatementList
646 %type <statement_> StatementListOpt
647 %type <statement_> StatementListItem
648 %type <functionParameter_> StrictFormalParameters
649 %type <target_> SuperCall
650 %type <target_> SuperProperty
651 %type <statement_> SwitchStatement
652 %type <target_> TemplateLiteral
653 %type <span_> TemplateSpans
654 %type <statement_> ThrowStatement
655 %type <statement_> TryStatement
656 %type <statement_> TypeDefinition
657 %type <expression_> UnaryExpression_
658 %type <expression_> UnaryExpression
659 %type <binding_> VariableDeclaration
660 %type <bindings_> VariableDeclarationList_
661 %type <bindings_> VariableDeclarationList
662 %type <for_> VariableStatement_
663 %type <statement_> VariableStatement
664 %type <statement_> WithStatement
665 %type <word_> Word
666 %type <word_> WordNoUnary
667 @begin ObjectiveC
668 %type <word_> WordOpt
669 @end
670 %type <expression_> YieldExpression
671
672 @begin C
673 %type <constant_> EnumConstantListOpt_
674 %type <constant_> EnumConstantListOpt
675 %type <number_> IntegerNumber
676 %type <integral_> IntegerType
677 %type <integral_> IntegerTypeOpt
678 %type <typedIdentifier_> PrefixedType
679 %type <specifier_> PrimitiveReference
680 %type <specifier_> PrimitiveType
681 %type <structField_> StructFieldListOpt
682 %type <typedIdentifier_> SuffixedType
683 %type <typedIdentifier_> SuffixedTypeOpt
684 %type <typedIdentifier_> TypeSignifier
685 %type <typedIdentifier_> TypeSignifierNone
686 %type <typedIdentifier_> TypeSignifierOpt
687 %type <signing_> TypeSigning
688 %type <modifier_> ParameterTail
689 %type <modifier_> TypeQualifierLeft
690 %type <modifier_> TypeQualifierLeftOpt
691 %type <typedIdentifier_> TypeQualifierRight
692 %type <typedIdentifier_> TypeQualifierRightOpt
693 %type <typedIdentifier_> TypedIdentifierDefinition
694 %type <typedIdentifier_> TypedIdentifierEncoding
695 %type <typedIdentifier_> TypedIdentifierField
696 %type <typedIdentifier_> TypedIdentifierMaybe
697 %type <typedIdentifier_> TypedIdentifierNo
698 %type <typedIdentifier_> TypedIdentifierTagged
699 %type <typedIdentifier_> TypedIdentifierYes
700 %type <typedFormal_> TypedParameterList_
701 %type <typedFormal_> TypedParameterList
702 %type <typedFormal_> TypedParameterListOpt
703 %type <typedParameter_> TypedParameters
704 @end
705
706 @begin ObjectiveC
707 %type <expression_> AssignmentExpressionClassic
708 %type <expression_> BoxableExpression
709 %type <statement_> CategoryStatement
710 %type <expression_> ClassSuperOpt
711 %type <expression_> ConditionalExpressionClassic
712 %type <message_> ClassMessageDeclaration
713 %type <message_> ClassMessageDeclarationListOpt
714 %type <protocol_> ClassProtocolListOpt
715 %type <protocol_> ClassProtocols
716 %type <protocol_> ClassProtocolsOpt
717 %type <implementationField_> ImplementationFieldListOpt
718 %type <statement_> ImplementationStatement
719 %type <keyValue_> KeyValuePairList_
720 %type <keyValue_> KeyValuePairList
721 %type <keyValue_> KeyValuePairListOpt
722 %type <target_> MessageExpression
723 %type <messageParameter_> MessageParameter
724 %type <messageParameter_> MessageParameters
725 %type <messageParameter_> MessageParameterList
726 %type <messageParameter_> MessageParameterListOpt
727 %type <bool_> MessageScope
728 %type <argument_> SelectorCall_
729 %type <argument_> SelectorCall
730 %type <selector_> SelectorExpression_
731 %type <selector_> SelectorExpression
732 %type <selector_> SelectorExpressionOpt
733 %type <argument_> SelectorList
734 %type <word_> SelectorWordOpt
735 %type <typedIdentifier_> TypeOpt
736 %type <argument_> VariadicCall
737 @end
738
739 @begin E4X
740 %type <propertyIdentifier_> PropertyIdentifier_
741 %type <selector_> PropertySelector_
742 %type <selector_> PropertySelector
743 %type <identifier_> QualifiedIdentifier_
744 %type <identifier_> QualifiedIdentifier
745 %type <identifier_> WildcardIdentifier
746 %type <identifier_> XMLComment
747 %type <identifier_> XMLCDATA
748 %type <identifier_> XMLElement
749 %type <identifier_> XMLElementContent
750 %type <identifier_> XMLMarkup
751 %type <identifier_> XMLPI
752
753 %type <attribute_> AttributeIdentifier
754 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
755 %type <expression_> PropertyIdentifier
756 %type <expression_> XMLListInitilizer
757 %type <expression_> XMLInitilizer
758 @end
759 /* }}} */
760 /* Token Priorities {{{ */
761 %nonassoc "if"
762 %nonassoc "else"
763
764 %nonassoc ":"
765 %nonassoc "!yield"
766 /* }}} */
767
768 %start Program
769 %token MarkModule
770 %token MarkScript
771
772 %%
773
774 Program
775 : MarkScript Script
776 | MarkModule Module
777 ;
778
779 /* Lexer State {{{ */
780 LexPushInOn: { driver.in_.push(true); };
781 LexPushInOff: { driver.in_.push(false); };
782 LexPopIn: { driver.in_.pop(); };
783
784 LexPushReturnOn: { driver.return_.push(true); };
785 LexPopReturn: { driver.return_.pop(); };
786 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
787
788 LexPushSuperOn: { driver.super_.push(true); };
789 LexPushSuperOff: { driver.super_.push(false); };
790 LexPopSuper: { driver.super_.pop(); };
791 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
792
793 LexPushYieldOn: { driver.yield_.push(true); };
794 LexPushYieldOff: { driver.yield_.push(false); };
795 LexPopYield: { driver.yield_.pop(); };
796
797 LexNewLineOrOpt
798 : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
799 ;
800
801 LexNewLineOrNot
802 : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
803 ;
804
805 LexNoStar
806 : { CYMAP(YieldStar, Star); }
807 ;
808
809 LexNoBrace
810 : { CYMAP(OpenBrace_, OpenBrace); }
811 ;
812
813 LexNoClass
814 : { CYMAP(_class__, _class_); }
815 ;
816
817 LexNoFunction
818 : { CYMAP(_function__, _function_); }
819 ;
820
821 LexSetStatement
822 : LexNoBrace LexNoClass LexNoFunction
823 ;
824 /* }}} */
825 /* Virtual Tokens {{{ */
826 Var_
827 : "var"
828 ;
829 /* }}} */
830
831 /* 11.6 Names and Keywords {{{ */
832 IdentifierName
833 : Word[pass] { $$ = $pass; }
834 | "for" { $$ = CYNew CYWord("for"); }
835 | "in" { $$ = CYNew CYWord("in"); }
836 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
837 ;
838
839 WordNoUnary
840 : IdentifierNoOf[pass] { $$ = $pass; }
841 | "break" { $$ = CYNew CYWord("break"); }
842 | "case" { $$ = CYNew CYWord("case"); }
843 | "catch" { $$ = CYNew CYWord("catch"); }
844 | "class" LexOf { $$ = CYNew CYWord("class"); }
845 | ";class" { $$ = CYNew CYWord("class"); }
846 | "const" { $$ = CYNew CYWord("const"); }
847 | "continue" { $$ = CYNew CYWord("continue"); }
848 | "debugger" { $$ = CYNew CYWord("debugger"); }
849 | "default" { $$ = CYNew CYWord("default"); }
850 | "do" { $$ = CYNew CYWord("do"); }
851 | "else" { $$ = CYNew CYWord("else"); }
852 | "enum" { $$ = CYNew CYWord("enum"); }
853 | "export" { $$ = CYNew CYWord("export"); }
854 | "extends" { $$ = CYNew CYWord("extends"); }
855 | "false" { $$ = CYNew CYWord("false"); }
856 | "finally" { $$ = CYNew CYWord("finally"); }
857 | "function" LexOf { $$ = CYNew CYWord("function"); }
858 | "if" { $$ = CYNew CYWord("if"); }
859 | "import" { $$ = CYNew CYWord("import"); }
860 | "!in" { $$ = CYNew CYWord("in"); }
861 | "!of" { $$ = CYNew CYWord("of"); }
862 | "null" { $$ = CYNew CYWord("null"); }
863 | "return" { $$ = CYNew CYWord("return"); }
864 | "super" { $$ = CYNew CYWord("super"); }
865 | "switch" { $$ = CYNew CYWord("switch"); }
866 | "this" { $$ = CYNew CYWord("this"); }
867 | "throw" { $$ = CYNew CYWord("throw"); }
868 | "true" { $$ = CYNew CYWord("true"); }
869 | "try" { $$ = CYNew CYWord("try"); }
870 | "var" { $$ = CYNew CYWord("var"); }
871 | "while" { $$ = CYNew CYWord("while"); }
872 | "with" { $$ = CYNew CYWord("with"); }
873 ;
874
875 Word
876 : WordNoUnary[pass] { $$ = $pass; }
877 | "delete" { $$ = CYNew CYWord("delete"); }
878 | "typeof" { $$ = CYNew CYWord("typeof"); }
879 | "void" { $$ = CYNew CYWord("void"); }
880 | "yield" { $$ = CYNew CYIdentifier("yield"); }
881 ;
882
883 @begin ObjectiveC
884 WordOpt
885 : Word[pass] { $$ = $pass; }
886 | { $$ = NULL; }
887 ;
888 @end
889 /* }}} */
890 /* 11.8.1 Null Literals {{{ */
891 NullLiteral
892 : "null" { $$ = CYNew CYNull(); }
893 ;
894 /* }}} */
895 /* 11.8.2 Boolean Literals {{{ */
896 BooleanLiteral
897 : "true" { $$ = CYNew CYTrue(); }
898 | "false" { $$ = CYNew CYFalse(); }
899 ;
900 /* }}} */
901 /* 11.8.5 Regular Expression Literals {{{ */
902 RegularExpressionSlash
903 : "/" { $$ = false; }
904 | "/=" { $$ = true; }
905 ;
906
907 RegularExpressionLiteral
908 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
909 ;
910 /* }}} */
911
912 /* 11.9 Automatic Semicolon Insertion {{{ */
913 StrictSemi
914 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
915 ;
916
917 NewLineNot
918 : LexNewLineOrNot ""
919 ;
920
921 NewLineOpt
922 : LexNewLineOrNot "\n"
923 | NewLineNot
924 ;
925
926 TerminatorSoft
927 : LexNewLineOrNot "\n" StrictSemi
928 | NewLineNot LexOf Terminator
929 ;
930
931 TerminatorHard
932 : ";"
933 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
934 ;
935
936 Terminator
937 : ";"
938 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
939 ;
940
941 TerminatorOpt
942 : ";"
943 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
944 ;
945 /* }}} */
946
947 /* 12.1 Identifiers {{{ */
948 IdentifierReference
949 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
950 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
951 ;
952
953 BindingIdentifier
954 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
955 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
956 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
957 ;
958
959 BindingIdentifierOpt
960 : BindingIdentifier[pass] { $$ = $pass; }
961 | LexOf { $$ = NULL; }
962 ;
963
964 LabelIdentifier
965 : Identifier[pass] { $$ = $pass; }
966 | "yield" { $$ = CYNew CYIdentifier("yield"); }
967 ;
968
969 IdentifierTypeNoOf
970 : Identifier_[pass] { $$ = $pass; }
971 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
972 | "as" { $$ = CYNew CYIdentifier("as"); }
973 | "await" { $$ = CYNew CYIdentifier("await"); }
974 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
975 | "byte" { $$ = CYNew CYIdentifier("byte"); }
976 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
977 | "double" { $$ = CYNew CYIdentifier("double"); }
978 | "each" { $$ = CYNew CYIdentifier("each"); }
979 | "eval" { $$ = CYNew CYIdentifier("eval"); }
980 | "final" { $$ = CYNew CYIdentifier("final"); }
981 | "float" { $$ = CYNew CYIdentifier("float"); }
982 | "from" { $$ = CYNew CYIdentifier("from"); }
983 | "get" { $$ = CYNew CYIdentifier("get"); }
984 | "goto" { $$ = CYNew CYIdentifier("goto"); }
985 | "implements" { $$ = CYNew CYIdentifier("implements"); }
986 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
987 | "interface" { $$ = CYNew CYIdentifier("interface"); }
988 | "let" { $$ = CYNew CYIdentifier("let"); }
989 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
990 | "native" { $$ = CYNew CYIdentifier("native"); }
991 | "package" { $$ = CYNew CYIdentifier("package"); }
992 | "private" { $$ = CYNew CYIdentifier("private"); }
993 | "protected" { $$ = CYNew CYIdentifier("protected"); }
994 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
995 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
996 | "public" { $$ = CYNew CYIdentifier("public"); }
997 | "set" { $$ = CYNew CYIdentifier("set"); }
998 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
999 | "target" { $$ = CYNew CYIdentifier("target"); }
1000 | "throws" { $$ = CYNew CYIdentifier("throws"); }
1001 | "transient" { $$ = CYNew CYIdentifier("transient"); }
1002 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
1003 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
1004 @begin ObjectiveC
1005 | "bool" { $$ = CYNew CYIdentifier("bool"); }
1006 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
1007 | "id" { $$ = CYNew CYIdentifier("id"); }
1008 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
1009 @end
1010 ;
1011
1012 IdentifierType
1013 : IdentifierTypeNoOf[pass] { $$ = $pass; }
1014 | "of" { $$ = CYNew CYIdentifier("of"); }
1015 ;
1016
1017 IdentifierTypeOpt
1018 : IdentifierType[pass] { $$ = $pass; }
1019 | { $$ = NULL; }
1020 ;
1021
1022 IdentifierNoOf
1023 : IdentifierTypeNoOf
1024 | "char" { $$ = CYNew CYIdentifier("char"); }
1025 | "int" { $$ = CYNew CYIdentifier("int"); }
1026 | "__int128" { $$ = CYNew CYIdentifier("__int128"); }
1027 | "long" { $$ = CYNew CYIdentifier("long"); }
1028 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1029 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1030 | "short" { $$ = CYNew CYIdentifier("short"); }
1031 | "static" { $$ = CYNew CYIdentifier("static"); }
1032 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1033 @begin C
1034 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1035 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1036 @end
1037 @begin ObjectiveC
1038 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1039 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1040 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1041 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1042 @end
1043 ;
1044
1045 Identifier
1046 : IdentifierNoOf[pass] { $$ = $pass; }
1047 | "of" { $$ = CYNew CYIdentifier("of"); }
1048 | "!of" { $$ = CYNew CYIdentifier("of"); }
1049 ;
1050 /* }}} */
1051 /* 12.2 Primary Expression {{{ */
1052 PrimaryExpression
1053 : "this" { $$ = CYNew CYThis(); }
1054 | IdentifierReference[pass] { $$ = $pass; }
1055 | Literal[pass] { $$ = $pass; }
1056 | ArrayLiteral[pass] { $$ = $pass; }
1057 | ObjectLiteral[pass] { $$ = $pass; }
1058 | FunctionExpression[pass] { $$ = $pass; }
1059 | ClassExpression[pass] { $$ = $pass; }
1060 | GeneratorExpression[pass] { $$ = $pass; }
1061 | RegularExpressionLiteral[pass] { $$ = $pass; }
1062 | TemplateLiteral[pass] { $$ = $pass; }
1063 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1064 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1065 ;
1066
1067 CoverParenthesizedExpressionAndArrowParameterList
1068 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1069 | "(" LexOf ")" { $$ = NULL; }
1070 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1071 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1072 ;
1073 /* }}} */
1074 /* 12.2.4 Literals {{{ */
1075 Literal
1076 : NullLiteral[pass] { $$ = $pass; }
1077 | BooleanLiteral[pass] { $$ = $pass; }
1078 | NumericLiteral[pass] { $$ = $pass; }
1079 | StringLiteral[pass] { $$ = $pass; }
1080 ;
1081 /* }}} */
1082 /* 12.2.5 Array Initializer {{{ */
1083 ArrayLiteral
1084 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1085 ;
1086
1087 ArrayElement
1088 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1089 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1090 ;
1091
1092 ElementList_
1093 : "," ElementListOpt[elements] { $$ = $elements; }
1094 | { $$ = NULL; }
1095 ;
1096
1097 ElementList
1098 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1099 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1100 ;
1101
1102 ElementListOpt
1103 : ElementList[pass] { $$ = $pass; }
1104 | LexOf { $$ = NULL; }
1105 ;
1106 /* }}} */
1107 /* 12.2.6 Object Initializer {{{ */
1108 ObjectLiteral
1109 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1110 ;
1111
1112 PropertyDefinitionList_
1113 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1114 | { $$ = NULL; }
1115 ;
1116
1117 PropertyDefinitionList
1118 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1119 ;
1120
1121 PropertyDefinitionListOpt
1122 : PropertyDefinitionList[properties] { $$ = $properties; }
1123 | { $$ = NULL; }
1124 ;
1125
1126 PropertyDefinition
1127 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1128 | CoverInitializedName[name] { CYNOT(@$); }
1129 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1130 | MethodDefinition[pass] { $$ = $pass; }
1131 ;
1132
1133 PropertyName
1134 : LiteralPropertyName[pass] { $$ = $pass; }
1135 | ComputedPropertyName[pass] { $$ = $pass; }
1136 ;
1137
1138 LiteralPropertyName
1139 : IdentifierName[pass] { $$ = $pass; }
1140 | StringLiteral[pass] { $$ = $pass; }
1141 | NumericLiteral[pass] { $$ = $pass; }
1142 ;
1143
1144 ComputedPropertyName
1145 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1146 ;
1147
1148 CoverInitializedName
1149 : IdentifierReference Initializer
1150 ;
1151
1152 Initializer
1153 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1154 ;
1155
1156 InitializerOpt
1157 : Initializer[pass] { $$ = $pass; }
1158 | { $$ = NULL; }
1159 ;
1160 /* }}} */
1161 /* 12.2.9 Template Literals {{{ */
1162 TemplateLiteral
1163 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1164 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1165 ;
1166
1167 TemplateSpans
1168 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1169 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1170 ;
1171 /* }}} */
1172
1173 /* 12.3 Left-Hand-Side Expressions {{{ */
1174 MemberAccess
1175 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1176 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1177 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1178 | TemplateLiteral { CYNOT(@$); }
1179 ;
1180
1181 MemberExpression
1182 : PrimaryExpression[pass] { $$ = $pass; }
1183 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1184 | SuperProperty[pass] { $$ = $pass; }
1185 | MetaProperty { CYNOT(@$); }
1186 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1187 ;
1188
1189 SuperProperty
1190 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1191 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1192 ;
1193
1194 MetaProperty
1195 : NewTarget
1196 ;
1197
1198 NewTarget
1199 : "new" "." "target"
1200 ;
1201
1202 NewExpression
1203 : MemberExpression[pass] { $$ = $pass; }
1204 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1205 ;
1206
1207 CallExpression_
1208 : MemberExpression[pass] { $$ = $pass; }
1209 | CallExpression[pass] { $$ = $pass; }
1210 ;
1211
1212 CallExpression
1213 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1214 | SuperCall[pass] { $$ = $pass; }
1215 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1216 ;
1217
1218 SuperCall
1219 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1220 ;
1221
1222 Arguments
1223 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1224 ;
1225
1226 ArgumentList_
1227 : "," ArgumentList[arguments] { $$ = $arguments; }
1228 | { $$ = NULL; }
1229 ;
1230
1231 ArgumentList
1232 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1233 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1234 ;
1235
1236 ArgumentListOpt
1237 : ArgumentList[pass] { $$ = $pass; }
1238 | LexOf { $$ = NULL; }
1239 ;
1240
1241 AccessExpression
1242 : NewExpression[pass] { $$ = $pass; }
1243 | CallExpression[pass] { $$ = $pass; }
1244 ;
1245
1246 LeftHandSideExpression
1247 : BracedExpression[pass] { $$ = $pass; }
1248 | IndirectExpression[pass] { $$ = $pass; }
1249 ;
1250 /* }}} */
1251 /* 12.4 Postfix Expressions {{{ */
1252 PostfixExpression
1253 : BracedExpression[pass] { $$ = $pass; }
1254 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1255 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1256 ;
1257 /* }}} */
1258 /* 12.5 Unary Operators {{{ */
1259 UnaryExpression_
1260 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1261 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1262 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1263 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1264 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1265 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1266 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1267 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1268 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1269 ;
1270
1271 UnaryExpression
1272 : PostfixExpression[expression] { $$ = $expression; }
1273 | UnaryExpression_[pass] { $$ = $pass; }
1274 ;
1275 /* }}} */
1276 /* 12.6 Multiplicative Operators {{{ */
1277 MultiplicativeExpression
1278 : UnaryExpression[pass] { $$ = $pass; }
1279 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1280 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1281 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1282 ;
1283 /* }}} */
1284 /* 12.7 Additive Operators {{{ */
1285 AdditiveExpression
1286 : MultiplicativeExpression[pass] { $$ = $pass; }
1287 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1288 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1289 ;
1290 /* }}} */
1291 /* 12.8 Bitwise Shift Operators {{{ */
1292 ShiftExpression
1293 : AdditiveExpression[pass] { $$ = $pass; }
1294 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1295 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1296 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1297 ;
1298 /* }}} */
1299 /* 12.9 Relational Operators {{{ */
1300 RelationalExpression
1301 : ShiftExpression[pass] { $$ = $pass; }
1302 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1303 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1304 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1305 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1306 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1307 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1308 ;
1309 /* }}} */
1310 /* 12.10 Equality Operators {{{ */
1311 EqualityExpression
1312 : RelationalExpression[pass] { $$ = $pass; }
1313 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1314 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1315 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1316 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1317 ;
1318 /* }}} */
1319 /* 12.11 Binary Bitwise Operators {{{ */
1320 BitwiseANDExpression
1321 : EqualityExpression[pass] { $$ = $pass; }
1322 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1323 ;
1324
1325 BitwiseXORExpression
1326 : BitwiseANDExpression[pass] { $$ = $pass; }
1327 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1328 ;
1329
1330 BitwiseORExpression
1331 : BitwiseXORExpression[pass] { $$ = $pass; }
1332 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1333 ;
1334 /* }}} */
1335 /* 12.12 Binary Logical Operators {{{ */
1336 LogicalANDExpression
1337 : BitwiseORExpression[pass] { $$ = $pass; }
1338 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1339 ;
1340
1341 LogicalORExpression
1342 : LogicalANDExpression[pass] { $$ = $pass; }
1343 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1344 ;
1345 /* }}} */
1346 /* 12.13 Conditional Operator ( ? : ) {{{ */
1347 @begin ObjectiveC
1348 ConditionalExpressionClassic
1349 : LogicalORExpression[pass] { $$ = $pass; }
1350 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1351 ;
1352 @end
1353
1354 ConditionalExpression
1355 : LogicalORExpression[pass] { $$ = $pass; }
1356 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1357 ;
1358 /* }}} */
1359 /* 12.14 Assignment Operators {{{ */
1360 LeftHandSideAssignment
1361 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1362 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1363 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1364 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1365 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1366 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1367 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1368 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1369 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1370 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1371 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1372 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1373 ;
1374
1375 @begin ObjectiveC
1376 AssignmentExpressionClassic
1377 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1378 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1379 ;
1380 @end
1381
1382 AssignmentExpression
1383 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1384 | LexOf YieldExpression[pass] { $$ = $pass; }
1385 | ArrowFunction[pass] { $$ = $pass; }
1386 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1387 ;
1388 /* }}} */
1389 /* 12.15 Comma Operator ( , ) {{{ */
1390 Expression
1391 : AssignmentExpression[pass] { $$ = $pass; }
1392 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1393 ;
1394
1395 ExpressionOpt
1396 : Expression[pass] { $$ = $pass; }
1397 | LexOf { $$ = NULL; }
1398 ;
1399 /* }}} */
1400
1401 /* 13 Statements and Declarations {{{ */
1402 Statement__
1403 : BlockStatement[pass] { $$ = $pass; }
1404 | VariableStatement[pass] { $$ = $pass; }
1405 | EmptyStatement[pass] { $$ = $pass; }
1406 | IfStatement[pass] { $$ = $pass; }
1407 | BreakableStatement[pass] { $$ = $pass; }
1408 | ContinueStatement[pass] { $$ = $pass; }
1409 | BreakStatement[pass] { $$ = $pass; }
1410 | ReturnStatement[pass] { $$ = $pass; }
1411 | WithStatement[pass] { $$ = $pass; }
1412 | LabelledStatement[pass] { $$ = $pass; }
1413 | ThrowStatement[pass] { $$ = $pass; }
1414 | TryStatement[pass] { $$ = $pass; }
1415 | DebuggerStatement[pass] { $$ = $pass; }
1416 ;
1417
1418 Statement_
1419 : LexOf Statement__[pass] { $$ = $pass; }
1420 | ExpressionStatement[pass] { $$ = $pass; }
1421 ;
1422
1423 Statement
1424 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1425 ;
1426
1427 Declaration_
1428 : HoistableDeclaration[pass] { $$ = $pass; }
1429 | ClassDeclaration[pass] { $$ = $pass; }
1430 ;
1431
1432 Declaration
1433 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1434 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1435 ;
1436
1437 HoistableDeclaration
1438 : FunctionDeclaration[pass] { $$ = $pass; }
1439 | GeneratorDeclaration[pass] { $$ = $pass; }
1440 ;
1441
1442 BreakableStatement
1443 : IterationStatement[pass] { $$ = $pass; }
1444 | SwitchStatement[pass] { $$ = $pass; }
1445 ;
1446 /* }}} */
1447 /* 13.2 Block {{{ */
1448 BlockStatement
1449 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1450 ;
1451
1452 Block
1453 : "{" StatementListOpt[code] "}" { $$ = $code; }
1454 ;
1455
1456 StatementList
1457 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1458 ;
1459
1460 StatementListOpt
1461 : StatementList[pass] { $$ = $pass; }
1462 | LexSetStatement LexLet LexOf { $$ = NULL; }
1463 ;
1464
1465 StatementListItem
1466 : Statement[pass] { $$ = $pass; }
1467 | Declaration[pass] { $$ = $pass; }
1468 ;
1469 /* }}} */
1470 /* 13.3 Let and Const Declarations {{{ */
1471 LexicalDeclaration_
1472 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1473 ;
1474
1475 LexicalDeclaration
1476 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1477 ;
1478
1479 LexLet
1480 : { CYMAP(_let__, _let_); }
1481 ;
1482
1483 LexOf
1484 : { CYMAP(_of__, _of_); }
1485 ;
1486
1487 LexBind
1488 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1489 ;
1490
1491 LetOrConst
1492 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1493 | LexLet LexOf "const" { $$ = true; }
1494 ;
1495
1496 BindingList_
1497 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1498 | { $$ = NULL; }
1499 ;
1500
1501 BindingList
1502 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1503 ;
1504
1505 LexicalBinding
1506 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1507 | LexOf BindingPattern Initializer { CYNOT(@$); }
1508 ;
1509 /* }}} */
1510 /* 13.3.2 Variable Statement {{{ */
1511 VariableStatement_
1512 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1513 ;
1514
1515 VariableStatement
1516 : VariableStatement_[statement] Terminator { $$ = $statement; }
1517 ;
1518
1519 VariableDeclarationList_
1520 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1521 | { $$ = NULL; }
1522 ;
1523
1524 VariableDeclarationList
1525 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1526 ;
1527
1528 VariableDeclaration
1529 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1530 | LexOf BindingPattern Initializer { CYNOT(@$); }
1531 ;
1532 /* }}} */
1533 /* 13.3.3 Destructuring Binding Patterns {{{ */
1534 BindingPattern
1535 : ObjectBindingPattern
1536 | ArrayBindingPattern
1537 ;
1538
1539 ObjectBindingPattern
1540 : "let {" BindingPropertyListOpt "}"
1541 ;
1542
1543 ArrayBindingPattern
1544 : "let [" BindingElementListOpt "]"
1545 ;
1546
1547 BindingPropertyList_
1548 : "," BindingPropertyListOpt
1549 |
1550 ;
1551
1552 BindingPropertyList
1553 : BindingProperty BindingPropertyList_
1554 ;
1555
1556 BindingPropertyListOpt
1557 : BindingPropertyList
1558 | LexOf
1559 ;
1560
1561 BindingElementList
1562 : BindingElementOpt[element] "," BindingElementListOpt[next]
1563 | BindingRestElement[element]
1564 | BindingElement[element]
1565 ;
1566
1567 BindingElementListOpt
1568 : BindingElementList[pass]
1569 | LexBind LexOf
1570 ;
1571
1572 BindingProperty
1573 : SingleNameBinding
1574 | LexOf PropertyName ":" BindingElement
1575 ;
1576
1577 BindingElement
1578 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1579 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1580 ;
1581
1582 BindingElementOpt
1583 : BindingElement[pass]
1584 | LexBind LexOf
1585 ;
1586
1587 SingleNameBinding
1588 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1589 ;
1590
1591 BindingRestElement
1592 : LexBind LexOf "..." BindingIdentifier
1593 ;
1594 /* }}} */
1595 /* 13.4 Empty Statement {{{ */
1596 EmptyStatement
1597 : ";" { $$ = CYNew CYEmpty(); }
1598 ;
1599 /* }}} */
1600 /* 13.5 Expression Statement {{{ */
1601 ExpressionStatement_
1602 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1603
1604 ExpressionStatement
1605 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1606 ;
1607 /* }}} */
1608 /* 13.6 The if Statement {{{ */
1609 ElseStatementOpt
1610 : "else" Statement[false] { $$ = $false; }
1611 | %prec "if" { $$ = NULL; }
1612 ;
1613
1614 IfStatement
1615 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1616 ;
1617 /* }}} */
1618 /* 13.7 Iteration Statements {{{ */
1619 IterationStatement
1620 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1621 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1622 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1623 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1624 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1625 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1626 ;
1627
1628 ForStatementInitializer
1629 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1630 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1631 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1632 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1633 ;
1634
1635 ForInStatementInitializer
1636 : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
1637 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1638 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1639 | ForDeclaration[pass] { $$ = $pass; }
1640 ;
1641
1642 ForDeclaration
1643 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1644 ;
1645
1646 ForBinding
1647 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1648 | LexOf BindingPattern { CYNOT(@$); }
1649 ;
1650 /* }}} */
1651 /* 13.8 The continue Statement {{{ */
1652 ContinueStatement
1653 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1654 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1655 ;
1656 /* }}} */
1657 /* 13.9 The break Statement {{{ */
1658 BreakStatement
1659 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1660 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1661 ;
1662 /* }}} */
1663 /* 13.10 The return Statement {{{ */
1664 ReturnStatement
1665 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1666 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1667 ;
1668 /* }}} */
1669 /* 13.11 The with Statement {{{ */
1670 WithStatement
1671 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1672 ;
1673 /* }}} */
1674 /* 13.12 The switch Statement {{{ */
1675 SwitchStatement
1676 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1677 ;
1678
1679 CaseBlock
1680 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1681 ;
1682
1683 CaseClause
1684 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1685 ;
1686
1687 CaseClausesOpt
1688 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1689 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1690 | { $$ = NULL; }
1691 ;
1692
1693 // XXX: the standard makes certain you can only have one of these
1694 DefaultClause
1695 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1696 ;
1697 /* }}} */
1698 /* 13.13 Labelled Statements {{{ */
1699 LabelledStatement
1700 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1701 ;
1702
1703 LabelledItem
1704 : Statement[pass] { $$ = $pass; }
1705 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1706 ;
1707 /* }}} */
1708 /* 13.14 The throw Statement {{{ */
1709 ThrowStatement
1710 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1711 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1712 ;
1713 /* }}} */
1714 /* 13.15 The try Statement {{{ */
1715 TryStatement
1716 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1717 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1718 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1719 ;
1720
1721 Catch
1722 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1723 ;
1724
1725 Finally
1726 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1727 ;
1728
1729 CatchParameter
1730 : BindingIdentifier[pass] { $$ = $pass; }
1731 | LexOf BindingPattern { CYNOT(@$); }
1732 ;
1733 /* }}} */
1734 /* 13.16 The debugger Statement {{{ */
1735 DebuggerStatement
1736 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1737 ;
1738 /* }}} */
1739
1740 /* 14.1 Function Definitions {{{ */
1741 FunctionDeclaration
1742 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1743 ;
1744
1745 FunctionExpression
1746 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1747 ;
1748
1749 StrictFormalParameters
1750 : FormalParameters[pass] { $$ = $pass; }
1751 ;
1752
1753 FormalParameters
1754 : LexBind LexOf { $$ = NULL; }
1755 | FormalParameterList
1756 ;
1757
1758 FormalParameterList_
1759 : "," FormalParameterList[parameters] { $$ = $parameters; }
1760 | { $$ = NULL; }
1761 ;
1762
1763 FormalParameterList
1764 : FunctionRestParameter { CYNOT(@$); }
1765 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1766 ;
1767
1768 FunctionRestParameter
1769 : BindingRestElement
1770 ;
1771
1772 FormalParameter
1773 : BindingElement[pass] { $$ = $pass; }
1774 ;
1775
1776 FunctionBody
1777 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1778 ;
1779
1780 FunctionStatementList
1781 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1782 ;
1783 /* }}} */
1784 /* 14.2 Arrow Function Definitions {{{ */
1785 ArrowFunction
1786 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1787 ;
1788
1789 ArrowParameters
1790 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1791 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1792 ;
1793
1794 ConciseBody
1795 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1796 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1797 ;
1798 /* }}} */
1799 /* 14.3 Method Definitions {{{ */
1800 MethodDefinition
1801 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1802 | GeneratorMethod[pass] { $$ = $pass; }
1803 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1804 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1805 ;
1806
1807 PropertySetParameterList
1808 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1809 ;
1810 /* }}} */
1811 /* 14.4 Generator Function Definitions {{{ */
1812 GeneratorMethod
1813 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1814 ;
1815
1816 GeneratorDeclaration
1817 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1818 ;
1819
1820 GeneratorExpression
1821 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1822 ;
1823
1824 GeneratorBody
1825 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1826 ;
1827
1828 YieldExpression
1829 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1830 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
1831 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1832 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1833 ;
1834 /* }}} */
1835 /* 14.5 Class Definitions {{{ */
1836 ClassDeclaration
1837 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1838 ;
1839
1840 ClassExpression
1841 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1842 ;
1843
1844 ClassTail
1845 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1846 ;
1847
1848 ClassHeritage
1849 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1850 ;
1851
1852 ClassHeritageOpt
1853 : ClassHeritage[pass] { $$ = $pass; }
1854 | { $$ = CYNew CYClassTail(NULL); }
1855 ;
1856
1857 ClassBody
1858 : ClassElementList
1859 ;
1860
1861 ClassBodyOpt
1862 : ClassBody
1863 |
1864 ;
1865
1866 ClassElementList
1867 : ClassElementListOpt ClassElement
1868 ;
1869
1870 ClassElementListOpt
1871 : ClassElementList
1872 |
1873 ;
1874
1875 ClassElement
1876 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1877 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1878 | ";"
1879 ;
1880 /* }}} */
1881
1882 /* 15.1 Scripts {{{ */
1883 Script
1884 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1885 ;
1886
1887 ScriptBody
1888 : StatementList[pass] { $$ = $pass; }
1889 ;
1890
1891 ScriptBodyOpt
1892 : ScriptBody[pass] { $$ = $pass; }
1893 | LexSetStatement LexLet LexOf { $$ = NULL; }
1894 ;
1895 /* }}} */
1896 /* 15.2 Modules {{{ */
1897 Module
1898 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1899 ;
1900
1901 ModuleBody
1902 : ModuleItemList[pass] { $$ = $pass; }
1903 ;
1904
1905 ModuleBodyOpt
1906 : ModuleBody[pass] { $$ = $pass; }
1907 | LexSetStatement LexLet LexOf { $$ = NULL; }
1908 ;
1909
1910 ModuleItemList
1911 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1912 ;
1913
1914 ModuleItemListOpt
1915 : ModuleItemList[pass] { $$ = $pass; }
1916 | LexSetStatement LexLet LexOf { $$ = NULL; }
1917 ;
1918
1919 ModuleItem
1920 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1921 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1922 | StatementListItem[pass] { $$ = $pass; }
1923 ;
1924 /* }}} */
1925 /* 15.2.2 Imports {{{ */
1926 ImportDeclaration
1927 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1928 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1929 ;
1930
1931 ImportClause
1932 : ImportedDefaultBinding[default] { $$ = $default; }
1933 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1934 | LexOf NamedImports[pass] { $$ = $pass; }
1935 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1936 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1937 ;
1938
1939 ImportedDefaultBinding
1940 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1941 ;
1942
1943 NameSpaceImport
1944 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1945 ;
1946
1947 NamedImports
1948 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1949 ;
1950
1951 FromClause
1952 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1953 ;
1954
1955 ImportsList_
1956 : "," ImportsListOpt[pass] { $$ = $pass; }
1957 | { $$ = NULL; }
1958 ;
1959
1960 ImportsList
1961 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1962 ;
1963
1964 ImportsListOpt
1965 : ImportsList[pass] { $$ = $pass; }
1966 | LexOf { $$ = NULL; }
1967 ;
1968
1969 ImportSpecifier
1970 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1971 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1972 ;
1973
1974 ModuleSpecifier
1975 : StringLiteral[pass] { $$ = $pass; }
1976 ;
1977
1978 ImportedBinding
1979 : BindingIdentifier[pass] { $$ = $pass; }
1980 ;
1981 /* }}} */
1982 /* 15.2.3 Exports {{{ */
1983 ExportDeclaration_
1984 : "*" FromClause Terminator
1985 | ExportClause FromClause Terminator
1986 | ExportClause Terminator
1987 | VariableStatement
1988 | "default" LexSetStatement LexOf HoistableDeclaration
1989 | "default" LexSetStatement LexOf ClassDeclaration
1990 | "default" LexSetStatement AssignmentExpression Terminator
1991 ;
1992
1993 ExportDeclaration
1994 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1995 | "export" Declaration
1996 ;
1997
1998 ExportClause
1999 : ";{" ExportsListOpt "}"
2000 ;
2001
2002 ExportsList_
2003 : "," ExportsListOpt
2004 |
2005 ;
2006
2007 ExportsList
2008 : ExportSpecifier ExportsList_
2009 ;
2010
2011 ExportsListOpt
2012 : ExportsList
2013 |
2014 ;
2015
2016 ExportSpecifier
2017 : IdentifierName
2018 | IdentifierName "as" IdentifierName
2019 ;
2020 /* }}} */
2021
2022 @begin C
2023 /* Cycript (C): Type Encoding {{{ */
2024 TypeSignifier
2025 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2026 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2027 ;
2028
2029 TypeSignifierNone
2030 : { $$ = CYNew CYTypedIdentifier(@$); }
2031 ;
2032
2033 TypeSignifierOpt
2034 : TypeSignifier[pass] { $$ = $pass; }
2035 | TypeSignifierNone[pass] { $$ = $pass; }
2036 ;
2037
2038 Restrict
2039 : "__restrict"
2040 | "restrict"
2041 ;
2042
2043 RestrictOpt
2044 : Restrict
2045 |
2046 ;
2047
2048 ParameterModifier
2049 : "throw" "(" ")"
2050 ;
2051
2052 ParameterModifierOpt
2053 : ParameterModifier
2054 |
2055 ;
2056
2057 ParameterTail
2058 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2059 ;
2060
2061 SuffixedType
2062 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2063 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2064 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2065 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2066 ;
2067
2068 SuffixedTypeOpt
2069 : SuffixedType[pass] { $$ = $pass; }
2070 | TypeSignifierOpt[pass] { $$ = $pass; }
2071 ;
2072
2073 PrefixedType
2074 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2075 ;
2076
2077 TypeQualifierLeft
2078 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2079 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2080 ;
2081
2082 TypeQualifierLeftOpt
2083 : TypeQualifierLeft[pass] { $$ = $pass; }
2084 | { $$ = NULL; }
2085 ;
2086
2087 TypeQualifierRight
2088 : SuffixedType[pass] { $$ = $pass; }
2089 | PrefixedType[pass] { $$ = $pass; }
2090 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2091 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2092 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2093 ;
2094
2095 TypeQualifierRightOpt
2096 : TypeQualifierRight[pass] { $$ = $pass; }
2097 | TypeSignifierOpt[pass] { $$ = $pass; }
2098 ;
2099
2100 IntegerType
2101 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2102 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2103 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2104 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2105 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2106 ;
2107
2108 IntegerTypeOpt
2109 : IntegerType[pass] { $$ = $pass; }
2110 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2111 ;
2112
2113 StructFieldListOpt
2114 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2115 | { $$ = NULL; }
2116 ;
2117
2118 IntegerNumber
2119 : NumericLiteral[pass] { $$ = $pass; }
2120 | "-" NumericLiteral[positive] { $$ = $positive; $$->value_ = -$$->value_; }
2121 ;
2122
2123 EnumConstantListOpt_
2124 : "," EnumConstantListOpt[pass] { $$ = $pass; }
2125 | { $$ = NULL; }
2126 ;
2127
2128 EnumConstantListOpt
2129 : IdentifierType[name] "=" IntegerNumber[value] EnumConstantListOpt_[next] { $$ = CYNew CYEnumConstant($name, $value, $next); }
2130 | { $$ = NULL; }
2131 ;
2132
2133 TypeSigning
2134 : { $$ = CYTypeNeutral; }
2135 | "signed" { $$ = CYTypeSigned; }
2136 | "unsigned" { $$ = CYTypeUnsigned; }
2137 ;
2138
2139 PrimitiveType
2140 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2141 | IntegerType[pass] { $$ = $pass; }
2142 | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); }
2143 | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); }
2144 ;
2145
2146 PrimitiveReference
2147 : PrimitiveType[pass] { $$ = $pass; }
2148 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); }
2149 | "enum" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceEnum, $name); }
2150 | "struct" AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
2151 | "enum" AutoComplete { driver.mode_ = CYDriver::AutoEnum; YYACCEPT; }
2152 ;
2153
2154 TypedIdentifierMaybe
2155 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2156 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2157 | TypeQualifierLeftOpt[modifier] PrimitiveReference[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2158 ;
2159
2160 TypedIdentifierYes
2161 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2162 ;
2163
2164 TypedIdentifierNo
2165 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2166 ;
2167
2168 TypedIdentifierTagged
2169 : TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2170 | TypeQualifierLeftOpt[modifier] "enum" ":" PrimitiveType[specifier] "{" EnumConstantListOpt[constants] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeEnum(NULL, $specifier, $constants); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2171 ;
2172
2173 TypedIdentifierField
2174 : TypedIdentifierYes[pass] { $$ = $pass; }
2175 | TypedIdentifierTagged[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2176 ;
2177
2178 TypedIdentifierEncoding
2179 : TypedIdentifierNo[pass] { $$ = $pass; }
2180 | TypedIdentifierTagged[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2181 | "void" TypeSignifierNone[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2182 ;
2183
2184 TypedIdentifierDefinition
2185 : TypedIdentifierYes[pass] { $$ = $pass; }
2186 | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2187 | "void" TypeSignifier[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2188 ;
2189
2190 PrimaryExpression
2191 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2192 ;
2193 /* }}} */
2194 @end
2195
2196 @begin ObjectiveC
2197 /* Cycript (Objective-C): @class Declaration {{{ */
2198 ClassSuperOpt
2199 /* XXX: why the hell did I choose MemberExpression? */
2200 : ":" MemberExpression[extends] { $$ = $extends; }
2201 | { $$ = NULL; }
2202 ;
2203
2204 ImplementationFieldListOpt
2205 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2206 | { $$ = NULL; }
2207 ;
2208
2209 MessageScope
2210 : "+" { $$ = false; }
2211 | "-" { $$ = true; }
2212 ;
2213
2214 TypeOpt
2215 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2216 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2217 ;
2218
2219 MessageParameter
2220 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2221 ;
2222
2223 MessageParameterList
2224 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2225 ;
2226
2227 MessageParameterListOpt
2228 : MessageParameterList[pass] { $$ = $pass; }
2229 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2230 ;
2231
2232 MessageParameters
2233 : MessageParameterList[pass] { $$ = $pass; }
2234 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2235 ;
2236
2237 ClassMessageDeclaration
2238 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2239 ;
2240
2241 ClassMessageDeclarationListOpt
2242 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2243 | { $$ = NULL; }
2244 ;
2245
2246 // XXX: this should be AssignmentExpressionNoRight
2247 ClassProtocols
2248 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2249 ;
2250
2251 ClassProtocolsOpt
2252 : "," ClassProtocols[protocols] { $$ = $protocols; }
2253 | { $$ = NULL; }
2254 ;
2255
2256 ClassProtocolListOpt
2257 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2258 | { $$ = NULL; }
2259 ;
2260
2261 ImplementationStatement
2262 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2263 ;
2264
2265 CategoryName
2266 : "(" WordOpt ")"
2267 ;
2268
2269 CategoryStatement
2270 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2271 ;
2272
2273 Statement__
2274 : ImplementationStatement[pass] { $$ = $pass; }
2275 | CategoryStatement[pass] { $$ = $pass; }
2276 ;
2277 /* }}} */
2278 /* Cycript (Objective-C): Send Message {{{ */
2279 VariadicCall
2280 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2281 | { $$ = NULL; }
2282 ;
2283
2284 SelectorWordOpt
2285 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2286 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2287 ;
2288
2289 SelectorCall_
2290 : SelectorCall[pass] { $$ = $pass; }
2291 | VariadicCall[pass] { $$ = $pass; }
2292 ;
2293
2294 SelectorCall
2295 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2296 ;
2297
2298 SelectorList
2299 : SelectorCall[pass] { $$ = $pass; }
2300 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2301 ;
2302
2303 MessageExpression
2304 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2305 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2306 ;
2307
2308 SelectorExpression_
2309 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2310 ;
2311
2312 SelectorExpression
2313 : SelectorExpression_[pass] { $$ = $pass; }
2314 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2315 ;
2316
2317 SelectorExpressionOpt
2318 : SelectorExpression_[pass] { $$ = $pass; }
2319 | { $$ = NULL; }
2320 ;
2321
2322 PrimaryExpression
2323 : MessageExpression[pass] { $$ = $pass; }
2324 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2325 ;
2326 /* }}} */
2327 @end
2328
2329 /* Cycript: @import Directive {{{ */
2330 ModulePath
2331 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2332 | Word[part] { $$ = CYNew CYModule($part); }
2333 ;
2334
2335 Declaration_
2336 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2337 ;
2338 /* }}} */
2339
2340 @begin ObjectiveC
2341 /* Cycript (Objective-C): Boxed Expressions {{{ */
2342 BoxableExpression
2343 : NullLiteral[pass] { $$ = $pass; }
2344 | BooleanLiteral[pass] { $$ = $pass; }
2345 | NumericLiteral[pass] { $$ = $pass; }
2346 | StringLiteral[pass] { $$ = $pass; }
2347 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2348 | "YES" { $$ = CYNew CYTrue(); }
2349 | "NO" { $$ = CYNew CYFalse(); }
2350 ;
2351
2352 KeyValuePairList_
2353 : "," KeyValuePairListOpt[next] { $$ = $next; }
2354 | { $$ = NULL; }
2355
2356 KeyValuePairList
2357 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2358 ;
2359
2360 KeyValuePairListOpt
2361 : KeyValuePairList[pass] { $$ = $pass; }
2362 | LexOf { $$ = NULL; }
2363 ;
2364
2365 PrimaryExpression
2366 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2367 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2368 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2369
2370 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2371 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2372 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2373 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2374 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2375 ;
2376 /* }}} */
2377 /* Cycript (Objective-C): Block Expressions {{{ */
2378 PrimaryExpression
2379 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2380 ;
2381 /* }}} */
2382 /* Cycript (Objective-C): Instance Literals {{{ */
2383 PrimaryExpression
2384 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2385 ;
2386 /* }}} */
2387 @end
2388
2389 @begin C
2390 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2391 UnaryExpression_
2392 : IndirectExpression[pass] { $$ = $pass; }
2393 ;
2394
2395 IndirectExpression
2396 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2397 ;
2398
2399 UnaryExpression_
2400 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2401 ;
2402
2403 MemberAccess
2404 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2405 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2406 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2407 ;
2408 /* }}} */
2409 /* Cycript (C): Lambda Expressions {{{ */
2410 TypedParameterList_
2411 : "," TypedParameterList[parameters] { $$ = $parameters; }
2412 | { $$ = CYNew CYTypedFormal(false); }
2413 ;
2414
2415 TypedParameterList
2416 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2417 | "..." { $$ = CYNew CYTypedFormal(true); }
2418 ;
2419
2420 TypedParameterListOpt
2421 : TypedParameterList[pass] { $$ = $pass; }
2422 | "void" { $$ = CYNew CYTypedFormal(false); }
2423 | { $$ = CYNew CYTypedFormal(false); }
2424 ;
2425
2426 TypedParameters
2427 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2428 ;
2429
2430 PrimaryExpression
2431 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2432 ;
2433 /* }}} */
2434 /* Cycript (C): Structure Definitions {{{ */
2435 IdentifierNoOf
2436 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2437 ;
2438
2439 Statement__
2440 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2441 ;
2442
2443 PrimaryExpression
2444 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); $$ = CYNew CYTypeExpression($typed); }
2445 | "(" LexOf "struct" NewLineOpt AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
2446 ;
2447 /* }}} */
2448 /* Cycript (C): Type Definitions {{{ */
2449 IdentifierNoOf
2450 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2451 ;
2452
2453 TypeDefinition
2454 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2455 ;
2456
2457 Statement__
2458 : TypeDefinition[pass] { $$ = $pass; }
2459 ;
2460
2461 PrimaryExpression
2462 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2463 ;
2464 /* }}} */
2465 /* Cycript (C): extern "C" {{{ */
2466 IdentifierNoOf
2467 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2468 ;
2469
2470 ExternCStatement
2471 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed); }
2472 | TypeDefinition[pass] { $$ = $pass; }
2473 ;
2474
2475 ExternCStatementListOpt
2476 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2477 | { $$ = NULL; }
2478 ;
2479
2480 ExternC
2481 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2482 | ExternCStatement[pass] { $$ = $pass; }
2483 ;
2484
2485 ABI
2486 : StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); }
2487 ;
2488
2489 Statement__
2490 : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; }
2491 ;
2492
2493 PrimaryExpression
2494 : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed); }
2495 ;
2496 /* }}} */
2497 @end
2498
2499 @begin E4X
2500 /* Lexer State {{{ */
2501 LexPushRegExp
2502 : { driver.PushCondition(CYDriver::RegExpCondition); }
2503 ;
2504
2505 LexPushXMLContent
2506 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2507 ;
2508
2509 LexPushXMLTag
2510 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2511 ;
2512
2513 LexPop
2514 : { driver.PopCondition(); }
2515 ;
2516
2517 LexSetXMLContent
2518 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2519 ;
2520
2521 LexSetXMLTag
2522 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2523 ;
2524 /* }}} */
2525 /* Virtual Tokens {{{ */
2526 XMLWhitespaceOpt
2527 : XMLWhitespace
2528 |
2529 ;
2530 /* }}} */
2531
2532 /* 8.1 Context Keywords {{{ */
2533 Identifier
2534 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2535 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2536 ;
2537 /* }}} */
2538 /* 8.3 XML Initializer Input Elements {{{ */
2539 XMLMarkup
2540 : XMLComment { $$ = $1; }
2541 | XMLCDATA { $$ = $1; }
2542 | XMLPI { $$ = $1; }
2543 ;
2544 /* }}} */
2545
2546 /* 11.1 Primary Expressions {{{ */
2547 PrimaryExpression
2548 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2549 | XMLInitilizer { $$ = $1; }
2550 | XMLListInitilizer { $$ = $1; }
2551 ;
2552
2553 PropertyIdentifier
2554 : AttributeIdentifier { $$ = $1; }
2555 | QualifiedIdentifier { $$ = $1; }
2556 | WildcardIdentifier { $$ = $1; }
2557 ;
2558 /* }}} */
2559 /* 11.1.1 Attribute Identifiers {{{ */
2560 AttributeIdentifier
2561 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2562 ;
2563
2564 PropertySelector_
2565 : PropertySelector { $$ = $1; }
2566 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2567 ;
2568
2569 PropertySelector
2570 : Identifier { $$ = CYNew CYSelector($1); }
2571 | WildcardIdentifier { $$ = $1; }
2572 ;
2573 /* }}} */
2574 /* 11.1.2 Qualified Identifiers {{{ */
2575 QualifiedIdentifier_
2576 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2577 | QualifiedIdentifier { $$ = $1; }
2578 ;
2579
2580 QualifiedIdentifier
2581 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2582 ;
2583 /* }}} */
2584 /* 11.1.3 Wildcard Identifiers {{{ */
2585 WildcardIdentifier
2586 : "*" { $$ = CYNew CYWildcard(); }
2587 ;
2588 /* }}} */
2589 /* 11.1.4 XML Initializer {{{ */
2590 XMLInitilizer
2591 : XMLMarkup { $$ = $1; }
2592 | XMLElement { $$ = $1; }
2593 ;
2594
2595 XMLElement
2596 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2597 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2598 ;
2599
2600 XMLTagContent
2601 : LexPushXMLTag XMLTagName XMLAttributes
2602 ;
2603
2604 XMLExpression
2605 : "{" LexPushRegExp Expression LexPop "}"
2606 ;
2607
2608 XMLTagName
2609 : XMLExpression
2610 | XMLName
2611 ;
2612
2613 XMLAttributes_
2614 : XMLAttributes_ XMLAttribute
2615 |
2616 ;
2617
2618 XMLAttributes
2619 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2620 | XMLAttributes_ XMLWhitespaceOpt
2621 ;
2622
2623 XMLAttributeValue_
2624 : XMLExpression
2625 | XMLAttributeValue
2626 ;
2627
2628 XMLAttribute
2629 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2630 ;
2631
2632 XMLElementContent
2633 : XMLExpression XMLElementContentOpt
2634 | XMLMarkup XMLElementContentOpt
2635 | XMLText XMLElementContentOpt
2636 | XMLElement XMLElementContentOpt
2637 ;
2638
2639 XMLElementContentOpt
2640 : XMLElementContent
2641 |
2642 ;
2643 /* }}} */
2644 /* 11.1.5 XMLList Initializer {{{ */
2645 XMLListInitilizer
2646 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2647 ;
2648 /* }}} */
2649
2650 /* 11.2 Left-Hand-Side Expressions {{{ */
2651 PropertyIdentifier_
2652 : Identifier { $$ = $1; }
2653 | PropertyIdentifier { $$ = $1; }
2654 ;
2655
2656 MemberAccess
2657 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2658 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2659 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2660 ;
2661 /* }}} */
2662 /* 12.1 The default xml namespace Statement {{{ */
2663 /* XXX: DefaultXMLNamespaceStatement
2664 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2665 ;
2666
2667 Statement__
2668 : DefaultXMLNamespaceStatement { $$ = $1; }
2669 ; */
2670 /* }}} */
2671 @end
2672
2673 /* JavaScript FTL: Array Comprehensions {{{ */
2674 Comprehension
2675 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2676 ;
2677
2678 ComprehensionFor
2679 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2680 ;
2681 /* }}} */
2682 /* JavaScript FTL: for each {{{ */
2683 IterationStatement
2684 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2685 ;
2686 /* }}} */
2687
2688 /* JavaScript FTW: Array Comprehensions {{{ */
2689 PrimaryExpression
2690 : ArrayComprehension
2691 ;
2692
2693 ArrayComprehension
2694 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2695 ;
2696
2697 Comprehension
2698 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2699 ;
2700
2701 ComprehensionTail
2702 : { $$ = NULL; }
2703 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2704 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2705 ;
2706
2707 ComprehensionFor
2708 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2709 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2710 ;
2711
2712 ComprehensionIf
2713 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2714 ;
2715 /* }}} */
2716 /* JavaScript FTW: Named Arguments {{{ */
2717 ArgumentList
2718 : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2719 ;
2720 /* }}} */
2721 /* JavaScript FTW: Subscript Access {{{ */
2722 MemberAccess
2723 : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); }
2724 ;
2725 /* }}} */
2726
2727 /* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */
2728 BracedParameter
2729 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
2730 ;
2731 /* }}} */
2732
2733 /* JavaScript FTW: Ruby Blocks {{{ */
2734 RubyProcParameterList_
2735 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2736 | { $$ = NULL; }
2737 ;
2738
2739 RubyProcParameterList
2740 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2741 | LexOf { $$ = NULL; }
2742 ;
2743
2744 RubyProcParameters
2745 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2746 | "||" { $$ = NULL; }
2747 ;
2748
2749 RubyProcParametersOpt
2750 : RubyProcParameters[pass] { $$ = $pass; }
2751 | { $$ = NULL; }
2752 ;
2753
2754 BracedParameter
2755 : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
2756 ;
2757
2758 PrimaryExpression
2759 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2760 ;
2761
2762 BracedExpression_
2763 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2764 | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
2765 ;
2766
2767 BracedExpression
2768 : BracedExpression_[pass] "\n" { $$ = $pass; }
2769 | BracedExpression_[pass] { $$ = $pass; }
2770 ;
2771 /* }}} */
2772 /* JavaScript FTW: Ruby Scopes {{{ */
2773 MemberAccess
2774 : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
2775 | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
2776 | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
2777 ;
2778 /* }}} */
2779 /* JavaScript FTW: Ruby Symbols {{{ */
2780 PrimaryExpression
2781 : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
2782 ;
2783 /* }}} */
2784
2785 %%
2786
2787 bool CYDriver::Parse(CYMark mark) {
2788 mark_ = mark;
2789 CYLocal<CYPool> local(&pool_);
2790 cy::parser parser(*this);
2791 #ifdef YYDEBUG
2792 parser.set_debug_level(debug_);
2793 #endif
2794 return parser.parse() != 0;
2795 }
2796
2797 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2798 if (!strict_)
2799 return;
2800
2801 CYDriver::Error error;
2802 error.warning_ = true;
2803 error.location_ = location;
2804 error.message_ = message;
2805 errors_.push_back(error);
2806 }
2807
2808 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2809 CYDriver::Error error;
2810 error.warning_ = false;
2811 error.location_ = location;
2812 error.message_ = message;
2813 driver.errors_.push_back(error);
2814 }