]> git.saurik.com Git - cycript.git/blame - Cycript.yy.in
Remove all non-%union fields from semantic values.
[cycript.git] / Cycript.yy.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 {
4e869640 23#define cyscanner driver.scanner_
693d501b 24#define YYSTACKEXPANDABLE 1
6ce9ac92 25}
1dbba6cc 26
6ce9ac92 27%code requires {
b12a9965 28#include "Driver.hpp"
63b4c5a8 29#include "Parser.hpp"
ddeb1876 30#include "Stack.hpp"
2c1d569a 31#define CYNew new(driver.pool_)
63b4c5a8 32
cbaa5f0f 33@begin ObjectiveC
3c1c3635 34#include "ObjectiveC/Syntax.hpp"
4de0686f
JF
35@end
36
691e4717 37@begin E4X
b92ceddb 38#include "E4X/Syntax.hpp"
691e4717
JF
39@end
40
82a02ede 41#include "Highlight.hpp"
a5662a53 42}
82a02ede 43
a5662a53
JF
44%union { bool bool_; }
45
46%union { CYArgument *argument_; }
47%union { CYAssignment *assignment_; }
48%union { CYBoolean *boolean_; }
49%union { CYClause *clause_; }
50%union { cy::Syntax::Catch *catch_; }
51%union { CYComment *comment_; }
52%union { CYComprehension *comprehension_; }
53%union { CYDeclaration *declaration_; }
54%union { CYDeclarations *declarations_; }
55%union { CYElement *element_; }
56%union { CYExpression *expression_; }
57%union { CYFalse *false_; }
58%union { CYFinally *finally_; }
59%union { CYForInitialiser *for_; }
60%union { CYForInInitialiser *forin_; }
61%union { CYFunctionParameter *functionParameter_; }
62%union { CYIdentifier *identifier_; }
63%union { CYInfix *infix_; }
64%union { CYLiteral *literal_; }
65%union { CYMember *member_; }
66%union { CYModule *module_; }
67%union { CYNull *null_; }
68%union { CYNumber *number_; }
69%union { CYParenthetical *parenthetical_; }
70%union { CYProgram *program_; }
71%union { CYProperty *property_; }
72%union { CYPropertyName *propertyName_; }
73%union { CYRubyProc *rubyProc_; }
74%union { CYStatement *statement_; }
75%union { CYString *string_; }
76%union { CYThis *this_; }
77%union { CYTrue *true_; }
78%union { CYWord *word_; }
4de0686f 79
7b750785 80@begin C
a5662a53
JF
81%union { CYTypeModifier *modifier_; }
82%union { CYTypeSpecifier *specifier_; }
83%union { CYTypedIdentifier *typedIdentifier_; }
84%union { CYTypedParameter *typedParameter_; }
7b750785
JF
85@end
86
cbaa5f0f 87@begin ObjectiveC
a5662a53
JF
88%union { CYClassName *className_; }
89%union { CYClassField *classField_; }
90%union { CYMessage *message_; }
91%union { CYMessageParameter *messageParameter_; }
92%union { CYProtocol *protocol_; }
93%union { CYSelectorPart *selector_; }
4de0686f 94@end
691e4717
JF
95
96@begin E4X
a5662a53
JF
97%union { CYAttribute *attribute_; }
98%union { CYPropertyIdentifier *propertyIdentifier_; }
99%union { CYSelector *selector_; }
691e4717 100@end
63b4c5a8 101
6ce9ac92 102%code provides {
a5662a53
JF
103
104struct YYSTYPE {
105 cy::parser::semantic_type semantic_;
106 hi::Value highlight_;
107};
108
58afc6aa 109int cylex(YYSTYPE *, CYLocation *, void *);
a5662a53
JF
110
111}
112
113%code {
114
115#undef yylex
116_finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, void *scanner) {
117 YYSTYPE data;
118 int token(cylex(&data, location, scanner));
119 *semantic = data.semantic_;
120 return token;
121}
122
6ce9ac92 123}
c5aeb567 124
6ce9ac92 125%name-prefix "cy"
e5332278 126
6ce9ac92 127%language "C++"
1dbba6cc 128
5999c315
JF
129%initial-action {
130 @$.begin.filename = @$.end.filename = &driver.filename_;
131};
132
be36c292 133%locations
e5332278 134%defines
1dbba6cc 135
58afc6aa
JF
136%define api.location.type { CYLocation }
137
534fb6da
JF
138//%glr-parser
139//%expect 1
cac61857 140
e5332278
JF
141%error-verbose
142
5999c315 143%parse-param { CYDriver &driver }
4e869640 144%lex-param { void *cyscanner }
e5332278 145
c3b144b8 146/* Token Declarations {{{ */
cb02f8ae 147@begin E4X
cb02f8ae
JF
148%token XMLCDATA
149%token XMLComment
150%token XMLPI
691e4717
JF
151
152%token XMLAttributeValue
153%token XMLName
154%token XMLTagCharacters
155%token XMLText
156%token XMLWhitespace
157@end
158
159@begin E4X
160%token LeftRight "<>"
161%token LeftSlashRight "</>"
162
163%token SlashRight "/>"
164%token LeftSlash "</"
165
691e4717
JF
166%token ColonColon "::"
167%token PeriodPeriod ".."
cb02f8ae 168@end
ac9a5ce1 169
b1589845
JF
170@begin E4X ObjectiveC
171%token At "@"
ac9d4181 172%token Pound "#"
b1589845
JF
173@end
174
63b4c5a8
JF
175%token Ampersand "&"
176%token AmpersandAmpersand "&&"
177%token AmpersandEqual "&="
178%token Carrot "^"
179%token CarrotEqual "^="
180%token Equal "="
181%token EqualEqual "=="
182%token EqualEqualEqual "==="
4b2fd91c 183%token EqualRight "=>"
6265f0de 184%token EqualRight_ "\n=>"
63b4c5a8
JF
185%token Exclamation "!"
186%token ExclamationEqual "!="
187%token ExclamationEqualEqual "!=="
188%token Hyphen "-"
189%token HyphenEqual "-="
190%token HyphenHyphen "--"
c3c20102 191%token HyphenHyphen_ "\n--"
63b4c5a8
JF
192%token HyphenRight "->"
193%token Left "<"
194%token LeftEqual "<="
195%token LeftLeft "<<"
196%token LeftLeftEqual "<<="
197%token Percent "%"
198%token PercentEqual "%="
199%token Period "."
c8a0500b 200%token PeriodPeriodPeriod "..."
63b4c5a8
JF
201%token Pipe "|"
202%token PipeEqual "|="
203%token PipePipe "||"
204%token Plus "+"
205%token PlusEqual "+="
206%token PlusPlus "++"
c3c20102 207%token PlusPlus_ "\n++"
63b4c5a8
JF
208%token Right ">"
209%token RightEqual ">="
210%token RightRight ">>"
211%token RightRightEqual ">>="
212%token RightRightRight ">>>"
213%token RightRightRightEqual ">>>="
214%token Slash "/"
215%token SlashEqual "/="
216%token Star "*"
217%token StarEqual "*="
218%token Tilde "~"
219
220%token Colon ":"
221%token Comma ","
222%token Question "?"
223%token SemiColon ";"
c3c20102 224%token NewLine "\n"
63b4c5a8 225
320ce753
JF
226%token <comment_> Comment
227
63b4c5a8
JF
228%token OpenParen "("
229%token CloseParen ")"
924f67b2 230
63b4c5a8 231%token OpenBrace "{"
6c093cce 232%token OpenBrace_ "\n{"
3ea7eed0 233%token OpenBrace__ ";{"
63b4c5a8 234%token CloseBrace "}"
924f67b2 235
63b4c5a8
JF
236%token OpenBracket "["
237%token CloseBracket "]"
238
09e4db67 239%token At_error_ "@error"
dc5d7cf4 240
1ba6903e 241@begin Java
09e4db67 242%token At_class_ "@class"
1ba6903e
JF
243@end
244
60097023 245@begin C
09e4db67
JF
246%token _typedef_ "typedef"
247%token _unsigned_ "unsigned"
248%token _signed_ "signed"
249%token _extern_ "extern"
60097023
JF
250@end
251
8a2eb1be 252@begin C
09e4db67 253%token At_encode_ "@encode"
8a2eb1be
JF
254@end
255
1ba6903e 256@begin ObjectiveC
09e4db67
JF
257%token At_implementation_ "@implementation"
258%token At_implementation__ ";@implementation"
259%token At_import_ "@import"
260%token At_end_ "@end"
261%token At_selector_ "@selector"
262%token At_null_ "@null"
263%token At_YES_ "@YES"
264%token At_NO_ "@NO"
265%token At_true_ "@true"
266%token At_false_ "@false"
267%token _YES_ "YES"
268%token _NO_ "NO"
1ba6903e 269@end
e7ed5354 270
09e4db67
JF
271%token _false_ "false"
272%token _null_ "null"
273%token _true_ "true"
274
275%token _break_ "break"
276%token _case_ "case"
277%token _catch_ "catch"
278%token _class_ "class"
279%token _const_ "const"
280%token _continue_ "continue"
281%token _debugger_ "debugger"
282%token _default_ "default"
283%token _delete_ "delete"
284%token _do_ "do"
285%token _else_ "else"
286%token _enum_ "enum"
287%token _export_ "export"
288%token _extends_ "extends"
289%token _finally_ "finally"
290%token _for_ "for"
291%token _function_ "function"
292%token _function__ ";function"
293%token _if_ "if"
294%token _import_ "import"
295%token _in_ "in"
296%token _in__ "!in"
297%token _instanceof_ "instanceof"
298%token _new_ "new"
299%token _return_ "return"
300%token _super_ "super"
301%token _switch_ "switch"
302%token _this_ "this"
303%token _throw_ "throw"
304%token _try_ "try"
305%token _typeof_ "typeof"
306%token _var_ "var"
307%token _void_ "void"
308%token _while_ "while"
309%token _with_ "with"
310
311%token _abstract_ "abstract"
312%token _await_ "await"
313%token _boolean_ "boolean"
314%token _byte_ "byte"
315%token _char_ "char"
316%token _double_ "double"
317%token _final_ "final"
318%token _float_ "float"
319%token _goto_ "goto"
320%token _implements_ "implements"
321%token _int_ "int"
322%token _interface_ "interface"
323%token _let_ "let"
324%token _long_ "long"
325%token _native_ "native"
326%token _package_ "package"
327%token _private_ "private"
328%token _protected_ "protected"
329%token _public_ "public"
330%token _short_ "short"
331%token _static_ "static"
332%token _synchronized_ "synchronized"
333%token _throws_ "throws"
334%token _transient_ "transient"
335%token _volatile_ "volatile"
336%token _yield_ "yield"
337
338%token _undefined_ "undefined"
339
340@begin ObjectiveC
341%token _bool_ "bool"
342%token _BOOL_ "BOOL"
343%token _id_ "id"
344%token _nil_ "nil"
345%token _NULL_ "NULL"
346%token _SEL_ "SEL"
347@end
348
349%token _auto_ "auto"
350%token _each_ "each"
351%token _of_ "of"
75b0a457 352
691e4717 353@begin E4X
09e4db67
JF
354%token _namespace_ "namespace"
355%token _xml_ "xml"
691e4717
JF
356@end
357
7e5391fd
JF
358%token AutoComplete
359
75b0a457 360%token <identifier_> Identifier_
63b4c5a8
JF
361%token <number_> NumericLiteral
362%token <string_> StringLiteral
63cd45c9 363%token <literal_> RegularExpressionLiteral
1dbba6cc 364
cf7d4c69 365%type <expression_> AdditiveExpression
cf7d4c69 366%type <argument_> ArgumentList_
55fc1817 367%type <argument_> ArgumentList
cf7d4c69
JF
368%type <argument_> ArgumentListOpt
369%type <argument_> Arguments
b3aa25d8
JF
370%type <expression_> ArrayComprehension
371%type <expression_> ArrayInitialiser
cf7d4c69 372%type <literal_> ArrayLiteral
4b2fd91c
JF
373%type <expression_> ArrowFunction
374%type <functionParameter_> ArrowParameters
55fc1817 375%type <expression_> AssignmentExpression
c2529502 376%type <identifier_> Binding
c8a0500b 377%type <identifier_> BindingIdentifier
cf7d4c69 378%type <expression_> BitwiseANDExpression
cac61857 379%type <statement_> Block_
55fc1817 380%type <statement_> Block
cf7d4c69 381%type <boolean_> BooleanLiteral
c8a0500b 382%type <declaration_> BindingElement
cf7d4c69
JF
383%type <expression_> BitwiseORExpression
384%type <expression_> BitwiseXORExpression
385%type <statement_> BreakStatement
c8a0500b 386%type <statement_> BreakableStatement
3ea7eed0 387%type <expression_> CallExpression_
cf7d4c69
JF
388%type <expression_> CallExpression
389%type <clause_> CaseBlock
390%type <clause_> CaseClause
391%type <clause_> CaseClausesOpt
392%type <catch_> CatchOpt
b3aa25d8
JF
393%type <expression_> Comprehension
394%type <comprehension_> ComprehensionFor
395%type <comprehension_> ComprehensionIf
396%type <comprehension_> ComprehensionTail
cf7d4c69
JF
397%type <expression_> ConditionalExpression
398%type <statement_> ContinueStatement
4b2fd91c 399%type <statement_> ConciseBody
c8a0500b 400%type <statement_> DebuggerStatement
3ea7eed0
JF
401%type <statement_> Declaration__
402%type <statement_> Declaration_
c8a0500b 403%type <statement_> Declaration
cf7d4c69 404%type <clause_> DefaultClause
cf7d4c69 405%type <expression_> Element
5befe15e 406%type <expression_> ElementOpt
cf7d4c69 407%type <element_> ElementList
5befe15e 408%type <element_> ElementListOpt
cf7d4c69
JF
409%type <statement_> ElseStatementOpt
410%type <statement_> EmptyStatement
411%type <expression_> EqualityExpression
b0385401 412%type <expression_> Expression
cf7d4c69
JF
413%type <expression_> ExpressionOpt
414%type <statement_> ExpressionStatement
b10bd496 415%type <finally_> FinallyOpt
cf7d4c69 416%type <for_> ForStatementInitialiser
cf7d4c69 417%type <forin_> ForInStatementInitialiser
c8a0500b 418%type <declaration_> FormalParameter
b09da87b 419%type <functionParameter_> FormalParameterList_
55fc1817 420%type <functionParameter_> FormalParameterList
c8a0500b 421%type <functionParameter_> FormalParameterListOpt
b10bd496
JF
422%type <statement_> FunctionBody
423%type <statement_> FunctionDeclaration
cf7d4c69 424%type <expression_> FunctionExpression
75b0a457 425%type <identifier_> Identifier
cf7d4c69 426%type <identifier_> IdentifierOpt
3fe283c5 427%type <identifier_> IdentifierType
4492c19c 428%type <word_> IdentifierName
cf7d4c69
JF
429%type <statement_> IfStatement
430%type <expression_> Initialiser
431%type <expression_> InitialiserOpt
432%type <statement_> IterationStatement
433%type <statement_> LabelledStatement
434%type <expression_> LeftHandSideExpression
15b88a33 435%type <statement_> LetStatement
c8a0500b 436%type <statement_> LexicalDeclaration
cf7d4c69 437%type <literal_> Literal
c3b144b8 438%type <literal_> ValueLiteral
cf7d4c69
JF
439%type <expression_> LogicalANDExpression
440%type <expression_> LogicalORExpression
9b5527f0 441%type <member_> MemberAccess
693d501b 442%type <expression_> MemberExpression_
55fc1817 443%type <expression_> MemberExpression
7b750785 444%type <module_> Module
cf7d4c69 445%type <expression_> MultiplicativeExpression
55fc1817 446%type <expression_> NewExpression
cf7d4c69
JF
447%type <null_> NullLiteral
448%type <literal_> ObjectLiteral
b0385401 449%type <parenthetical_> Parenthetical
cf7d4c69
JF
450%type <expression_> PostfixExpression
451%type <expression_> PrimaryExpression
b10bd496 452%type <statement_> Program
c8a0500b
JF
453%type <statement_> ProgramBody
454%type <statement_> ProgramBodyOpt
b92ceddb 455%type <propertyName_> PropertyName_
55fc1817 456%type <propertyName_> PropertyName
aea76473
JF
457%type <property_> PropertyDefinition
458%type <property_> PropertyDefinitionList_
459%type <property_> PropertyDefinitionList
460%type <property_> PropertyDefinitionListOpt
55fc1817 461%type <expression_> RelationalExpression
cf7d4c69 462%type <statement_> ReturnStatement
6c093cce 463%type <rubyProc_> RubyProcExpression
6c093cce 464%type <functionParameter_> RubyProcParameterList_
55fc1817 465%type <functionParameter_> RubyProcParameterList
d7205a63 466%type <functionParameter_> RubyProcParameters
6c093cce 467%type <functionParameter_> RubyProcParametersOpt
cf7d4c69 468%type <expression_> ShiftExpression
c8a0500b 469%type <declaration_> SingleNameBinding
3ea7eed0 470%type <statement_> Statement__
b10bd496 471%type <statement_> Statement_
55fc1817 472%type <statement_> Statement
693d501b 473%type <statement_> StatementList
cf7d4c69 474%type <statement_> StatementListOpt
c8a0500b 475%type <statement_> StatementListItem
cf7d4c69
JF
476%type <statement_> SwitchStatement
477%type <statement_> ThrowStatement
478%type <statement_> TryStatement
693d501b 479%type <expression_> UnaryExpression_
55fc1817 480%type <expression_> UnaryExpression
cf7d4c69 481%type <declaration_> VariableDeclaration
cf7d4c69 482%type <declarations_> VariableDeclarationList_
55fc1817 483%type <declarations_> VariableDeclarationList
cf7d4c69 484%type <statement_> VariableStatement
cf7d4c69 485%type <statement_> WithStatement
4492c19c 486%type <word_> Word
73f04979 487@begin ObjectiveC
4492c19c 488%type <word_> WordOpt
73f04979 489@end
46f4f308 490%type <expression_> Variable
cf7d4c69 491
7b750785 492@begin C
7b750785
JF
493%type <specifier_> IntegerType
494%type <specifier_> IntegerTypeOpt
495%type <typedIdentifier_> PrefixedType
496%type <specifier_> PrimitiveType
7b750785 497%type <typedIdentifier_> SuffixedType
00b4cb83 498%type <typedIdentifier_> TypeSignifier
7b750785
JF
499%type <modifier_> TypeQualifierLeft
500%type <typedIdentifier_> TypeQualifierRight
501%type <typedIdentifier_> TypedIdentifier
502%type <typedParameter_> TypedParameterList_
503%type <typedParameter_> TypedParameterList
504%type <typedParameter_> TypedParameterListOpt
505@end
506
507@begin ObjectiveC
c3b144b8 508%type <expression_> BoxableExpression
328ad766
JF
509%type <statement_> CategoryStatement
510%type <expression_> ClassExpression
b6a67580
JF
511%type <classField_> ClassFieldListOpt
512%type <classField_> ClassFields
328ad766
JF
513%type <statement_> ClassStatement
514%type <expression_> ClassSuperOpt
328ad766
JF
515%type <message_> ClassMessageDeclaration
516%type <message_> ClassMessageDeclarationListOpt
517%type <className_> ClassName
518%type <className_> ClassNameOpt
64b8d29f
JF
519%type <protocol_> ClassProtocolListOpt
520%type <protocol_> ClassProtocols
521%type <protocol_> ClassProtocolsOpt
693d501b 522%type <expression_> MessageExpression
328ad766
JF
523%type <messageParameter_> MessageParameter
524%type <messageParameter_> MessageParameters
525%type <messageParameter_> MessageParameterList
526%type <messageParameter_> MessageParameterListOpt
527%type <bool_> MessageScope
693d501b 528%type <argument_> SelectorCall_
55fc1817 529%type <argument_> SelectorCall
328ad766 530%type <selector_> SelectorExpression_
55fc1817 531%type <selector_> SelectorExpression
328ad766 532%type <selector_> SelectorExpressionOpt
693d501b 533%type <argument_> SelectorList
7e5391fd 534%type <word_> SelectorWordOpt
57d55714 535%type <typedIdentifier_> TypeOpt
693d501b 536%type <argument_> VariadicCall
328ad766 537@end
693d501b 538
691e4717 539@begin E4X
b92ceddb 540%type <propertyIdentifier_> PropertyIdentifier_
b92ceddb 541%type <selector_> PropertySelector_
55fc1817 542%type <selector_> PropertySelector
691e4717 543%type <identifier_> QualifiedIdentifier_
55fc1817 544%type <identifier_> QualifiedIdentifier
691e4717
JF
545%type <identifier_> WildcardIdentifier
546%type <identifier_> XMLComment
547%type <identifier_> XMLCDATA
548%type <identifier_> XMLElement
549%type <identifier_> XMLElementContent
550%type <identifier_> XMLMarkup
551%type <identifier_> XMLPI
552
553%type <attribute_> AttributeIdentifier
b92ceddb 554/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
691e4717
JF
555%type <expression_> PropertyIdentifier
556%type <expression_> XMLListInitialiser
557%type <expression_> XMLInitialiser
558@end
c3b144b8
JF
559/* }}} */
560/* Token Priorities {{{ */
3ea7eed0
JF
561%nonassoc ""
562%left "++" "--"
b92ceddb
JF
563
564%nonassoc "if"
565%nonassoc "else"
c3b144b8 566/* }}} */
b92ceddb 567
693d501b 568%start Program
e5332278 569
693d501b 570%%
c3c20102 571
691e4717 572/* Lexer State {{{ */
3ea7eed0
JF
573LexPushInOn
574 : { driver.in_.push(true); }
575 ;
576
577LexPushInOff
578 : { driver.in_.push(false); }
579 ;
580
581LexPopIn
582 : { driver.in_.pop(); }
583 ;
584
691e4717
JF
585LexSetRegExp
586 : { driver.SetCondition(CYDriver::RegExpCondition); }
587 ;
3ea7eed0 588
a5662a53
JF
589LexNoNewLine
590 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.no_.NewLine = true; }
591 ;
592
4b2fd91c 593LexNoBrace
6ce9ac92 594 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
4b2fd91c 595 ;
066da9f6 596
4b2fd91c 597LexNoFunction
09e4db67 598 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); }
4b2fd91c
JF
599 ;
600
39ed6a51
JF
601LexNoAtImplementation :
602@begin ObjectiveC
09e4db67 603 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); }
39ed6a51 604@end
507848cd
JF
605 ;
606
4b2fd91c 607LexSetStatement
507848cd 608 : LexNoBrace LexNoFunction LexNoAtImplementation
3ea7eed0 609 ;
691e4717 610/* }}} */
c3b144b8 611/* Virtual Tokens {{{ */
3ea7eed0 612BRACE
6c093cce
JF
613 : "{"
614 | "\n{"
615 ;
a87d7060
JF
616
617Var_
618 : "var"
619 ;
c3b144b8 620/* }}} */
6c093cce 621
c3b144b8
JF
622/* 7.6 Identifier Names and Identifiers {{{ */
623IdentifierName
624 : Word { $$ = $1; }
c3c20102
JF
625 ;
626
36cd3cb9 627Word
cf7d4c69 628 : Identifier { $$ = $1; }
aca28f96 629
8f56307d 630 | "auto" { $$ = CYNew CYWord("auto"); }
a5662a53 631 | "break" { $$ = CYNew CYWord("break"); }
8f56307d
JF
632 | "case" { $$ = CYNew CYWord("case"); }
633 | "catch" { $$ = CYNew CYWord("catch"); }
634 | "class" { $$ = CYNew CYWord("class"); }
635 | "const" { $$ = CYNew CYWord("const"); }
a5662a53 636 | "continue" { $$ = CYNew CYWord("continue"); }
8f56307d
JF
637 | "debugger" { $$ = CYNew CYWord("debugger"); }
638 | "default" { $$ = CYNew CYWord("default"); }
639 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
640 | "do" { $$ = CYNew CYWord("do"); }
641 | "else" { $$ = CYNew CYWord("else"); }
642 | "enum" { $$ = CYNew CYWord("enum"); }
643 | "export" { $$ = CYNew CYWord("export"); }
644 | "extends" { $$ = CYNew CYWord("extends"); }
645 | "false" { $$ = CYNew CYWord("false"); }
646 | "finally" { $$ = CYNew CYWord("finally"); }
647 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
648 | "function" { $$ = CYNew CYWord("function"); }
649 | "if" { $$ = CYNew CYWord("if"); }
650 | "import" { $$ = CYNew CYWord("import"); }
651 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
652 | "!in" { $$ = CYNew CYWord("in"); }
653 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
dd983804
JF
654
655 // XXX: as it currently is not an Identifier
d6e7cafb 656 | "let" { $$ = CYNew CYIdentifier("let"); }
dd983804 657
8f56307d
JF
658 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
659 | "null" { $$ = CYNew CYWord("null"); }
a5662a53 660 | "return" { $$ = CYNew CYWord("return"); }
8f56307d
JF
661 | "super" { $$ = CYNew CYWord("super"); }
662 | "switch" { $$ = CYNew CYWord("switch"); }
663 | "this" { $$ = CYNew CYWord("this"); }
a5662a53 664 | "throw" { $$ = CYNew CYWord("throw"); }
8f56307d
JF
665 | "true" { $$ = CYNew CYWord("true"); }
666 | "try" { $$ = CYNew CYWord("try"); }
667 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
668 | "var" { $$ = CYNew CYWord("var"); }
669 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
670 | "while" { $$ = CYNew CYWord("while"); }
671 | "with" { $$ = CYNew CYWord("with"); }
2bf24581 672 ;
f2f0d1d1 673
73f04979 674@begin ObjectiveC
55fc1817
JF
675WordOpt
676 : Word { $$ = $1; }
677 | { $$ = NULL; }
678 ;
73f04979 679@end
55fc1817 680
3fe283c5 681IdentifierType
75b0a457 682 : Identifier_ { $$ = $1; }
534fb6da 683
d6e7cafb
JF
684 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
685 | "await" { $$ = CYNew CYIdentifier("await"); }
686 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
687 | "byte" { $$ = CYNew CYIdentifier("byte"); }
688 | "double" { $$ = CYNew CYIdentifier("double"); }
689 | "final" { $$ = CYNew CYIdentifier("final"); }
690 | "float" { $$ = CYNew CYIdentifier("float"); }
691 | "goto" { $$ = CYNew CYIdentifier("goto"); }
692 | "implements" { $$ = CYNew CYIdentifier("implements"); }
693 | "interface" { $$ = CYNew CYIdentifier("interface"); }
694 | "native" { $$ = CYNew CYIdentifier("native"); }
695 | "package" { $$ = CYNew CYIdentifier("package"); }
696 | "private" { $$ = CYNew CYIdentifier("private"); }
697 | "protected" { $$ = CYNew CYIdentifier("protected"); }
698 | "public" { $$ = CYNew CYIdentifier("public"); }
699 | "static" { $$ = CYNew CYIdentifier("static"); }
700 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
701 | "throws" { $$ = CYNew CYIdentifier("throws"); }
702 | "transient" { $$ = CYNew CYIdentifier("transient"); }
534fb6da 703
dd983804 704 // XXX: currently I only have this as Word
d6e7cafb 705 // | "let" { $$ = CYNew CYIdentifier("let"); }
dd983804 706
a5662a53 707 | "yield" { $$ = CYNew CYIdentifier("yield"); }
534fb6da 708
d6e7cafb
JF
709 | "each" { $$ = CYNew CYIdentifier("each"); }
710 | "of" { $$ = CYNew CYIdentifier("of"); }
09e4db67
JF
711
712@begin ObjectiveC
713 | "bool" { $$ = CYNew CYIdentifier("bool"); }
714 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
715 | "id" { $$ = CYNew CYIdentifier("id"); }
716 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
717@end
75b0a457
JF
718 ;
719
3fe283c5
JF
720Identifier
721 : IdentifierType
d6e7cafb
JF
722 | "char" { $$ = CYNew CYIdentifier("char"); }
723 | "int" { $$ = CYNew CYIdentifier("int"); }
724 | "long" { $$ = CYNew CYIdentifier("long"); }
725 | "short" { $$ = CYNew CYIdentifier("short"); }
09e4db67 726 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
d6e7cafb 727 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
3fe283c5 728@begin C
d6e7cafb
JF
729 | "extern" { $$ = CYNew CYIdentifier("extern"); }
730 | "signed" { $$ = CYNew CYIdentifier("signed"); }
731 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
732 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
7b750785
JF
733@end
734@begin ObjectiveC
09e4db67 735 | "nil" { $$ = CYNew CYIdentifier("nil"); }
d6e7cafb 736 | "NO" { $$ = CYNew CYIdentifier("NO"); }
09e4db67 737 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
d6e7cafb 738 | "YES" { $$ = CYNew CYIdentifier("YES"); }
3fe283c5
JF
739@end
740 ;
741
36cd3cb9 742IdentifierOpt
cf7d4c69
JF
743 : Identifier { $$ = $1; }
744 | { $$ = NULL; }
1dbba6cc 745 ;
c3b144b8 746/* }}} */
1dbba6cc 747
c3b144b8
JF
748/* 7.8 Literals {{{ */
749Literal
cf7d4c69 750 : NullLiteral { $$ = $1; }
c3b144b8 751 | ValueLiteral { $$ = $1; }
561ac418
JF
752 ;
753
c3b144b8
JF
754ValueLiteral
755 : BooleanLiteral { $$ = $1; }
756 | NumericLiteral { $$ = $1; }
757 | StringLiteral { $$ = $1; }
3ea7eed0 758 | RegularExpressionLiteral { $$ = $1; }
1dbba6cc 759 ;
c3b144b8
JF
760/* }}} */
761/* 7.8.1 Null Literals {{{ */
36cd3cb9 762NullLiteral
8f56307d 763 : "null" { $$ = CYNew CYNull(); }
1dbba6cc 764 ;
c3b144b8
JF
765/* }}} */
766/* 7.8.2 Boolean Literals {{{ */
36cd3cb9 767BooleanLiteral
8f56307d
JF
768 : "true" { $$ = CYNew CYTrue(); }
769 | "false" { $$ = CYNew CYFalse(); }
1dbba6cc 770 ;
c3b144b8
JF
771/* }}} */
772
773/* 7.9 Automatic Semicolon Insertion {{{ */
774StrictSemi
6ce9ac92 775 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
c3b144b8
JF
776 ;
777
a5662a53
JF
778TerminatorSoft
779 : ";"
780 | "\n" StrictSemi
781 ;
782
c3b144b8
JF
783Terminator
784 : ";"
a5662a53 785 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
c3b144b8
JF
786 ;
787
788TerminatorOpt
789 : ";"
790 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
791 ;
792/* }}} */
1dbba6cc 793
1dbba6cc 794/* 11.1 Primary Expressions {{{ */
3ea7eed0 795Parenthetical
b0385401 796 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
561ac418
JF
797 ;
798
46f4f308
JF
799Variable
800 : Identifier { $$ = CYNew CYVariable($1); }
801 ;
802
3ea7eed0 803PrimaryExpression
8f56307d 804 : "this" { $$ = CYNew CYThis(); }
46f4f308 805 | Variable { $$ = $1; }
cf7d4c69 806 | Literal { $$ = $1; }
b3aa25d8 807 | ArrayInitialiser { $$ = $1; }
3ea7eed0 808 | ObjectLiteral { $$ = $1; }
3ea7eed0
JF
809 | Parenthetical { $$ = $1; }
810 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1dbba6cc
JF
811 ;
812/* }}} */
b3aa25d8
JF
813/* 11.1.4 Array Initializer {{{ */
814ArrayInitialiser
815 : ArrayLiteral { $$ = $1; }
816 | ArrayComprehension { $$ = $1; }
817 ;
818/* }}} */
819/* 11.1.4.1 Array Literal {{{ */
36cd3cb9 820ArrayLiteral
440424e2 821 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
1dbba6cc
JF
822 ;
823
36cd3cb9 824Element
cf7d4c69 825 : AssignmentExpression { $$ = $1; }
5befe15e
JF
826 ;
827
828ElementOpt
829 : Element { $$ = $1; }
691e4717 830 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
831 ;
832
36cd3cb9 833ElementList
2eb8215d
JF
834 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
835 | Element { $$ = CYNew CYElement($1, NULL); }
1dbba6cc 836 ;
55fc1817
JF
837
838ElementListOpt
839 : ElementList { $$ = $1; }
840 | LexSetRegExp { $$ = NULL; }
841 ;
1dbba6cc 842/* }}} */
c2529502 843/* 11.1.4.2 Array Comprehension {{{ */
b3aa25d8
JF
844ArrayComprehension
845 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
c2529502
JF
846 ;
847
b3aa25d8
JF
848Comprehension
849 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
c2529502
JF
850 ;
851
b3aa25d8
JF
852ComprehensionTail
853 : { $$ = NULL; }
854 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
855 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
856 ;
857
858ComprehensionFor
859 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
860 ;
861
862ComprehensionIf
863 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
c2529502
JF
864 ;
865/* }}} */
1dbba6cc 866/* 11.1.5 Object Initialiser {{{ */
36cd3cb9 867ObjectLiteral
440424e2 868 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
1dbba6cc
JF
869 ;
870
aea76473
JF
871PropertyDefinitionList_
872 : "," PropertyDefinitionList { $$ = $2; }
70234143 873 | "," LexSetRegExp { $$ = NULL; }
cac61857 874 | { $$ = NULL; }
1dbba6cc
JF
875 ;
876
aea76473
JF
877PropertyDefinitionList
878 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
55fc1817
JF
879 ;
880
aea76473
JF
881PropertyDefinitionListOpt
882 : PropertyDefinitionList { $$ = $1; }
70234143 883 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
884 ;
885
aea76473 886PropertyDefinition
797cb0e5
JF
887 // XXX: this should be IdentifierName
888 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
889 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
aea76473
JF
890 //| MethodDefinition
891 ;
892
b92ceddb 893PropertyName_
4492c19c 894 : IdentifierName { $$ = $1; }
36cd3cb9
JF
895 | StringLiteral { $$ = $1; }
896 | NumericLiteral { $$ = $1; }
1dbba6cc 897 ;
b92ceddb
JF
898
899PropertyName
900 : LexSetRegExp PropertyName_ { $$ = $2; }
901 ;
1dbba6cc
JF
902/* }}} */
903
63cd45c9 904/* 11.2 Left-Hand-Side Expressions {{{ */
9b5527f0 905MemberAccess
440424e2 906 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
5ccfc586 907 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
7e5391fd 908 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
9b5527f0
JF
909 ;
910
55fc1817 911MemberExpression_
3ea7eed0
JF
912 : MemberExpression { $$ = $1; }
913 //| "super" { $$ = $1; }
55fc1817
JF
914 ;
915
36cd3cb9 916MemberExpression
3ea7eed0 917 : LexSetRegExp PrimaryExpression { $$ = $2; }
afbff131 918 | LexSetRegExp FunctionExpression { $$ = $2; }
3ea7eed0
JF
919 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
920 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
1dbba6cc
JF
921 ;
922
36cd3cb9 923NewExpression
cf7d4c69 924 : MemberExpression { $$ = $1; }
3ea7eed0 925 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
1dbba6cc
JF
926 ;
927
3ea7eed0
JF
928CallExpression_
929 : MemberExpression_
930 | CallExpression
b1589845
JF
931 ;
932
36cd3cb9 933CallExpression
3ea7eed0 934 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
7e5391fd 935 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
1dbba6cc
JF
936 ;
937
3ea7eed0 938Arguments
440424e2 939 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
b1589845
JF
940 ;
941
36cd3cb9 942ArgumentList_
cf7d4c69
JF
943 : "," ArgumentList { $$ = $2; }
944 | { $$ = NULL; }
1dbba6cc
JF
945 ;
946
55fc1817
JF
947ArgumentList
948 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
ed493ddd 949 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
55fc1817
JF
950 ;
951
36cd3cb9 952ArgumentListOpt
cf7d4c69 953 : ArgumentList { $$ = $1; }
691e4717 954 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
955 ;
956
36cd3cb9 957LeftHandSideExpression
cf7d4c69
JF
958 : NewExpression { $$ = $1; }
959 | CallExpression { $$ = $1; }
693d501b 960 ;
63cd45c9
JF
961/* }}} */
962/* 11.3 Postfix Expressions {{{ */
36cd3cb9 963PostfixExpression
3ea7eed0 964 : %prec "" LeftHandSideExpression { $$ = $1; }
2eb8215d
JF
965 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
966 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
1dbba6cc 967 ;
63cd45c9
JF
968/* }}} */
969/* 11.4 Unary Operators {{{ */
693d501b 970UnaryExpression_
2eb8215d
JF
971 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
972 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
973 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
974 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
975 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
976 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
977 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
978 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
979 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
980 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
981 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
693d501b
JF
982 ;
983
984UnaryExpression
985 : PostfixExpression { $$ = $1; }
691e4717 986 | LexSetRegExp UnaryExpression_ { $$ = $2; }
693d501b 987 ;
63cd45c9
JF
988/* }}} */
989/* 11.5 Multiplicative Operators {{{ */
36cd3cb9 990MultiplicativeExpression
cf7d4c69 991 : UnaryExpression { $$ = $1; }
2eb8215d
JF
992 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
993 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
994 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
1dbba6cc 995 ;
63cd45c9
JF
996/* }}} */
997/* 11.6 Additive Operators {{{ */
36cd3cb9 998AdditiveExpression
cf7d4c69 999 : MultiplicativeExpression { $$ = $1; }
2eb8215d
JF
1000 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1001 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1dbba6cc 1002 ;
63cd45c9
JF
1003/* }}} */
1004/* 11.7 Bitwise Shift Operators {{{ */
36cd3cb9 1005ShiftExpression
cf7d4c69 1006 : AdditiveExpression { $$ = $1; }
2eb8215d
JF
1007 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1008 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1009 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1dbba6cc 1010 ;
63cd45c9
JF
1011/* }}} */
1012/* 11.8 Relational Operators {{{ */
3ea7eed0 1013RelationalExpression
05089169
JF
1014 : ShiftExpression { $$ = $1; }
1015 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1016 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1017 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1018 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1019 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1020 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
693d501b 1021 ;
63cd45c9
JF
1022/* }}} */
1023/* 11.9 Equality Operators {{{ */
36cd3cb9 1024EqualityExpression
cf7d4c69 1025 : RelationalExpression { $$ = $1; }
2eb8215d
JF
1026 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1027 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1028 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1029 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1dbba6cc 1030 ;
63cd45c9
JF
1031/* }}} */
1032/* 11.10 Binary Bitwise Operators {{{ */
36cd3cb9 1033BitwiseANDExpression
cf7d4c69 1034 : EqualityExpression { $$ = $1; }
2eb8215d 1035 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1dbba6cc
JF
1036 ;
1037
36cd3cb9 1038BitwiseXORExpression
cf7d4c69 1039 : BitwiseANDExpression { $$ = $1; }
2eb8215d 1040 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1dbba6cc
JF
1041 ;
1042
36cd3cb9 1043BitwiseORExpression
cf7d4c69 1044 : BitwiseXORExpression { $$ = $1; }
2eb8215d 1045 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1dbba6cc 1046 ;
63cd45c9
JF
1047/* }}} */
1048/* 11.11 Binary Logical Operators {{{ */
36cd3cb9 1049LogicalANDExpression
cf7d4c69 1050 : BitwiseORExpression { $$ = $1; }
2eb8215d 1051 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1dbba6cc
JF
1052 ;
1053
36cd3cb9 1054LogicalORExpression
cf7d4c69 1055 : LogicalANDExpression { $$ = $1; }
2eb8215d 1056 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1dbba6cc 1057 ;
63cd45c9
JF
1058/* }}} */
1059/* 11.12 Conditional Operator ( ? : ) {{{ */
36cd3cb9 1060ConditionalExpression
cf7d4c69 1061 : LogicalORExpression { $$ = $1; }
440424e2 1062 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
c2faf0d3 1063 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
693d501b 1064 ;
63cd45c9
JF
1065/* }}} */
1066/* 11.13 Assignment Operators {{{ */
36cd3cb9 1067AssignmentExpression
cf7d4c69 1068 : ConditionalExpression { $$ = $1; }
4b2fd91c 1069 | ArrowFunction { $$ = $1; }
005a0939
JF
1070 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1071 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1072 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1073 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1074 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1075 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1076 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1077 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1078 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1079 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1080 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1081 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
693d501b 1082 ;
63cd45c9
JF
1083/* }}} */
1084/* 11.14 Comma Operator {{{ */
55fc1817 1085Expression
b0385401
JF
1086 : AssignmentExpression { $$ = $1; }
1087 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
693d501b
JF
1088 ;
1089
36cd3cb9 1090ExpressionOpt
cf7d4c69 1091 : Expression { $$ = $1; }
691e4717 1092 | LexSetRegExp { $$ = NULL; }
1dbba6cc 1093 ;
63cd45c9 1094/* }}} */
693d501b 1095
63cd45c9 1096/* 12 Statements {{{ */
3ea7eed0 1097Statement__
36cd3cb9
JF
1098 : Block { $$ = $1; }
1099 | VariableStatement { $$ = $1; }
1100 | EmptyStatement { $$ = $1; }
cf7d4c69 1101 | IfStatement { $$ = $1; }
c8a0500b 1102 | BreakableStatement { $$ = $1; }
36cd3cb9
JF
1103 | ContinueStatement { $$ = $1; }
1104 | BreakStatement { $$ = $1; }
1105 | ReturnStatement { $$ = $1; }
cf7d4c69
JF
1106 | WithStatement { $$ = $1; }
1107 | LabelledStatement { $$ = $1; }
36cd3cb9
JF
1108 | ThrowStatement { $$ = $1; }
1109 | TryStatement { $$ = $1; }
c8a0500b 1110 | DebuggerStatement { $$ = $1; }
1dbba6cc 1111 ;
b10bd496 1112
3ea7eed0
JF
1113Statement_
1114 : LexSetRegExp Statement__ { $$ = $2; }
1115 | ExpressionStatement { $$ = $1; }
1116 ;
1117
b10bd496 1118Statement
3ea7eed0 1119 : LexSetStatement Statement_ { $$ = $2; }
b10bd496 1120 ;
c8a0500b 1121
3ea7eed0 1122Declaration__
c8a0500b
JF
1123 : FunctionDeclaration { $$ = $1; }
1124 | LexicalDeclaration { $$ = $1; }
1125 ;
1126
3ea7eed0
JF
1127Declaration_
1128 : LexSetRegExp Declaration__ { $$ = $2; }
1129 ;
1130
1131Declaration
1132 : LexSetStatement Declaration_ { $$ = $2; }
1133 ;
1134
c8a0500b
JF
1135BreakableStatement
1136 : IterationStatement { $$ = $1; }
1137 | SwitchStatement { $$ = $1; }
1138 ;
63cd45c9
JF
1139/* }}} */
1140/* 12.1 Block {{{ */
cac61857 1141Block_
3ea7eed0 1142 : BRACE StatementListOpt "}" { $$ = $2; }
cac61857
JF
1143 ;
1144
36cd3cb9 1145Block
3ea7eed0 1146 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1dbba6cc
JF
1147 ;
1148
693d501b 1149StatementList
c8a0500b 1150 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
693d501b
JF
1151 ;
1152
1153StatementListOpt
1154 : StatementList { $$ = $1; }
5d660bed 1155 | LexSetStatement LexSetRegExp { $$ = NULL; }
1dbba6cc 1156 ;
c8a0500b
JF
1157
1158StatementListItem
1159 : Statement { $$ = $1; }
3ea7eed0 1160 | Declaration { $$ = $1; }
c8a0500b
JF
1161 ;
1162/* }}} */
c3b144b8 1163
c8a0500b
JF
1164/* 12.2 Declarations {{{ */
1165BindingIdentifier
1166 : Identifier { $$ = $1; }
1167 ;
1168
c2529502
JF
1169Binding
1170 : BindingIdentifier
1171 ;
1172
c8a0500b
JF
1173// XXX: BindingPattern
1174/* }}} */
1175/* 12.2.1 Let and Const Declarations {{{ */
1176LexicalDeclaration
1177 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1178 ;
1179
1180LetOrConst
1181 : "let"
1182 | "const"
1183 ;
63cd45c9 1184/* }}} */
c8a0500b 1185/* 12.2.2 Variable Statement {{{ */
36cd3cb9 1186VariableStatement
a87d7060 1187 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1dbba6cc
JF
1188 ;
1189
36cd3cb9 1190VariableDeclarationList_
cf7d4c69
JF
1191 : "," VariableDeclarationList { $$ = $2; }
1192 | { $$ = NULL; }
1dbba6cc
JF
1193 ;
1194
55fc1817
JF
1195VariableDeclarationList
1196 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1197 ;
1198
36cd3cb9 1199VariableDeclaration
c8a0500b
JF
1200 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1201 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1dbba6cc
JF
1202 ;
1203
55fc1817
JF
1204Initialiser
1205 : "=" AssignmentExpression { $$ = $2; }
1206 ;
1207
36cd3cb9 1208InitialiserOpt
cf7d4c69 1209 : Initialiser { $$ = $1; }
36cd3cb9 1210 | { $$ = NULL; }
1dbba6cc 1211 ;
63cd45c9 1212/* }}} */
c8a0500b
JF
1213/* 12.2.4 Destructuring Binding Patterns {{{ */
1214// XXX: *
1215
1216BindingElement
1217 : SingleNameBinding { $$ = $1; }
1218 ;
1219
1220SingleNameBinding
1221 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1222 ;
1223/* }}} */
c3b144b8 1224
63cd45c9 1225/* 12.3 Empty Statement {{{ */
36cd3cb9 1226EmptyStatement
2eb8215d 1227 : ";" { $$ = CYNew CYEmpty(); }
1dbba6cc 1228 ;
63cd45c9
JF
1229/* }}} */
1230/* 12.4 Expression Statement {{{ */
36cd3cb9 1231ExpressionStatement
3ea7eed0 1232 : Expression Terminator { $$ = CYNew CYExpress($1); }
1dbba6cc 1233 ;
63cd45c9
JF
1234/* }}} */
1235/* 12.5 The if Statement {{{ */
36cd3cb9
JF
1236ElseStatementOpt
1237 : "else" Statement { $$ = $2; }
c3c20102 1238 | %prec "if" { $$ = NULL; }
1dbba6cc
JF
1239 ;
1240
36cd3cb9 1241IfStatement
2eb8215d 1242 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1dbba6cc 1243 ;
63cd45c9 1244/* }}} */
1dbba6cc 1245
63cd45c9 1246/* 12.6.1 The do-while Statement {{{ */
d5618df7 1247IterationStatement
2eb8215d 1248 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1dbba6cc 1249 ;
63cd45c9
JF
1250/* }}} */
1251/* 12.6.2 The while Statement {{{ */
d5618df7 1252IterationStatement
2eb8215d 1253 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1dbba6cc 1254 ;
63cd45c9
JF
1255/* }}} */
1256/* 12.6.3 The for Statement {{{ */
d5618df7 1257IterationStatement
440424e2 1258 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1dbba6cc
JF
1259 ;
1260
36cd3cb9 1261ForStatementInitialiser
3ea7eed0 1262 : ExpressionOpt { $$ = $1; }
a87d7060 1263 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1dbba6cc 1264 ;
63cd45c9 1265/* }}} */
0d56ef32 1266/* 12.6.4 The for-in and for-of Statements {{{ */
d5618df7 1267IterationStatement
440424e2
JF
1268 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1269 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1dbba6cc
JF
1270 ;
1271
36cd3cb9
JF
1272ForInStatementInitialiser
1273 : LeftHandSideExpression { $$ = $1; }
a87d7060 1274 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1dbba6cc 1275 ;
63cd45c9 1276/* }}} */
1dbba6cc 1277
63cd45c9 1278/* 12.7 The continue Statement {{{ */
a5662a53
JF
1279Continue
1280 : "continue" LexNoNewLine
1281 ;
1282
36cd3cb9 1283ContinueStatement
a5662a53
JF
1284 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1285 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1dbba6cc 1286 ;
63cd45c9
JF
1287/* }}} */
1288/* 12.8 The break Statement {{{ */
a5662a53
JF
1289Break
1290 : "break" LexNoNewLine
1291 ;
1292
36cd3cb9 1293BreakStatement
a5662a53
JF
1294 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1295 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1dbba6cc 1296 ;
63cd45c9
JF
1297/* }}} */
1298/* 12.9 The return Statement {{{ */
a5662a53
JF
1299Return
1300 : "return" LexNoNewLine
1301 ;
1302
36cd3cb9 1303ReturnStatement
a5662a53
JF
1304 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1305 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1dbba6cc 1306 ;
63cd45c9
JF
1307/* }}} */
1308/* 12.10 The with Statement {{{ */
36cd3cb9 1309WithStatement
2eb8215d 1310 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1dbba6cc 1311 ;
63cd45c9 1312/* }}} */
1dbba6cc 1313
63cd45c9 1314/* 12.11 The switch Statement {{{ */
36cd3cb9 1315SwitchStatement
2eb8215d 1316 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1dbba6cc
JF
1317 ;
1318
1319CaseBlock
3ea7eed0 1320 : BRACE CaseClausesOpt "}" { $$ = $2; }
1dbba6cc
JF
1321 ;
1322
55fc1817
JF
1323CaseClause
1324 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1325 ;
1326
36cd3cb9 1327CaseClausesOpt
cf7d4c69
JF
1328 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1329 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1330 | { $$ = NULL; }
1dbba6cc
JF
1331 ;
1332
36cd3cb9 1333DefaultClause
2eb8215d 1334 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1dbba6cc 1335 ;
63cd45c9
JF
1336/* }}} */
1337/* 12.12 Labelled Statements {{{ */
36cd3cb9 1338LabelledStatement
2eb8215d 1339 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1dbba6cc 1340 ;
63cd45c9
JF
1341/* }}} */
1342/* 12.13 The throw Statement {{{ */
a5662a53
JF
1343ThrowWord
1344 : "throw" LexNoNewLine
1345 ;
1346
36cd3cb9 1347ThrowStatement
a5662a53
JF
1348 : ThrowWord LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1349 | ThrowWord Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1dbba6cc 1350 ;
63cd45c9
JF
1351/* }}} */
1352/* 12.14 The try Statement {{{ */
36cd3cb9 1353TryStatement
2eb8215d 1354 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1dbba6cc
JF
1355 ;
1356
1357CatchOpt
2eb8215d 1358 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
cf7d4c69 1359 | { $$ = NULL; }
1dbba6cc
JF
1360 ;
1361
1362FinallyOpt
2eb8215d 1363 : "finally" Block_ { $$ = CYNew CYFinally($2); }
cf7d4c69 1364 | { $$ = NULL; }
1dbba6cc 1365 ;
63cd45c9 1366/* }}} */
c8a0500b
JF
1367/* 12.14 The debugger Statement {{{ */
1368DebuggerStatement
1369 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1370 ;
1371/* }}} */
1dbba6cc 1372
4b2fd91c 1373/* 13.1 Function Definitions {{{ */
36cd3cb9 1374FunctionDeclaration
3ea7eed0 1375 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1dbba6cc
JF
1376 ;
1377
36cd3cb9 1378FunctionExpression
440424e2 1379 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1dbba6cc
JF
1380 ;
1381
1382FormalParameterList_
36cd3cb9 1383 : "," FormalParameterList { $$ = $2; }
cf7d4c69 1384 | { $$ = NULL; }
1dbba6cc
JF
1385 ;
1386
c8a0500b
JF
1387FormalParameterList
1388 // XXX: : FunctionRestParameter { $$ = $1; }
1389 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1390 ;
1391
55fc1817
JF
1392FormalParameterListOpt
1393 : FormalParameterList
1394 | { $$ = NULL; }
1395 ;
1396
c8a0500b
JF
1397/* XXX: FunctionRestParameter
1398 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1399 ;*/
1400
1401FormalParameter
1402 : BindingElement { $$ = $1; }
1403 ;
1404
36cd3cb9 1405FunctionBody
c8a0500b 1406 : StatementListOpt { $$ = $1; }
1dbba6cc 1407 ;
63cd45c9 1408/* }}} */
4b2fd91c
JF
1409/* 13.2 Arrow Function Definitions {{{ */
1410ArrowFunction
a0be43fc 1411 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
4b2fd91c
JF
1412 ;
1413
1414ArrowParameters
1415 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
0afc9ba3 1416 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
b0385401 1417 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
4b2fd91c
JF
1418 ;
1419
1420ConciseBody
1421 : AssignmentExpression { $$ = CYNew CYReturn($1); }
440424e2 1422 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
4b2fd91c
JF
1423 ;
1424/* }}} */
63cd45c9 1425/* 14 Program {{{ */
1dbba6cc 1426Program
c8a0500b 1427 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1dbba6cc
JF
1428 ;
1429
55fc1817
JF
1430ProgramBody
1431 : StatementList { $$ = $1; }
1432 ;
1433
c8a0500b
JF
1434ProgramBodyOpt
1435 : ProgramBody { $$ = $1; }
5d660bed 1436 | LexSetStatement LexSetRegExp { $$ = NULL; }
1dbba6cc 1437 ;
63cd45c9 1438/* }}} */
e5332278 1439
7b750785
JF
1440@begin C
1441/* Cycript (C): Type Encoding {{{ */
663c538f 1442TypeSignifier
00b4cb83
JF
1443 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1444 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
663c538f
JF
1445 ;
1446
46f4f308 1447SuffixedType
00b4cb83 1448 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
3fe16be7 1449 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
00b4cb83
JF
1450 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1451 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1452 | TypeSignifier { $$ = $1; }
1453 | { $$ = CYNew CYTypedIdentifier(@$); }
46f4f308
JF
1454 ;
1455
1456PrefixedType
9a39f705 1457 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
46f4f308
JF
1458 ;
1459
663c538f 1460TypeQualifierLeft
3fe283c5
JF
1461 : { $$ = NULL; }
1462 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1463 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
663c538f
JF
1464 ;
1465
1466TypeQualifierRight
3fe283c5 1467 : PrefixedType { $$ = $1; }
9a39f705 1468 | SuffixedType { $$ = $1; }
3fe283c5
JF
1469 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1470 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1471 ;
1472
1473IntegerType
1474 : "int" { $$ = CYNew CYTypeVariable("int"); }
1475 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1476 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1477 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1478 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1479 ;
1480
1481IntegerTypeOpt
1482 : IntegerType { $$ = $1; }
22e0b32a 1483 | { $$ = CYNew CYTypeVariable("int"); }
56e02e5b
JF
1484 ;
1485
663c538f 1486PrimitiveType
3fe283c5
JF
1487 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1488 | IntegerType { $$ = $1; }
1489 | "void" { $$ = CYNew CYTypeVoid(); }
1490 | "char" { $$ = CYNew CYTypeVariable("char"); }
1491 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1492 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
46f4f308
JF
1493 ;
1494
1495TypedIdentifier
3fe283c5 1496 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
561e7f1c
JF
1497 ;
1498
46f4f308 1499PrimaryExpression
57d55714 1500 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
46f4f308
JF
1501 ;
1502/* }}} */
7b750785
JF
1503@end
1504
1505@begin ObjectiveC
4de0686f 1506/* Cycript (Objective-C): @class Declaration {{{ */
b09da87b 1507ClassSuperOpt
3ea7eed0
JF
1508 /* XXX: why the hell did I choose MemberExpression? */
1509 : ":" LexSetRegExp MemberExpression { $$ = $3; }
b09da87b
JF
1510 | { $$ = NULL; }
1511 ;
1512
cfd73c6d 1513ClassFieldListOpt
b6a67580 1514 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
70234143 1515 | LexSetRegExp { $$ = NULL; }
55fc1817
JF
1516 ;
1517
cfd73c6d
JF
1518ClassFields
1519 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1ba6903e
JF
1520 ;
1521
b09da87b
JF
1522MessageScope
1523 : "+" { $$ = false; }
1524 | "-" { $$ = true; }
1525 ;
1526
1527TypeOpt
104cc5f5
JF
1528 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1529 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
b09da87b
JF
1530 ;
1531
1532MessageParameter
104cc5f5 1533 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
b09da87b
JF
1534 ;
1535
55fc1817
JF
1536MessageParameterList
1537 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1538 ;
1539
b09da87b
JF
1540MessageParameterListOpt
1541 : MessageParameterList { $$ = $1; }
1542 | { $$ = NULL; }
1543 ;
1544
b09da87b
JF
1545MessageParameters
1546 : MessageParameterList { $$ = $1; }
104cc5f5 1547 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
b09da87b
JF
1548 ;
1549
1550ClassMessageDeclaration
3ea7eed0 1551 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
b09da87b
JF
1552 ;
1553
1554ClassMessageDeclarationListOpt
4e8c99fb 1555 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1ba6903e 1556 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
b09da87b
JF
1557 | { $$ = NULL; }
1558 ;
1559
e5bc40db
JF
1560ClassName
1561 : Identifier { $$ = $1; }
1562 | "(" AssignmentExpression ")" { $$ = $2; }
1563 ;
1564
367eebb1
JF
1565ClassNameOpt
1566 : ClassName { $$ = $1; }
1567 | { $$ = NULL; }
b09da87b
JF
1568 ;
1569
64b8d29f
JF
1570// XXX: this should be AssignmentExpressionNoRight
1571ClassProtocols
2eb8215d 1572 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
64b8d29f
JF
1573 ;
1574
1575ClassProtocolsOpt
1576 : "," ClassProtocols { $$ = $2; }
1577 | { $$ = NULL; }
1578 ;
1579
1580ClassProtocolListOpt
1581 : "<" ClassProtocols ">" { $$ = $2; }
1582 | { $$ = NULL; }
1583 ;
1584
fb98ac0c 1585ClassExpression
440424e2 1586 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
fb98ac0c
JF
1587 ;
1588
1589ClassStatement
cfd73c6d 1590 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1ba6903e
JF
1591 ;
1592
1593CategoryName
a630a9eb 1594 : "(" WordOpt ")"
367eebb1
JF
1595 ;
1596
1597CategoryStatement
3ea7eed0 1598 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
367eebb1
JF
1599 ;
1600
3ea7eed0 1601PrimaryExpression
fb98ac0c 1602 : ClassExpression { $$ = $1; }
367eebb1
JF
1603 ;
1604
3ea7eed0 1605Statement__
fb98ac0c 1606 : ClassStatement { $$ = $1; }
365abb0a 1607 | CategoryStatement { $$ = $1; }
b09da87b 1608 ;
cac61857 1609/* }}} */
4de0686f 1610/* Cycript (Objective-C): Send Message {{{ */
693d501b 1611VariadicCall
2eb8215d 1612 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
693d501b
JF
1613 | { $$ = NULL; }
1614 ;
1615
7e5391fd
JF
1616SelectorWordOpt
1617 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1618 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1619 ;
1620
55fc1817
JF
1621SelectorCall_
1622 : SelectorCall { $$ = $1; }
1623 | VariadicCall { $$ = $1; }
1624 ;
1625
693d501b 1626SelectorCall
02447eaf 1627 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
693d501b
JF
1628 ;
1629
1630SelectorList
1631 : SelectorCall { $$ = $1; }
2eb8215d 1632 | Word { $$ = CYNew CYArgument($1, NULL); }
693d501b
JF
1633 ;
1634
1635MessageExpression
440424e2
JF
1636 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1637 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
693d501b
JF
1638 ;
1639
e7ed5354 1640SelectorExpression_
2eb8215d 1641 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
e7ed5354
JF
1642 ;
1643
1644SelectorExpression
1645 : SelectorExpression_ { $$ = $1; }
2eb8215d 1646 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
e7ed5354
JF
1647 ;
1648
55fc1817
JF
1649SelectorExpressionOpt
1650 : SelectorExpression_ { $$ = $1; }
1651 | { $$ = NULL; }
1652 ;
1653
3ea7eed0 1654PrimaryExpression
693d501b 1655 : MessageExpression { $$ = $1; }
440424e2 1656 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
693d501b
JF
1657 ;
1658/* }}} */
7b750785
JF
1659@end
1660
1661/* Cycript: @import Directive {{{ */
417dcc12
JF
1662Module
1663 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1664 | Word { $$ = CYNew CYModule($1); }
1ba6903e
JF
1665 ;
1666
417dcc12
JF
1667Declaration__
1668 : "@import" Module { $$ = CYNew CYImport($2); }
1ba6903e
JF
1669 ;
1670/* }}} */
7b750785
JF
1671
1672@begin ObjectiveC
c3b144b8
JF
1673/* Cycript (Objective-C): Boxed Expressions {{{ */
1674BoxableExpression
1675 : NullLiteral { $$ = $1; }
1676 | BooleanLiteral { $$ = $1; }
1677 | NumericLiteral { $$ = $1; }
1678 | StringLiteral { $$ = $1; }
1679 | ArrayLiteral { $$ = $1; }
1680 | ObjectLiteral { $$ = $1; }
1681 | Parenthetical { $$ = $1; }
60496dd5
JF
1682 | "YES" { $$ = CYNew CYTrue(); }
1683 | "NO" { $$ = CYNew CYFalse(); }
c3b144b8
JF
1684 ;
1685
1686PrimaryExpression
1687 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
4ea461c0
JF
1688 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1689 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1690 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1691 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1692 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
c3b144b8
JF
1693 ;
1694/* }}} */
56e02e5b 1695/* Cycript (Objective-C): Block Expressions {{{ */
56e02e5b 1696PrimaryExpression
00b4cb83 1697 : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
56e02e5b
JF
1698 ;
1699/* }}} */
61769f4f
JF
1700/* Cycript (Objective-C): Instance Literals {{{ */
1701PrimaryExpression
ac9d4181 1702 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
61769f4f
JF
1703 ;
1704/* }}} */
4de0686f
JF
1705@end
1706
1707@begin C
1708/* Cycript (C): Pointer Indirection/Addressing {{{ */
9465b86d
JF
1709LeftHandSideExpression
1710 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
693d501b
JF
1711 ;
1712
1713UnaryExpression_
2eb8215d 1714 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
693d501b
JF
1715 ;
1716
9b5527f0 1717MemberAccess
2eb8215d 1718 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
5ccfc586 1719 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
7e5391fd 1720 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
9b5527f0 1721 ;
cac61857 1722/* }}} */
a87d7060
JF
1723/* Cycript (C): auto Compatibility {{{ */
1724Var_
1725 : "auto"
1726 ;
1727/* }}} */
690cf1a8
JF
1728/* Cycript (C): Lambda Expressions {{{ */
1729TypedParameterList_
1730 : "," TypedParameterList { $$ = $2; }
1731 | { $$ = NULL; }
1732 ;
1733
1734TypedParameterList
1735 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1736 ;
1737
1738TypedParameterListOpt
1739 : TypedParameterList { $$ = $1; }
1740 | { $$ = NULL; }
1741 ;
1742
1743PrimaryExpression
9a39f705 1744 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
690cf1a8
JF
1745 ;
1746/* }}} */
60097023
JF
1747/* Cycript (C): Type Definitions {{{ */
1748Statement__
00b4cb83 1749 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
60097023
JF
1750 ;
1751/* }}} */
c5587ed7
JF
1752/* Cycript (C): extern "C" {{{ */
1753Statement__
44fc505c 1754 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
c5587ed7
JF
1755 ;
1756/* }}} */
1757
4de0686f
JF
1758@end
1759
320ce753 1760/* YUI: Documentation Comments {{{ */
3ea7eed0 1761Statement__
320ce753
JF
1762 : Comment { $$ = $1; }
1763 ;
1764/* }}} */
1765
cb02f8ae 1766@begin E4X
691e4717
JF
1767/* Lexer State {{{ */
1768LexPushRegExp
1769 : { driver.PushCondition(CYDriver::RegExpCondition); }
1770 ;
1771
1772LexPushXMLContent
1773 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1774 ;
1775
1776LexPushXMLTag
1777 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1778 ;
1779
1780LexPop
1781 : { driver.PopCondition(); }
1782 ;
1783
1784LexSetXMLContent
1785 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1786 ;
1787
1788LexSetXMLTag
1789 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1790 ;
1791/* }}} */
c3b144b8 1792/* Virtual Tokens {{{ */
691e4717
JF
1793XMLWhitespaceOpt
1794 : XMLWhitespace
1795 |
1796 ;
c3b144b8 1797/* }}} */
691e4717
JF
1798
1799/* 8.1 Context Keywords {{{ */
1800Identifier
d6e7cafb
JF
1801 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1802 | "xml" { $$ = CYNew CYIdentifier("xml"); }
691e4717
JF
1803 ;
1804/* }}} */
cb02f8ae
JF
1805/* 8.3 XML Initialiser Input Elements {{{ */
1806XMLMarkup
691e4717
JF
1807 : XMLComment { $$ = $1; }
1808 | XMLCDATA { $$ = $1; }
1809 | XMLPI { $$ = $1; }
cb02f8ae
JF
1810 ;
1811/* }}} */
c3b144b8 1812
cb02f8ae 1813/* 11.1 Primary Expressions {{{ */
3ea7eed0 1814PrimaryExpression
2eb8215d 1815 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
691e4717
JF
1816 | XMLInitialiser { $$ = $1; }
1817 | XMLListInitialiser { $$ = $1; }
cb02f8ae
JF
1818 ;
1819
1820PropertyIdentifier
691e4717
JF
1821 : AttributeIdentifier { $$ = $1; }
1822 | QualifiedIdentifier { $$ = $1; }
1823 | WildcardIdentifier { $$ = $1; }
cb02f8ae
JF
1824 ;
1825/* }}} */
1826/* 11.1.1 Attribute Identifiers {{{ */
1827AttributeIdentifier
2eb8215d 1828 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
691e4717
JF
1829 ;
1830
1831PropertySelector_
b92ceddb 1832 : PropertySelector { $$ = $1; }
440424e2 1833 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
cb02f8ae
JF
1834 ;
1835
1836PropertySelector
2eb8215d 1837 : Identifier { $$ = CYNew CYSelector($1); }
691e4717 1838 | WildcardIdentifier { $$ = $1; }
cb02f8ae
JF
1839 ;
1840/* }}} */
1841/* 11.1.2 Qualified Identifiers {{{ */
691e4717 1842QualifiedIdentifier_
2eb8215d 1843 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
691e4717
JF
1844 | QualifiedIdentifier { $$ = $1; }
1845 ;
1846
cb02f8ae 1847QualifiedIdentifier
2eb8215d 1848 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
cb02f8ae
JF
1849 ;
1850/* }}} */
1851/* 11.1.3 Wildcard Identifiers {{{ */
1852WildcardIdentifier
2eb8215d 1853 : "*" { $$ = CYNew CYWildcard(); }
cb02f8ae
JF
1854 ;
1855/* }}} */
1856/* 11.1.4 XML Initialiser {{{ */
1857XMLInitialiser
691e4717
JF
1858 : XMLMarkup { $$ = $1; }
1859 | XMLElement { $$ = $1; }
cb02f8ae
JF
1860 ;
1861
1862XMLElement
440424e2
JF
1863 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1864 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
cb02f8ae
JF
1865 ;
1866
1867XMLTagContent
0347fadf 1868 : LexPushXMLTag XMLTagName XMLAttributes
cb02f8ae
JF
1869 ;
1870
691e4717 1871XMLExpression
3ea7eed0 1872 : BRACE LexPushRegExp Expression LexPop "}"
691e4717
JF
1873 ;
1874
cb02f8ae 1875XMLTagName
691e4717 1876 : XMLExpression
cb02f8ae
JF
1877 | XMLName
1878 ;
1879
0347fadf
JF
1880XMLAttributes_
1881 : XMLAttributes_ XMLAttribute
1882 |
cb02f8ae
JF
1883 ;
1884
0347fadf
JF
1885XMLAttributes
1886 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1887 | XMLAttributes_ XMLWhitespaceOpt
cb02f8ae
JF
1888 ;
1889
691e4717
JF
1890XMLAttributeValue_
1891 : XMLExpression
1892 | XMLAttributeValue
1893 ;
1894
cb02f8ae 1895XMLAttribute
691e4717 1896 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
cb02f8ae
JF
1897 ;
1898
cb02f8ae 1899XMLElementContent
691e4717 1900 : XMLExpression XMLElementContentOpt
cb02f8ae
JF
1901 | XMLMarkup XMLElementContentOpt
1902 | XMLText XMLElementContentOpt
1903 | XMLElement XMLElementContentOpt
1904 ;
1905
1906XMLElementContentOpt
1907 : XMLElementContent
1908 |
1909 ;
1910/* }}} */
1911/* 11.1.5 XMLList Initialiser {{{ */
1912XMLListInitialiser
440424e2 1913 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
691e4717
JF
1914 ;
1915/* }}} */
c3b144b8 1916
691e4717
JF
1917/* 11.2 Left-Hand-Side Expressions {{{ */
1918PropertyIdentifier_
0347fadf 1919 : Identifier { $$ = $1; }
691e4717
JF
1920 | PropertyIdentifier { $$ = $1; }
1921 ;
1922
1923MemberAccess
2eb8215d
JF
1924 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1925 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1926 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
691e4717
JF
1927 ;
1928/* }}} */
1929/* 12.1 The default xml namespace Statement {{{ */
b92ceddb 1930/* XXX: DefaultXMLNamespaceStatement
2eb8215d 1931 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
691e4717
JF
1932 ;
1933
3ea7eed0 1934Statement__
691e4717 1935 : DefaultXMLNamespaceStatement { $$ = $1; }
b92ceddb 1936 ; */
cb02f8ae
JF
1937/* }}} */
1938@end
1939
cac61857 1940/* JavaScript 1.7: Array Comprehensions {{{ */
b3aa25d8
JF
1941Comprehension
1942 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
367eebb1
JF
1943 ;
1944
b3aa25d8
JF
1945ComprehensionFor
1946 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1947 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
367eebb1 1948 ;
cac61857
JF
1949/* }}} */
1950/* JavaScript 1.7: for each {{{ */
d5618df7 1951IterationStatement
440424e2 1952 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
cac61857
JF
1953 ;
1954/* }}} */
15b88a33 1955/* JavaScript 1.7: let Statements {{{ */
cac61857 1956LetStatement
c8a0500b 1957 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
cac61857
JF
1958 ;
1959
3ea7eed0 1960Statement__
cac61857
JF
1961 : LetStatement
1962 ;
15b88a33 1963/* }}} */
4e11a430 1964
6c093cce
JF
1965/* JavaScript FTW: Ruby Blocks {{{ */
1966RubyProcParameterList_
1967 : "," RubyProcParameterList { $$ = $2; }
1968 | { $$ = NULL; }
1969 ;
1970
1971RubyProcParameterList
c8a0500b 1972 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
6c093cce
JF
1973 | { $$ = NULL; }
1974 ;
1975
d7205a63 1976RubyProcParameters
6c093cce 1977 : "|" RubyProcParameterList "|" { $$ = $2; }
d7205a63
JF
1978 | "||" { $$ = NULL; }
1979 ;
1980
1981RubyProcParametersOpt
1982 : RubyProcParameters
6c093cce
JF
1983 | { $$ = NULL; }
1984 ;
1985
1986RubyProcExpression
2eb8215d 1987 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
6c093cce
JF
1988 ;
1989
3ea7eed0 1990PrimaryExpression
440424e2 1991 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
6c093cce
JF
1992 ;
1993
3ea7eed0
JF
1994CallExpression
1995 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
6c093cce 1996 ;
6c093cce 1997/* }}} */
367eebb1 1998
e5332278 1999%%