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