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