1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
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.
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.
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/>.
23 #define cyscanner driver.scanner_
24 #define YYSTACKEXPANDABLE 1
31 #define CYNew new(driver.pool_)
34 #include "ObjectiveC/Syntax.hpp"
38 #include "E4X/Syntax.hpp"
41 #include "Highlight.hpp"
44 %union { bool bool_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBoolean *boolean_; }
49 %union { CYClause *clause_; }
50 %union { cy::Syntax::Catch *catch_; }
51 %union { CYComprehension *comprehension_; }
52 %union { CYDeclaration *declaration_; }
53 %union { CYDeclarations *declarations_; }
54 %union { CYElement *element_; }
55 %union { CYExpression *expression_; }
56 %union { CYFalse *false_; }
57 %union { CYFinally *finally_; }
58 %union { CYForInitializer *for_; }
59 %union { CYForInInitializer *forin_; }
60 %union { CYFunctionParameter *functionParameter_; }
61 %union { CYIdentifier *identifier_; }
62 %union { CYInfix *infix_; }
63 %union { CYLiteral *literal_; }
64 %union { CYMember *member_; }
65 %union { CYModule *module_; }
66 %union { CYNull *null_; }
67 %union { CYNumber *number_; }
68 %union { CYParenthetical *parenthetical_; }
69 %union { CYProperty *property_; }
70 %union { CYPropertyName *propertyName_; }
71 %union { CYRubyProc *rubyProc_; }
72 %union { CYSpan *span_; }
73 %union { CYStatement *statement_; }
74 %union { CYString *string_; }
75 %union { CYThis *this_; }
76 %union { CYTrue *true_; }
77 %union { CYWord *word_; }
80 %union { CYTypeModifier *modifier_; }
81 %union { CYTypeSpecifier *specifier_; }
82 %union { CYTypedIdentifier *typedIdentifier_; }
83 %union { CYTypedParameter *typedParameter_; }
87 %union { CYClassName *className_; }
88 %union { CYClassField *classField_; }
89 %union { CYMessage *message_; }
90 %union { CYMessageParameter *messageParameter_; }
91 %union { CYProtocol *protocol_; }
92 %union { CYSelectorPart *selector_; }
96 %union { CYAttribute *attribute_; }
97 %union { CYPropertyIdentifier *propertyIdentifier_; }
98 %union { CYSelector *selector_; }
104 cy::parser::semantic_type semantic_;
105 hi::Value highlight_;
108 int cylex(YYSTYPE *, CYLocation *, void *);
115 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, void *scanner) {
117 int token(cylex(&data, location, scanner));
118 *semantic = data.semantic_;
129 @$.begin.filename = @$.end.filename = &driver.filename_;
135 %define api.location.type { CYLocation }
142 %parse-param { CYDriver &driver }
143 %lex-param { void *cyscanner }
145 /* Token Declarations {{{ */
151 %token XMLAttributeValue
153 %token XMLTagCharacters
159 %token LeftRight "<>"
160 %token LeftSlashRight "</>"
162 %token SlashRight "/>"
163 %token LeftSlash "</"
165 %token ColonColon "::"
166 %token PeriodPeriod ".."
169 @begin E4X ObjectiveC
175 %token AmpersandAmpersand "&&"
176 %token AmpersandEqual "&="
178 %token CarrotEqual "^="
180 %token EqualEqual "=="
181 %token EqualEqualEqual "==="
182 %token EqualRight "=>"
183 %token EqualRight_ "\n=>"
184 %token Exclamation "!"
185 %token ExclamationEqual "!="
186 %token ExclamationEqualEqual "!=="
188 %token HyphenEqual "-="
189 %token HyphenHyphen "--"
190 %token HyphenHyphen_ "\n--"
191 %token HyphenRight "->"
193 %token LeftEqual "<="
195 %token LeftLeftEqual "<<="
197 %token PercentEqual "%="
199 %token PeriodPeriodPeriod "..."
201 %token PipeEqual "|="
204 %token PlusEqual "+="
206 %token PlusPlus_ "\n++"
208 %token RightEqual ">="
209 %token RightRight ">>"
210 %token RightRightEqual ">>="
211 %token RightRightRight ">>>"
212 %token RightRightRightEqual ">>>="
214 %token SlashEqual "/="
216 %token StarEqual "*="
228 %token CloseParen ")"
231 %token OpenBrace_ "\n{"
232 %token OpenBrace__ ";{"
233 %token CloseBrace "}"
235 %token OpenBracket "["
236 %token CloseBracket "]"
238 %token At_error_ "@error"
241 %token At_class_ "@class"
245 %token _typedef_ "typedef"
246 %token _unsigned_ "unsigned"
247 %token _signed_ "signed"
248 %token _extern_ "extern"
252 %token At_encode_ "@encode"
256 %token At_implementation_ "@implementation"
257 %token At_implementation__ ";@implementation"
258 %token At_import_ "@import"
259 %token At_end_ "@end"
260 %token At_selector_ "@selector"
261 %token At_null_ "@null"
262 %token At_YES_ "@YES"
264 %token At_true_ "@true"
265 %token At_false_ "@false"
270 %token _false_ "false"
274 %token _break_ "break"
276 %token _catch_ "catch"
277 %token _class_ "class"
278 %token _class__ "!class"
279 %token _const_ "const"
280 %token _continue_ "continue"
281 %token _debugger_ "debugger"
282 %token _default_ "default"
283 %token _delete_ "delete"
287 %token _export_ "export"
288 %token _extends_ "extends"
289 %token _finally_ "finally"
291 %token _function_ "function"
292 %token _function__ ";function"
294 %token _import_ "import"
297 %token _instanceof_ "instanceof"
299 %token _return_ "return"
300 %token _super_ "super"
301 %token _switch_ "switch"
303 %token _throw_ "throw"
305 %token _typeof_ "typeof"
308 %token _while_ "while"
311 %token _abstract_ "abstract"
312 %token _await_ "await"
313 %token _boolean_ "boolean"
316 %token _double_ "double"
317 %token _final_ "final"
318 %token _float_ "float"
320 %token _implements_ "implements"
322 %token _interface_ "interface"
325 %token _native_ "native"
326 %token _package_ "package"
327 %token _private_ "private"
328 %token _protected_ "protected"
329 %token _public_ "public"
330 %token _short_ "short"
331 %token _static_ "static"
332 %token _synchronized_ "synchronized"
333 %token _throws_ "throws"
334 %token _transient_ "transient"
335 %token _volatile_ "volatile"
336 %token _yield_ "yield"
338 %token _undefined_ "undefined"
354 %token _namespace_ "namespace"
360 %token <identifier_> Identifier_
361 %token <number_> NumericLiteral
362 %token <string_> StringLiteral
363 %token <literal_> RegularExpressionLiteral
365 %token <string_> NoSubstitutionTemplate
366 %token <string_> TemplateHead
367 %token <string_> TemplateMiddle
368 %token <string_> TemplateTail
370 %type <expression_> AdditiveExpression
371 %type <argument_> ArgumentList_
372 %type <argument_> ArgumentList
373 %type <argument_> ArgumentListOpt
374 %type <argument_> Arguments
375 %type <expression_> ArrayComprehension
376 %type <literal_> ArrayLiteral
377 %type <expression_> ArrowFunction
378 %type <functionParameter_> ArrowParameters
379 %type <expression_> AssignmentExpression
380 %type <identifier_> Binding
381 %type <identifier_> BindingIdentifier
382 %type <expression_> BitwiseANDExpression
383 %type <statement_> Block
384 %type <statement_> BlockStatement
385 %type <boolean_> BooleanLiteral
386 %type <declaration_> BindingElement
387 %type <expression_> BitwiseORExpression
388 %type <expression_> BitwiseXORExpression
389 %type <statement_> BreakStatement
390 %type <statement_> BreakableStatement
391 %type <expression_> CallExpression_
392 %type <expression_> CallExpression
393 %type <clause_> CaseBlock
394 %type <clause_> CaseClause
395 %type <clause_> CaseClausesOpt
397 %type <identifier_> CatchParameter
398 %type <expression_> Comprehension
399 %type <comprehension_> ComprehensionFor
400 %type <comprehension_> ComprehensionIf
401 %type <comprehension_> ComprehensionTail
402 %type <expression_> ConditionalExpression
403 %type <statement_> ContinueStatement
404 %type <statement_> ConciseBody
405 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
406 %type <statement_> DebuggerStatement
407 %type <statement_> Declaration__
408 %type <statement_> Declaration_
409 %type <statement_> Declaration
410 %type <clause_> DefaultClause
411 %type <expression_> Element
412 %type <expression_> ElementOpt
413 %type <element_> ElementList
414 %type <element_> ElementListOpt
415 %type <statement_> ElseStatementOpt
416 %type <statement_> EmptyStatement
417 %type <expression_> EqualityExpression
418 %type <expression_> Expression
419 %type <expression_> ExpressionOpt
420 %type <statement_> ExpressionStatement
421 %type <finally_> Finally
422 %type <for_> ForStatementInitializer
423 %type <forin_> ForInStatementInitializer
424 %type <declaration_> FormalParameter
425 %type <functionParameter_> FormalParameterList_
426 %type <functionParameter_> FormalParameterList
427 %type <functionParameter_> FormalParameterListOpt
428 %type <statement_> FunctionBody
429 %type <statement_> FunctionDeclaration
430 %type <expression_> FunctionExpression
431 %type <statement_> HoistableDeclaration
432 %type <identifier_> Identifier
433 %type <identifier_> IdentifierOpt
434 %type <identifier_> IdentifierType
435 %type <word_> IdentifierName
436 %type <expression_> IdentifierReference
437 %type <statement_> IfStatement
438 %type <expression_> Initializer
439 %type <expression_> InitializerOpt
440 %type <statement_> IterationStatement
441 %type <identifier_> LabelIdentifier
442 %type <statement_> LabelledItem
443 %type <statement_> LabelledStatement
444 %type <expression_> LeftHandSideExpression
445 %type <statement_> LetStatement
446 %type <statement_> LexicalDeclaration
447 %type <literal_> Literal
448 %type <expression_> LogicalANDExpression
449 %type <expression_> LogicalORExpression
450 %type <member_> MemberAccess
451 %type <expression_> MemberExpression_
452 %type <expression_> MemberExpression
453 %type <module_> Module
454 %type <expression_> MultiplicativeExpression
455 %type <expression_> NewExpression
456 %type <null_> NullLiteral
457 %type <literal_> ObjectLiteral
458 %type <expression_> PostfixExpression
459 %type <expression_> PrimaryExpression
460 %type <propertyName_> PropertyName_
461 %type <propertyName_> PropertyName
462 %type <property_> PropertyDefinition
463 %type <property_> PropertyDefinitionList_
464 %type <property_> PropertyDefinitionList
465 %type <property_> PropertyDefinitionListOpt
466 %type <expression_> RelationalExpression
467 %type <statement_> ReturnStatement
468 %type <rubyProc_> RubyProcExpression
469 %type <functionParameter_> RubyProcParameterList_
470 %type <functionParameter_> RubyProcParameterList
471 %type <functionParameter_> RubyProcParameters
472 %type <functionParameter_> RubyProcParametersOpt
473 %type <statement_> Script
474 %type <statement_> ScriptBody
475 %type <statement_> ScriptBodyOpt
476 %type <expression_> ShiftExpression
477 %type <declaration_> SingleNameBinding
478 %type <statement_> Statement__
479 %type <statement_> Statement_
480 %type <statement_> Statement
481 %type <statement_> StatementList
482 %type <statement_> StatementListOpt
483 %type <statement_> StatementListItem
484 %type <statement_> SwitchStatement
485 %type <expression_> TemplateLiteral
486 %type <span_> TemplateSpans
487 %type <statement_> ThrowStatement
488 %type <statement_> TryStatement
489 %type <expression_> UnaryExpression_
490 %type <expression_> UnaryExpression
491 %type <declaration_> VariableDeclaration
492 %type <declarations_> VariableDeclarationList_
493 %type <declarations_> VariableDeclarationList
494 %type <statement_> VariableStatement
495 %type <statement_> WithStatement
498 %type <word_> WordOpt
502 %type <specifier_> IntegerType
503 %type <specifier_> IntegerTypeOpt
504 %type <typedIdentifier_> PrefixedType
505 %type <specifier_> PrimitiveType
506 %type <typedIdentifier_> SuffixedType
507 %type <typedIdentifier_> TypeSignifier
508 %type <modifier_> TypeQualifierLeft
509 %type <typedIdentifier_> TypeQualifierRight
510 %type <typedIdentifier_> TypedIdentifier
511 %type <typedParameter_> TypedParameterList_
512 %type <typedParameter_> TypedParameterList
513 %type <typedParameter_> TypedParameterListOpt
517 %type <expression_> BoxableExpression
518 %type <statement_> CategoryStatement
519 %type <expression_> ClassExpression
520 %type <classField_> ClassFieldListOpt
521 %type <classField_> ClassFields
522 %type <statement_> ClassStatement
523 %type <expression_> ClassSuperOpt
524 %type <message_> ClassMessageDeclaration
525 %type <message_> ClassMessageDeclarationListOpt
526 %type <className_> ClassName
527 %type <className_> ClassNameOpt
528 %type <protocol_> ClassProtocolListOpt
529 %type <protocol_> ClassProtocols
530 %type <protocol_> ClassProtocolsOpt
531 %type <expression_> MessageExpression
532 %type <messageParameter_> MessageParameter
533 %type <messageParameter_> MessageParameters
534 %type <messageParameter_> MessageParameterList
535 %type <messageParameter_> MessageParameterListOpt
536 %type <bool_> MessageScope
537 %type <argument_> SelectorCall_
538 %type <argument_> SelectorCall
539 %type <selector_> SelectorExpression_
540 %type <selector_> SelectorExpression
541 %type <selector_> SelectorExpressionOpt
542 %type <argument_> SelectorList
543 %type <word_> SelectorWordOpt
544 %type <typedIdentifier_> TypeOpt
545 %type <argument_> VariadicCall
549 %type <propertyIdentifier_> PropertyIdentifier_
550 %type <selector_> PropertySelector_
551 %type <selector_> PropertySelector
552 %type <identifier_> QualifiedIdentifier_
553 %type <identifier_> QualifiedIdentifier
554 %type <identifier_> WildcardIdentifier
555 %type <identifier_> XMLComment
556 %type <identifier_> XMLCDATA
557 %type <identifier_> XMLElement
558 %type <identifier_> XMLElementContent
559 %type <identifier_> XMLMarkup
560 %type <identifier_> XMLPI
562 %type <attribute_> AttributeIdentifier
563 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
564 %type <expression_> PropertyIdentifier
565 %type <expression_> XMLListInitialiser
566 %type <expression_> XMLInitialiser
569 /* Token Priorities {{{ */
581 /* Lexer State {{{ */
583 : { driver.in_.push(true); }
587 : { driver.in_.push(false); }
591 : { driver.in_.pop(); }
595 : { driver.SetCondition(CYDriver::RegExpCondition); }
599 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.no_.NewLine = true; }
603 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
607 : { if (yyla.empty()) driver.no_.Class = true; else if (yyla.type == yytranslate_(token::_class_)) yyla.type = yytranslate_(token::_class__); }
611 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); }
614 LexNoAtImplementation :
616 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); }
621 : LexNoBrace LexNoClass LexNoFunction LexNoAtImplementation
624 /* Virtual Tokens {{{ */
635 /* 11.6 Names and Keywords {{{ */
638 | "for" { $$ = CYNew CYWord("for"); }
639 | "in" { $$ = CYNew CYWord("in"); }
640 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
644 : Identifier { $$ = $1; }
645 | "auto" { $$ = CYNew CYWord("auto"); }
646 | "break" { $$ = CYNew CYWord("break"); }
647 | "case" { $$ = CYNew CYWord("case"); }
648 | "catch" { $$ = CYNew CYWord("catch"); }
649 | "class" { $$ = CYNew CYWord("class"); }
650 | "!class" { $$ = CYNew CYWord("class"); }
651 | "const" { $$ = CYNew CYWord("const"); }
652 | "continue" { $$ = CYNew CYWord("continue"); }
653 | "debugger" { $$ = CYNew CYWord("debugger"); }
654 | "default" { $$ = CYNew CYWord("default"); }
655 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
656 | "do" { $$ = CYNew CYWord("do"); }
657 | "else" { $$ = CYNew CYWord("else"); }
658 | "enum" { $$ = CYNew CYWord("enum"); }
659 | "export" { $$ = CYNew CYWord("export"); }
660 | "extends" { $$ = CYNew CYWord("extends"); }
661 | "false" { $$ = CYNew CYWord("false"); }
662 | "finally" { $$ = CYNew CYWord("finally"); }
663 | "function" { $$ = CYNew CYWord("function"); }
664 | "if" { $$ = CYNew CYWord("if"); }
665 | "import" { $$ = CYNew CYWord("import"); }
666 | "!in" { $$ = CYNew CYWord("in"); }
667 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
668 | "null" { $$ = CYNew CYWord("null"); }
669 | "return" { $$ = CYNew CYWord("return"); }
670 | "super" { $$ = CYNew CYWord("super"); }
671 | "switch" { $$ = CYNew CYWord("switch"); }
672 | "this" { $$ = CYNew CYWord("this"); }
673 | "throw" { $$ = CYNew CYWord("throw"); }
674 | "true" { $$ = CYNew CYWord("true"); }
675 | "try" { $$ = CYNew CYWord("try"); }
676 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
677 | "var" { $$ = CYNew CYWord("var"); }
678 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
679 | "while" { $$ = CYNew CYWord("while"); }
680 | "with" { $$ = CYNew CYWord("with"); }
682 // XXX: should be Identifier
683 | "let" { $$ = CYNew CYIdentifier("let"); }
693 /* 11.8.1 Null Literals {{{ */
695 : "null" { $$ = CYNew CYNull(); }
698 /* 11.8.2 Boolean Literals {{{ */
700 : "true" { $$ = CYNew CYTrue(); }
701 | "false" { $$ = CYNew CYFalse(); }
705 /* 11.9 Automatic Semicolon Insertion {{{ */
707 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
717 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
722 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
726 /* 12.1 Identifiers {{{ */
728 : Identifier { $$ = CYNew CYVariable($1); }
733 : Identifier { $$ = $1; }
738 : Identifier { $$ = $1; }
743 : Identifier_ { $$ = $1; }
744 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
745 | "await" { $$ = CYNew CYIdentifier("await"); }
746 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
747 | "byte" { $$ = CYNew CYIdentifier("byte"); }
748 | "double" { $$ = CYNew CYIdentifier("double"); }
749 | "each" { $$ = CYNew CYIdentifier("each"); }
750 | "final" { $$ = CYNew CYIdentifier("final"); }
751 | "float" { $$ = CYNew CYIdentifier("float"); }
752 | "goto" { $$ = CYNew CYIdentifier("goto"); }
753 | "implements" { $$ = CYNew CYIdentifier("implements"); }
754 | "interface" { $$ = CYNew CYIdentifier("interface"); }
755 | "native" { $$ = CYNew CYIdentifier("native"); }
756 | "of" { $$ = CYNew CYIdentifier("of"); }
757 | "package" { $$ = CYNew CYIdentifier("package"); }
758 | "private" { $$ = CYNew CYIdentifier("private"); }
759 | "protected" { $$ = CYNew CYIdentifier("protected"); }
760 | "public" { $$ = CYNew CYIdentifier("public"); }
761 | "static" { $$ = CYNew CYIdentifier("static"); }
762 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
763 | "throws" { $$ = CYNew CYIdentifier("throws"); }
764 | "transient" { $$ = CYNew CYIdentifier("transient"); }
765 | "yield" { $$ = CYNew CYIdentifier("yield"); }
767 | "bool" { $$ = CYNew CYIdentifier("bool"); }
768 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
769 | "id" { $$ = CYNew CYIdentifier("id"); }
770 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
776 | "char" { $$ = CYNew CYIdentifier("char"); }
777 | "int" { $$ = CYNew CYIdentifier("int"); }
778 | "long" { $$ = CYNew CYIdentifier("long"); }
779 | "short" { $$ = CYNew CYIdentifier("short"); }
780 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
781 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
783 | "extern" { $$ = CYNew CYIdentifier("extern"); }
784 | "signed" { $$ = CYNew CYIdentifier("signed"); }
785 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
786 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
789 | "nil" { $$ = CYNew CYIdentifier("nil"); }
790 | "NO" { $$ = CYNew CYIdentifier("NO"); }
791 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
792 | "YES" { $$ = CYNew CYIdentifier("YES"); }
797 : Identifier { $$ = $1; }
801 /* 12.2 Primary Expression {{{ */
803 : "this" { $$ = CYNew CYThis(); }
804 | IdentifierReference { $$ = $1; }
805 | Literal { $$ = $1; }
806 | ArrayLiteral { $$ = $1; }
807 | ObjectLiteral { $$ = $1; }
808 | RegularExpressionLiteral { $$ = $1; }
809 | TemplateLiteral { $$ = $1; }
810 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) error(@1, "invalid parenthetical"); $$ = $1; }
811 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
814 CoverParenthesizedExpressionAndArrowParameterList
815 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
816 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
819 /* 12.2.4 Literals {{{ */
821 : NullLiteral { $$ = $1; }
822 | BooleanLiteral { $$ = $1; }
823 | NumericLiteral { $$ = $1; }
824 | StringLiteral { $$ = $1; }
827 /* 12.2.5 Array Initializer {{{ */
829 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
833 : AssignmentExpression { $$ = $1; }
837 : Element { $$ = $1; }
838 | LexSetRegExp { $$ = NULL; }
842 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
843 | Element { $$ = CYNew CYElement($1, NULL); }
847 : ElementList { $$ = $1; }
848 | LexSetRegExp { $$ = NULL; }
851 /* 12.2.6 Object Initializer {{{ */
853 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
856 PropertyDefinitionList_
857 : "," PropertyDefinitionList { $$ = $2; }
858 | "," LexSetRegExp { $$ = NULL; }
862 PropertyDefinitionList
863 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
866 PropertyDefinitionListOpt
867 : PropertyDefinitionList { $$ = $1; }
868 | LexSetRegExp { $$ = NULL; }
872 // XXX: this should be IdentifierName
873 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
874 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
879 : IdentifierName { $$ = $1; }
880 | StringLiteral { $$ = $1; }
881 | NumericLiteral { $$ = $1; }
885 : LexSetRegExp PropertyName_ { $$ = $2; }
890 : "=" AssignmentExpression { $$ = $2; }
894 : Initializer { $$ = $1; }
898 /* 12.2.9 Template Literals {{{ */
900 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
901 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
905 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
906 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
910 /* 12.3+ Left-Hand-Side Expressions {{{ */
912 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
913 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
914 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
918 : MemberExpression { $$ = $1; }
919 //| "super" { $$ = $1; }
923 : LexSetRegExp PrimaryExpression { $$ = $2; }
924 | LexSetRegExp FunctionExpression { $$ = $2; }
925 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
926 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
930 : MemberExpression { $$ = $1; }
931 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
940 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
941 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
945 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
949 : "," ArgumentList { $$ = $2; }
954 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
955 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
959 : ArgumentList { $$ = $1; }
960 | LexSetRegExp { $$ = NULL; }
963 LeftHandSideExpression
964 : NewExpression { $$ = $1; }
965 | CallExpression { $$ = $1; }
968 /* 12.4 Postfix Expressions {{{ */
970 : %prec "" LeftHandSideExpression { $$ = $1; }
971 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
972 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
975 /* 12.5 Unary Operators {{{ */
977 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
978 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
979 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
980 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
981 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
982 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
983 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
984 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
985 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
986 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
987 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
991 : PostfixExpression { $$ = $1; }
992 | LexSetRegExp UnaryExpression_ { $$ = $2; }
995 /* 12.6 Multiplicative Operators {{{ */
996 MultiplicativeExpression
997 : UnaryExpression { $$ = $1; }
998 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
999 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
1000 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
1003 /* 12.7 Additive Operators {{{ */
1005 : MultiplicativeExpression { $$ = $1; }
1006 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1007 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1010 /* 12.8 Bitwise Shift Operators {{{ */
1012 : AdditiveExpression { $$ = $1; }
1013 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1014 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1015 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1018 /* 12.9 Relational Operators {{{ */
1019 RelationalExpression
1020 : ShiftExpression { $$ = $1; }
1021 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1022 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1023 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1024 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1025 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1026 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1029 /* 12.10 Equality Operators {{{ */
1031 : RelationalExpression { $$ = $1; }
1032 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1033 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1034 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1035 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1038 /* 12.11 Binary Bitwise Operators {{{ */
1039 BitwiseANDExpression
1040 : EqualityExpression { $$ = $1; }
1041 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1044 BitwiseXORExpression
1045 : BitwiseANDExpression { $$ = $1; }
1046 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1050 : BitwiseXORExpression { $$ = $1; }
1051 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1054 /* 12.12 Binary Logical Operators {{{ */
1055 LogicalANDExpression
1056 : BitwiseORExpression { $$ = $1; }
1057 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1061 : LogicalANDExpression { $$ = $1; }
1062 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1065 /* 12.13 Conditional Operator ( ? : ) {{{ */
1066 ConditionalExpression
1067 : LogicalORExpression { $$ = $1; }
1068 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1071 /* 12.14 Assignment Operators {{{ */
1072 AssignmentExpression
1073 : ConditionalExpression { $$ = $1; }
1074 // XXX: | YieldExpression { $$ = $1; }
1075 | ArrowFunction { $$ = $1; }
1076 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1077 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1078 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1079 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1080 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1081 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1082 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1083 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1084 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1085 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1086 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1087 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1090 /* 12.15 Comma Operator ( , ) {{{ */
1092 : AssignmentExpression { $$ = $1; }
1093 /* XXX: I have this backwards... */
1094 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1098 : Expression { $$ = $1; }
1099 | LexSetRegExp { $$ = NULL; }
1103 /* 13 Statements and Declarations {{{ */
1105 : BlockStatement { $$ = $1; }
1106 | VariableStatement { $$ = $1; }
1107 | EmptyStatement { $$ = $1; }
1108 | IfStatement { $$ = $1; }
1109 | BreakableStatement { $$ = $1; }
1110 | ContinueStatement { $$ = $1; }
1111 | BreakStatement { $$ = $1; }
1112 | ReturnStatement { $$ = $1; }
1113 | WithStatement { $$ = $1; }
1114 | LabelledStatement { $$ = $1; }
1115 | ThrowStatement { $$ = $1; }
1116 | TryStatement { $$ = $1; }
1117 | DebuggerStatement { $$ = $1; }
1121 : LexSetRegExp Statement__ { $$ = $2; }
1122 | ExpressionStatement { $$ = $1; }
1126 : LexSetStatement Statement_ { $$ = $2; }
1130 : HoistableDeclaration { $$ = $1; }
1131 // XXX: | ClassDeclaration { $$ = $1; }
1132 | LexicalDeclaration { $$ = $1; }
1136 : LexSetRegExp Declaration__ { $$ = $2; }
1140 : LexSetStatement Declaration_ { $$ = $2; }
1143 HoistableDeclaration
1144 : FunctionDeclaration
1145 // XXX: | GeneratorDeclaration
1149 : IterationStatement { $$ = $1; }
1150 | SwitchStatement { $$ = $1; }
1153 /* 13.2 Block {{{ */
1155 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1159 : BRACE StatementListOpt "}" { $$ = $2; }
1163 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1167 : StatementList { $$ = $1; }
1168 | LexSetStatement LexSetRegExp { $$ = NULL; }
1172 : Statement { $$ = $1; }
1173 | Declaration { $$ = $1; }
1176 /* 13.3+ Let and Const Declarations {{{ */
1178 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1190 // XXX: lots of binding stuff
1192 /* 13.3.2+ Variable Statement {{{ */
1194 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1197 VariableDeclarationList_
1198 : "," VariableDeclarationList { $$ = $2; }
1202 VariableDeclarationList
1203 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1207 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1208 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1211 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1215 : SingleNameBinding { $$ = $1; }
1219 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1222 /* 13.4 Empty Statement {{{ */
1224 : ";" { $$ = CYNew CYEmpty(); }
1227 /* 13.5 Expression Statement {{{ */
1229 : Expression Terminator { $$ = CYNew CYExpress($1); }
1232 /* 13.6 The if Statement {{{ */
1234 : "else" Statement { $$ = $2; }
1235 | %prec "if" { $$ = NULL; }
1239 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1242 /* 13.7+ Iteration Statements {{{ */
1244 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1245 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1246 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1247 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1248 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1251 ForStatementInitializer
1252 : ExpressionOpt { $$ = $1; }
1253 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1256 ForInStatementInitializer
1257 : LeftHandSideExpression { $$ = $1; }
1258 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1261 /* 13.8 The continue Statement {{{ */
1263 : "continue" LexNoNewLine
1267 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1268 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1271 /* 13.9 The break Statement {{{ */
1273 : "break" LexNoNewLine
1277 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1278 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1281 /* 13.10 The return Statement {{{ */
1283 : "return" LexNoNewLine
1287 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1288 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1291 /* 13.11 The with Statement {{{ */
1293 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1296 /* 13.12 The switch Statement {{{ */
1298 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1302 : BRACE CaseClausesOpt "}" { $$ = $2; }
1306 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1310 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1311 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1315 // XXX: the standard makes certain you can only have one of these
1317 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1320 /* 13.13 Labelled Statements {{{ */
1322 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1326 : Statement { $$ = $1; }
1327 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1330 /* 13.14 The throw Statement {{{ */
1332 : "throw" LexNoNewLine
1336 : Throw LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1337 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1340 /* 13.15 The try Statement {{{ */
1342 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1343 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1344 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1348 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1352 : "finally" Block { $$ = CYNew CYFinally($2); }
1356 : BindingIdentifier { $$ = $1; }
1357 // XXX: BindingPattern
1360 /* 13.16 The debugger Statement {{{ */
1362 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1366 /* 14.1+ Function Definitions {{{ */
1368 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1372 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1375 FormalParameterList_
1376 : "," FormalParameterList { $$ = $2; }
1381 // XXX: : FunctionRestParameter { $$ = $1; }
1382 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1385 FormalParameterListOpt
1386 : FormalParameterList
1390 /* XXX: FunctionRestParameter
1391 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1395 : BindingElement { $$ = $1; }
1399 : StatementListOpt { $$ = $1; }
1402 /* 14.2 Arrow Function Definitions {{{ */
1404 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1408 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1409 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1413 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1414 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1417 /* 14.3+ Method Definitions {{{ */
1419 /* 14.4+ Generator Function Definitions {{{ */
1421 /* 14.5+ Class Definitions {{{ */
1424 /* 15.1 Scripts {{{ */
1426 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1430 : StatementList { $$ = $1; }
1434 : ScriptBody { $$ = $1; }
1435 | LexSetStatement LexSetRegExp { $$ = NULL; }
1438 /* 15.2+ Modules {{{ */
1440 /* 15.2.2+ Imports {{{ */
1442 /* 15.2.3+ Exports {{{ */
1446 /* Cycript (C): Type Encoding {{{ */
1448 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1449 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1453 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1454 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1455 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1456 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1457 | TypeSignifier { $$ = $1; }
1458 | { $$ = CYNew CYTypedIdentifier(@$); }
1462 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1467 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1468 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1472 : PrefixedType { $$ = $1; }
1473 | SuffixedType { $$ = $1; }
1474 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1475 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1479 : "int" { $$ = CYNew CYTypeVariable("int"); }
1480 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1481 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1482 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1483 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1487 : IntegerType { $$ = $1; }
1488 | { $$ = CYNew CYTypeVariable("int"); }
1492 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1493 | IntegerType { $$ = $1; }
1494 | "void" { $$ = CYNew CYTypeVoid(); }
1495 | "char" { $$ = CYNew CYTypeVariable("char"); }
1496 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1497 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1501 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1505 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1511 /* Cycript (Objective-C): @class Declaration {{{ */
1513 /* XXX: why the hell did I choose MemberExpression? */
1514 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1519 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1520 | LexSetRegExp { $$ = NULL; }
1524 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1528 : "+" { $$ = false; }
1529 | "-" { $$ = true; }
1533 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1534 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1538 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1541 MessageParameterList
1542 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1545 MessageParameterListOpt
1546 : MessageParameterList { $$ = $1; }
1551 : MessageParameterList { $$ = $1; }
1552 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1555 ClassMessageDeclaration
1556 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1559 ClassMessageDeclarationListOpt
1560 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1565 : Identifier { $$ = $1; }
1566 | "(" AssignmentExpression ")" { $$ = $2; }
1570 : ClassName { $$ = $1; }
1574 // XXX: this should be AssignmentExpressionNoRight
1576 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1580 : "," ClassProtocols { $$ = $2; }
1584 ClassProtocolListOpt
1585 : "<" ClassProtocols ">" { $$ = $2; }
1590 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1594 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1602 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1606 : ClassExpression { $$ = $1; }
1610 : ClassStatement { $$ = $1; }
1611 | CategoryStatement { $$ = $1; }
1614 /* Cycript (Objective-C): Send Message {{{ */
1616 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1621 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1622 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1626 : SelectorCall { $$ = $1; }
1627 | VariadicCall { $$ = $1; }
1631 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1635 : SelectorCall { $$ = $1; }
1636 | Word { $$ = CYNew CYArgument($1, NULL); }
1640 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1641 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1645 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1649 : SelectorExpression_ { $$ = $1; }
1650 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1653 SelectorExpressionOpt
1654 : SelectorExpression_ { $$ = $1; }
1659 : MessageExpression { $$ = $1; }
1660 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1665 /* Cycript: @import Directive {{{ */
1667 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1668 | Word { $$ = CYNew CYModule($1); }
1672 : "@import" Module { $$ = CYNew CYImport($2); }
1677 /* Cycript (Objective-C): Boxed Expressions {{{ */
1679 : NullLiteral { $$ = $1; }
1680 | BooleanLiteral { $$ = $1; }
1681 | NumericLiteral { $$ = $1; }
1682 | StringLiteral { $$ = $1; }
1683 | ArrayLiteral { $$ = $1; }
1684 | ObjectLiteral { $$ = $1; }
1685 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1686 | "YES" { $$ = CYNew CYTrue(); }
1687 | "NO" { $$ = CYNew CYFalse(); }
1691 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1692 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1693 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1694 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1695 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1696 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1699 /* Cycript (Objective-C): Block Expressions {{{ */
1701 : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
1704 /* Cycript (Objective-C): Instance Literals {{{ */
1706 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1712 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1713 LeftHandSideExpression
1714 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1718 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1722 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1723 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1724 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1727 /* Cycript (C): auto Compatibility {{{ */
1732 /* Cycript (C): Lambda Expressions {{{ */
1734 : "," TypedParameterList { $$ = $2; }
1739 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1742 TypedParameterListOpt
1743 : TypedParameterList { $$ = $1; }
1748 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1751 /* Cycript (C): Type Definitions {{{ */
1753 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1756 /* Cycript (C): extern "C" {{{ */
1758 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
1765 /* Lexer State {{{ */
1767 : { driver.PushCondition(CYDriver::RegExpCondition); }
1771 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1775 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1779 : { driver.PopCondition(); }
1783 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1787 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1790 /* Virtual Tokens {{{ */
1797 /* 8.1 Context Keywords {{{ */
1799 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1800 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1803 /* 8.3 XML Initializer Input Elements {{{ */
1805 : XMLComment { $$ = $1; }
1806 | XMLCDATA { $$ = $1; }
1807 | XMLPI { $$ = $1; }
1811 /* 11.1 Primary Expressions {{{ */
1813 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1814 | XMLInitialiser { $$ = $1; }
1815 | XMLListInitialiser { $$ = $1; }
1819 : AttributeIdentifier { $$ = $1; }
1820 | QualifiedIdentifier { $$ = $1; }
1821 | WildcardIdentifier { $$ = $1; }
1824 /* 11.1.1 Attribute Identifiers {{{ */
1826 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1830 : PropertySelector { $$ = $1; }
1831 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1835 : Identifier { $$ = CYNew CYSelector($1); }
1836 | WildcardIdentifier { $$ = $1; }
1839 /* 11.1.2 Qualified Identifiers {{{ */
1840 QualifiedIdentifier_
1841 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1842 | QualifiedIdentifier { $$ = $1; }
1846 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1849 /* 11.1.3 Wildcard Identifiers {{{ */
1851 : "*" { $$ = CYNew CYWildcard(); }
1854 /* 11.1.4 XML Initializer {{{ */
1856 : XMLMarkup { $$ = $1; }
1857 | XMLElement { $$ = $1; }
1861 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1862 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1866 : LexPushXMLTag XMLTagName XMLAttributes
1870 : BRACE LexPushRegExp Expression LexPop "}"
1879 : XMLAttributes_ XMLAttribute
1884 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1885 | XMLAttributes_ XMLWhitespaceOpt
1894 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1898 : XMLExpression XMLElementContentOpt
1899 | XMLMarkup XMLElementContentOpt
1900 | XMLText XMLElementContentOpt
1901 | XMLElement XMLElementContentOpt
1904 XMLElementContentOpt
1909 /* 11.1.5 XMLList Initializer {{{ */
1911 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1915 /* 11.2 Left-Hand-Side Expressions {{{ */
1917 : Identifier { $$ = $1; }
1918 | PropertyIdentifier { $$ = $1; }
1922 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1923 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1924 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1927 /* 12.1 The default xml namespace Statement {{{ */
1928 /* XXX: DefaultXMLNamespaceStatement
1929 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1933 : DefaultXMLNamespaceStatement { $$ = $1; }
1938 /* JavaScript FTL: Array Comprehensions {{{ */
1940 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1944 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1945 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1948 /* JavaScript FTL: for each {{{ */
1950 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1953 /* JavaScript FTL: let Statements {{{ */
1955 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1963 /* JavaScript FTW: Array Comprehensions {{{ */
1965 : ArrayComprehension
1969 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1973 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1978 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1979 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1983 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1987 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1990 /* JavaScript FTW: Coalesce Operator {{{ */
1991 ConditionalExpression
1992 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1995 /* JavaScript FTW: Ruby Blocks {{{ */
1996 RubyProcParameterList_
1997 : "," RubyProcParameterList { $$ = $2; }
2001 RubyProcParameterList
2002 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
2007 : "|" RubyProcParameterList "|" { $$ = $2; }
2008 | "||" { $$ = NULL; }
2011 RubyProcParametersOpt
2012 : RubyProcParameters
2017 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2021 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2025 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }