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