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