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