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