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