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