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