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