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