1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
24 @if Bison24 %code top {
25 #define cyscanner driver.scanner_
26 #define YYSTACKEXPANDABLE 1
27 @if Bison23 #define yyerrok (yyerrstatus_ = 0)
30 @if Bison24 %code requires {
32 #define CYNew new($pool)
35 #include "ObjectiveC/Syntax.hpp"
39 #include "E4X/Syntax.hpp"
48 CYDriver::Condition condition_;
50 CYArgument *argument_;
51 CYAssignment *assignment_;
54 cy::Syntax::Catch *catch_;
56 CYComprehension *comprehension_;
57 CYCompound *compound_;
58 CYDeclaration *declaration_;
59 CYDeclarations *declarations_;
61 CYExpression *expression_;
64 CYForInitialiser *for_;
65 CYForInInitialiser *forin_;
66 CYFunctionParameter *functionParameter_;
67 CYIdentifier *identifier_;
74 CYProperty *property_;
75 CYPropertyName *propertyName_;
76 CYRubyProc *rubyProc_;
77 CYStatement *statement_;
84 CYClassName *className_;
87 CYMessageParameter *messageParameter_;
88 CYProtocol *protocol_;
89 CYSelectorPart *selector_;
93 CYAttribute *attribute_;
94 CYPropertyIdentifier *propertyIdentifier_;
95 CYSelector *selector_;
100 #define YYSTYPE YYSTYPE
103 @if Bison24 %code provides {
104 int cylex(YYSTYPE *, cy::location *, void *);
111 @if Bison23 %skeleton "lalr1.cc"
112 @if Bison24 %language "C++"
115 @$.begin.filename = @$.end.filename = &driver.filename_;
126 %parse-param { CYDriver &driver }
127 %lex-param { void *cyscanner }
134 %token XMLAttributeValue
136 %token XMLTagCharacters
142 %token LeftRight "<>"
143 %token LeftSlashRight "</>"
145 %token SlashRight "/>"
146 %token LeftSlash "</"
148 %token ColonColon "::"
149 %token PeriodPeriod ".."
152 @begin E4X ObjectiveC
157 %token AmpersandAmpersand "&&"
158 %token AmpersandEqual "&="
160 %token CarrotEqual "^="
162 %token EqualEqual "=="
163 %token EqualEqualEqual "==="
164 %token Exclamation "!"
165 %token ExclamationEqual "!="
166 %token ExclamationEqualEqual "!=="
168 %token HyphenEqual "-="
169 %token HyphenHyphen "--"
170 %token HyphenHyphen_ "\n--"
171 %token HyphenRight "->"
173 %token LeftEqual "<="
175 %token LeftLeftEqual "<<="
177 %token PercentEqual "%="
179 %token PeriodPeriodPeriod "..."
181 %token PipeEqual "|="
184 %token PlusEqual "+="
186 %token PlusPlus_ "\n++"
188 %token RightEqual ">="
189 %token RightRight ">>"
190 %token RightRightEqual ">>="
191 %token RightRightRight ">>>"
192 %token RightRightRightEqual ">>>="
194 %token SlashEqual "/="
196 %token StarEqual "*="
205 %token <comment_> Comment
208 %token CloseParen ")"
211 %token OpenBrace_ "\n{"
212 %token OpenBrace__ ";{"
213 %token CloseBrace "}"
215 %token OpenBracket "["
216 %token CloseBracket "]"
219 %token AtClass "@class"
223 %token AtImplementation "@implementation"
224 %token AtImplementation_ ";@implementation"
225 %token AtImport "@import"
227 %token AtSelector "@selector"
230 %token <false_> False "false"
231 %token <null_> Null "null"
232 %token <true_> True "true"
234 // ES3/ES5/WIE/JSC Reserved
235 %token <word_> Break "break"
236 %token <word_> Case "case"
237 %token <word_> Catch "catch"
238 %token <word_> Continue "continue"
239 %token <word_> Default "default"
240 %token <word_> Delete "delete"
241 %token <word_> Do "do"
242 %token <word_> Else "else"
243 %token <word_> Finally "finally"
244 %token <word_> For "for"
245 %token <word_> Function "function"
246 %token <word_> Function_ ";function"
247 %token <word_> If "if"
248 %token <word_> In "in"
249 %token <word_> In_ "!in"
250 %token <word_> InstanceOf "instanceof"
251 %token <word_> New "new"
252 %token <word_> Return "return"
253 %token <word_> Switch "switch"
254 %token <this_> This "this"
255 %token <word_> Throw "throw"
256 %token <word_> Try "try"
257 %token <word_> TypeOf "typeof"
258 %token <word_> Var "var"
259 %token <word_> Void "void"
260 %token <word_> While "while"
261 %token <word_> With "with"
263 // ES3/IE6 Future, ES5/JSC Reserved
264 %token <word_> Debugger "debugger"
266 // ES3/ES5/IE6 Future, JSC Reserved
267 %token <word_> Const "const"
269 // ES3/ES5/IE6/JSC Future
270 %token <word_> Class "class"
271 %token <word_> Enum "enum"
272 %token <word_> Export "export"
273 %token <word_> Extends "extends"
274 %token <word_> Import "import"
275 %token <word_> Super "super"
277 // ES3 Future, ES5 Strict Future
278 %token <identifier_> Implements "implements"
279 %token <identifier_> Interface "interface"
280 %token <identifier_> Package "package"
281 %token <identifier_> Private "private"
282 %token <identifier_> Protected "protected"
283 %token <identifier_> Public "public"
284 %token <identifier_> Static "static"
287 %token <identifier_> Abstract "abstract"
288 %token <identifier_> Boolean "boolean"
289 %token <identifier_> Byte "byte"
290 %token <identifier_> Char "char"
291 %token <identifier_> Double "double"
292 %token <identifier_> Final "final"
293 %token <identifier_> Float "float"
294 %token <identifier_> Goto "goto"
295 %token <identifier_> Int "int"
296 %token <identifier_> Long "long"
297 %token <identifier_> Native "native"
298 %token <identifier_> Short "short"
299 %token <identifier_> Synchronized "synchronized"
300 %token <identifier_> Throws "throws"
301 %token <identifier_> Transient "transient"
302 %token <identifier_> Volatile "volatile"
305 %token <identifier_> Let "let"
306 %token <identifier_> Yield "yield"
309 %token <identifier_> Each "each"
313 %token <identifier_> Namespace "namespace"
314 %token <identifier_> XML "xml"
319 %token <identifier_> Identifier_
320 %token <number_> NumericLiteral
321 %token <string_> StringLiteral
322 %token <literal_> RegularExpressionLiteral
324 %type <expression_> AdditiveExpression
325 %type <argument_> ArgumentList_
326 %type <argument_> ArgumentList
327 %type <argument_> ArgumentListOpt
328 %type <argument_> Arguments
329 %type <literal_> ArrayLiteral
330 %type <assignment_> AssignmentExpression_
331 %type <expression_> AssignmentExpression
332 %type <identifier_> BindingIdentifier
333 %type <expression_> BitwiseANDExpression
334 %type <statement_> Block_
335 %type <statement_> Block
336 %type <boolean_> BooleanLiteral
337 %type <declaration_> BindingElement
338 %type <expression_> BitwiseORExpression
339 %type <expression_> BitwiseXORExpression
340 %type <statement_> BreakStatement
341 %type <statement_> BreakableStatement
342 %type <expression_> CallExpression_
343 %type <expression_> CallExpression
344 %type <clause_> CaseBlock
345 %type <clause_> CaseClause
346 %type <clause_> CaseClausesOpt
347 %type <catch_> CatchOpt
348 %type <comprehension_> ComprehensionList
349 %type <comprehension_> ComprehensionListOpt
350 %type <expression_> ConditionalExpression
351 %type <statement_> ContinueStatement
352 %type <statement_> DebuggerStatement
353 %type <statement_> Declaration__
354 %type <statement_> Declaration_
355 %type <statement_> Declaration
356 %type <clause_> DefaultClause
357 %type <statement_> DoWhileStatement
358 %type <expression_> Element
359 %type <expression_> ElementOpt
360 %type <element_> ElementList
361 %type <element_> ElementListOpt
362 %type <statement_> ElseStatementOpt
363 %type <statement_> EmptyStatement
364 %type <expression_> EqualityExpression
365 %type <compound_> Expression_
366 %type <expression_> Expression
367 %type <expression_> ExpressionOpt
368 %type <statement_> ExpressionStatement
369 %type <finally_> FinallyOpt
370 %type <comprehension_> ForComprehension
371 %type <statement_> ForStatement
372 %type <for_> ForStatementInitialiser
373 %type <statement_> ForInStatement
374 %type <forin_> ForInStatementInitialiser
375 %type <declaration_> FormalParameter
376 %type <functionParameter_> FormalParameterList_
377 %type <functionParameter_> FormalParameterList
378 %type <functionParameter_> FormalParameterListOpt
379 %type <statement_> FunctionBody
380 %type <statement_> FunctionDeclaration
381 %type <expression_> FunctionExpression
382 %type <identifier_> Identifier
383 %type <identifier_> IdentifierOpt
384 %type <comprehension_> IfComprehension
385 %type <statement_> IfStatement
386 %type <expression_> Initialiser
387 %type <expression_> InitialiserOpt
388 %type <statement_> IterationStatement
389 %type <statement_> LabelledStatement
390 %type <expression_> LeftHandSideExpression
391 %type <statement_> LetStatement
392 %type <statement_> LexicalDeclaration
393 %type <literal_> Literal
394 %type <literal_> LiteralNoRE
395 %type <expression_> LogicalANDExpression
396 %type <expression_> LogicalORExpression
397 %type <member_> MemberAccess
398 %type <expression_> MemberExpression_
399 %type <expression_> MemberExpression
400 %type <expression_> MultiplicativeExpression
401 %type <expression_> NewExpression
402 %type <null_> NullLiteral
403 %type <literal_> ObjectLiteral
404 %type <expression_> Parenthetical
405 %type <expression_> PostfixExpression
406 %type <expression_> PrimaryExpression
407 %type <statement_> Program
408 %type <statement_> ProgramBody
409 %type <statement_> ProgramBodyOpt
410 %type <propertyName_> PropertyName_
411 %type <propertyName_> PropertyName
412 %type <property_> PropertyNameAndValueList_
413 %type <property_> PropertyNameAndValueList
414 %type <property_> PropertyNameAndValueListOpt
415 %type <expression_> RelationalExpression_
416 %type <expression_> RelationalExpression
417 %type <statement_> ReturnStatement
418 %type <rubyProc_> RubyProcExpression
419 %type <functionParameter_> RubyProcParameterList_
420 %type <functionParameter_> RubyProcParameterList
421 %type <functionParameter_> RubyProcParameters
422 %type <functionParameter_> RubyProcParametersOpt
423 %type <expression_> ShiftExpression
424 %type <declaration_> SingleNameBinding
425 %type <statement_> Statement__
426 %type <statement_> Statement_
427 %type <statement_> Statement
428 %type <statement_> StatementList
429 %type <statement_> StatementListOpt
430 %type <statement_> StatementListItem
431 %type <statement_> SwitchStatement
432 %type <statement_> ThrowStatement
433 %type <statement_> TryStatement
434 %type <expression_> UnaryExpression_
435 %type <expression_> UnaryExpression
436 %type <declaration_> VariableDeclaration
437 %type <declarations_> VariableDeclarationList_
438 %type <declarations_> VariableDeclarationList
439 %type <statement_> VariableStatement
440 %type <statement_> WhileStatement
441 %type <statement_> WithStatement
444 %type <statement_> CategoryStatement
445 %type <expression_> ClassExpression
446 %type <statement_> ClassStatement
447 %type <expression_> ClassSuperOpt
448 %type <field_> ClassFieldList
449 %type <message_> ClassMessageDeclaration
450 %type <message_> ClassMessageDeclarationListOpt
451 %type <className_> ClassName
452 %type <className_> ClassNameOpt
453 %type <protocol_> ClassProtocolListOpt
454 %type <protocol_> ClassProtocols
455 %type <protocol_> ClassProtocolsOpt
456 %type <expression_> MessageExpression
457 %type <messageParameter_> MessageParameter
458 %type <messageParameter_> MessageParameters
459 %type <messageParameter_> MessageParameterList
460 %type <messageParameter_> MessageParameterListOpt
461 %type <bool_> MessageScope
462 %type <argument_> SelectorCall_
463 %type <argument_> SelectorCall
464 %type <selector_> SelectorExpression_
465 %type <selector_> SelectorExpression
466 %type <selector_> SelectorExpressionOpt
467 %type <argument_> SelectorList
468 %type <word_> SelectorWordOpt
469 %type <expression_> TypeOpt
470 %type <argument_> VariadicCall
472 %type <word_> WordOpt
476 %type <propertyIdentifier_> PropertyIdentifier_
477 %type <selector_> PropertySelector_
478 %type <selector_> PropertySelector
479 %type <identifier_> QualifiedIdentifier_
480 %type <identifier_> QualifiedIdentifier
481 %type <identifier_> WildcardIdentifier
482 %type <identifier_> XMLComment
483 %type <identifier_> XMLCDATA
484 %type <identifier_> XMLElement
485 %type <identifier_> XMLElementContent
486 %type <identifier_> XMLMarkup
487 %type <identifier_> XMLPI
489 %type <attribute_> AttributeIdentifier
490 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
491 %type <expression_> PropertyIdentifier
492 %type <expression_> XMLListInitialiser
493 %type <expression_> XMLInitialiser
506 /* Lexer State {{{ */
508 : { driver.in_.push(true); }
512 : { driver.in_.push(false); }
516 : { driver.in_.pop(); }
520 : { driver.SetCondition(CYDriver::RegExpCondition); }
524 : { switch (yychar) {
525 case token::Function:
526 yychar = token::Function_;
529 case token::OpenBrace:
530 case token::OpenBrace_:
531 yychar = token::OpenBrace__;
543 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
553 | error { if (yychar != 0 && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
558 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
573 : Identifier { $$ = $1; }
574 | "break" NewLineOpt { $$ = $1; }
575 | "case" { $$ = $1; }
576 | "catch" { $$ = $1; }
577 | "class" { $$ = $1; }
578 | "const" { $$ = $1; }
579 | "continue" NewLineOpt { $$ = $1; }
580 | "debugger" { $$ = $1; }
581 | "default" { $$ = $1; }
582 | "delete" { $$ = $1; }
584 | "else" { $$ = $1; }
585 | "enum" { $$ = $1; }
586 | "export" { $$ = $1; }
587 | "extends" { $$ = $1; }
588 | "false" { $$ = $1; }
589 | "finally" { $$ = $1; }
590 /* XXX: | "for" { $$ = $1; } */
591 | "function" { $$ = $1; }
593 | "import" { $$ = $1; }
594 /* XXX: | "in" { $$ = $1; } */
595 /* XXX: | "instanceof" { $$ = $1; } */
597 | "null" { $$ = $1; }
598 | "return" NewLineOpt { $$ = $1; }
599 | "super" { $$ = $1; }
600 | "switch" { $$ = $1; }
601 | "this" { $$ = $1; }
602 | "throw" NewLineOpt { $$ = $1; }
603 | "true" { $$ = $1; }
605 | "typeof" { $$ = $1; }
607 | "void" { $$ = $1; }
608 | "while" { $$ = $1; }
609 | "with" { $$ = $1; }
618 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
619 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
620 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
621 | "@" Parenthetical { $$ = CYNew CYBox($2); }
626 : Identifier_ { $$ = $1; }
628 | "implements" { $$ = $1; }
629 | "interface" { $$ = $1; }
630 | "package" { $$ = $1; }
631 | "private" { $$ = $1; }
632 | "protected" { $$ = $1; }
633 | "public" { $$ = $1; }
634 | "static" { $$ = $1; }
636 | "abstract" { $$ = $1; }
637 | "boolean" { $$ = $1; }
638 | "byte" { $$ = $1; }
639 | "char" { $$ = $1; }
640 | "double" { $$ = $1; }
641 | "final" { $$ = $1; }
642 | "float" { $$ = $1; }
643 | "goto" { $$ = $1; }
645 | "long" { $$ = $1; }
646 | "native" { $$ = $1; }
647 | "short" { $$ = $1; }
648 | "synchronized" { $$ = $1; }
649 | "throws" { $$ = $1; }
650 | "transient" { $$ = $1; }
651 | "volatile" { $$ = $1; }
653 // XXX: is this allowed?! | "let" { $$ = $1; }
654 | "yield" { $$ = $1; }
656 | "each" { $$ = $1; }
660 : Identifier { $$ = $1; }
665 : NullLiteral { $$ = $1; }
666 | BooleanLiteral { $$ = $1; }
667 | NumericLiteral { $$ = $1; }
668 | StringLiteral { $$ = $1; }
672 : LiteralNoRE { $$ = $1; }
673 | RegularExpressionLiteral { $$ = $1; }
677 : "null" { $$ = $1; }
681 : "true" { $$ = $1; }
682 | "false" { $$ = $1; }
685 /* 11.1 Primary Expressions {{{ */
687 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
691 : "this" { $$ = $1; }
692 | Identifier { $$ = CYNew CYVariable($1); }
693 | Literal { $$ = $1; }
694 | ArrayLiteral { $$ = $1; }
695 | ObjectLiteral { $$ = $1; }
696 | FunctionExpression { $$ = $1; }
697 | Parenthetical { $$ = $1; }
698 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
701 /* 11.1.4.1 Array Initialiser {{{ */
703 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
707 : AssignmentExpression { $$ = $1; }
711 : Element { $$ = $1; }
712 | LexSetRegExp { $$ = NULL; }
716 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
717 | Element { $$ = CYNew CYElement($1, NULL); }
721 : ElementList { $$ = $1; }
722 | LexSetRegExp { $$ = NULL; }
725 /* 11.1.5 Object Initialiser {{{ */
727 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
730 PropertyNameAndValueList_
731 : "," PropertyNameAndValueList { $$ = $2; }
735 PropertyNameAndValueList
736 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
739 PropertyNameAndValueListOpt
740 : PropertyNameAndValueList { $$ = $1; }
745 : Identifier { $$ = $1; }
746 | StringLiteral { $$ = $1; }
747 | NumericLiteral { $$ = $1; }
751 : LexSetRegExp PropertyName_ { $$ = $2; }
755 /* 11.2 Left-Hand-Side Expressions {{{ */
757 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
758 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
759 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
763 : MemberExpression { $$ = $1; }
764 //| "super" { $$ = $1; }
768 : LexSetRegExp PrimaryExpression { $$ = $2; }
769 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
770 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
774 : MemberExpression { $$ = $1; }
775 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
784 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
785 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
789 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
793 : "," ArgumentList { $$ = $2; }
798 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
802 : ArgumentList { $$ = $1; }
803 | LexSetRegExp { $$ = NULL; }
806 LeftHandSideExpression
807 : NewExpression { $$ = $1; }
808 | CallExpression { $$ = $1; }
811 /* 11.3 Postfix Expressions {{{ */
813 : %prec "" LeftHandSideExpression { $$ = $1; }
814 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
815 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
818 /* 11.4 Unary Operators {{{ */
820 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
821 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
822 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
823 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
824 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
825 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
826 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
827 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
828 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
829 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
830 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
834 : PostfixExpression { $$ = $1; }
835 | LexSetRegExp UnaryExpression_ { $$ = $2; }
838 /* 11.5 Multiplicative Operators {{{ */
839 MultiplicativeExpression
840 : UnaryExpression { $$ = $1; }
841 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
842 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
843 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
846 /* 11.6 Additive Operators {{{ */
848 : MultiplicativeExpression { $$ = $1; }
849 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
850 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
853 /* 11.7 Bitwise Shift Operators {{{ */
855 : AdditiveExpression { $$ = $1; }
856 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
857 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
858 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
861 /* 11.8 Relational Operators {{{ */
862 RelationalExpression_
863 : ShiftExpression { $$ = $1; }
867 : RelationalExpression_ { $$ = $1; }
868 | RelationalExpression "<" RelationalExpression_ { $$ = CYNew CYLess($1, $3); }
869 | RelationalExpression ">" RelationalExpression_ { $$ = CYNew CYGreater($1, $3); }
870 | RelationalExpression "<=" RelationalExpression_ { $$ = CYNew CYLessOrEqual($1, $3); }
871 | RelationalExpression ">=" RelationalExpression_ { $$ = CYNew CYGreaterOrEqual($1, $3); }
872 | RelationalExpression "instanceof" RelationalExpression_ { $$ = CYNew CYInstanceOf($1, $3); }
873 | RelationalExpression "in" RelationalExpression_ { $$ = CYNew CYIn($1, $3); }
876 /* 11.9 Equality Operators {{{ */
878 : RelationalExpression { $$ = $1; }
879 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
880 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
881 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
882 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
885 /* 11.10 Binary Bitwise Operators {{{ */
887 : EqualityExpression { $$ = $1; }
888 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
892 : BitwiseANDExpression { $$ = $1; }
893 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
897 : BitwiseXORExpression { $$ = $1; }
898 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
901 /* 11.11 Binary Logical Operators {{{ */
903 : BitwiseORExpression { $$ = $1; }
904 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
908 : LogicalANDExpression { $$ = $1; }
909 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
912 /* 11.12 Conditional Operator ( ? : ) {{{ */
913 ConditionalExpression
914 : LogicalORExpression { $$ = $1; }
915 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
918 /* 11.13 Assignment Operators {{{ */
919 AssignmentExpression_
920 : "=" AssignmentExpression { $$ = CYNew CYAssign(NULL, $2); }
921 | "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign(NULL, $2); }
922 | "/=" AssignmentExpression { $$ = CYNew CYDivideAssign(NULL, $2); }
923 | "%=" AssignmentExpression { $$ = CYNew CYModulusAssign(NULL, $2); }
924 | "+=" AssignmentExpression { $$ = CYNew CYAddAssign(NULL, $2); }
925 | "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign(NULL, $2); }
926 | "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign(NULL, $2); }
927 | ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign(NULL, $2); }
928 | ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign(NULL, $2); }
929 | "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign(NULL, $2); }
930 | "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign(NULL, $2); }
931 | "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign(NULL, $2); }
935 : ConditionalExpression { $$ = $1; }
936 | LeftHandSideExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
939 /* 11.14 Comma Operator {{{ */
941 : "," Expression { $$ = CYNew CYCompound($2); }
946 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
950 : Expression { $$ = $1; }
951 | LexSetRegExp { $$ = NULL; }
955 /* 12 Statements {{{ */
958 | VariableStatement { $$ = $1; }
959 | EmptyStatement { $$ = $1; }
960 | IfStatement { $$ = $1; }
961 | BreakableStatement { $$ = $1; }
962 | ContinueStatement { $$ = $1; }
963 | BreakStatement { $$ = $1; }
964 | ReturnStatement { $$ = $1; }
965 | WithStatement { $$ = $1; }
966 | LabelledStatement { $$ = $1; }
967 | ThrowStatement { $$ = $1; }
968 | TryStatement { $$ = $1; }
969 | DebuggerStatement { $$ = $1; }
973 : LexSetRegExp Statement__ { $$ = $2; }
974 | ExpressionStatement { $$ = $1; }
978 : LexSetStatement Statement_ { $$ = $2; }
982 : FunctionDeclaration { $$ = $1; }
983 | LexicalDeclaration { $$ = $1; }
987 : LexSetRegExp Declaration__ { $$ = $2; }
991 : LexSetStatement Declaration_ { $$ = $2; }
995 : IterationStatement { $$ = $1; }
996 | SwitchStatement { $$ = $1; }
1001 : BRACE StatementListOpt "}" { $$ = $2; }
1005 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1009 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1013 : StatementList { $$ = $1; }
1014 | LexSetRegExp { $$ = NULL; }
1018 : Statement { $$ = $1; }
1019 | Declaration { $$ = $1; }
1022 /* 12.2 Declarations {{{ */
1024 : Identifier { $$ = $1; }
1027 // XXX: BindingPattern
1029 /* 12.2.1 Let and Const Declarations {{{ */
1031 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1039 /* 12.2.2 Variable Statement {{{ */
1041 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1044 VariableDeclarationList_
1045 : "," VariableDeclarationList { $$ = $2; }
1049 VariableDeclarationList
1050 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1054 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1055 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1059 : "=" AssignmentExpression { $$ = $2; }
1063 : Initialiser { $$ = $1; }
1067 /* 12.2.4 Destructuring Binding Patterns {{{ */
1071 : SingleNameBinding { $$ = $1; }
1075 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1078 /* 12.3 Empty Statement {{{ */
1080 : ";" { $$ = CYNew CYEmpty(); }
1083 /* 12.4 Expression Statement {{{ */
1085 : Expression Terminator { $$ = CYNew CYExpress($1); }
1088 /* 12.5 The if Statement {{{ */
1090 : "else" Statement { $$ = $2; }
1091 | %prec "if" { $$ = NULL; }
1095 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1099 /* 12.6 Iteration Statements {{{ */
1101 : DoWhileStatement { $$ = $1; }
1102 | WhileStatement { $$ = $1; }
1103 | ForStatement { $$ = $1; }
1104 | ForInStatement { $$ = $1; }
1107 /* 12.6.1 The do-while Statement {{{ */
1109 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1112 /* 12.6.2 The while Statement {{{ */
1114 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1117 /* 12.6.3 The for Statement {{{ */
1119 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1122 ForStatementInitialiser
1123 : ExpressionOpt { $$ = $1; }
1124 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1127 /* 12.6.4 The for-in Statement {{{ */
1129 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1132 ForInStatementInitialiser
1133 : LeftHandSideExpression { $$ = $1; }
1134 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1138 /* 12.7 The continue Statement {{{ */
1140 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1143 /* 12.8 The break Statement {{{ */
1145 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1148 /* 12.9 The return Statement {{{ */
1150 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1153 /* 12.10 The with Statement {{{ */
1155 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1159 /* 12.11 The switch Statement {{{ */
1161 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1165 : BRACE CaseClausesOpt "}" { $$ = $2; }
1169 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1173 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1174 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1179 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1182 /* 12.12 Labelled Statements {{{ */
1184 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1187 /* 12.13 The throw Statement {{{ */
1189 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1192 /* 12.14 The try Statement {{{ */
1194 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1198 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1203 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1207 /* 12.14 The debugger Statement {{{ */
1209 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1213 /* 13 Function Definition {{{ */
1215 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1219 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1222 FormalParameterList_
1223 : "," FormalParameterList { $$ = $2; }
1228 // XXX: : FunctionRestParameter { $$ = $1; }
1229 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1232 FormalParameterListOpt
1233 : FormalParameterList
1237 /* XXX: FunctionRestParameter
1238 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1242 : BindingElement { $$ = $1; }
1246 : StatementListOpt { $$ = $1; }
1249 /* 14 Program {{{ */
1251 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1255 : StatementList { $$ = $1; }
1259 : ProgramBody { $$ = $1; }
1265 /* Cycript (Objective-C): @class Declaration {{{ */
1267 /* XXX: why the hell did I choose MemberExpression? */
1268 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1273 : Expression Identifier ";"
1277 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1281 : ClassFieldListOpt ClassField
1286 : "+" { $$ = false; }
1287 | "-" { $$ = true; }
1291 : "(" Expression ")" { $$ = $2; }
1292 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1297 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1300 MessageParameterList
1301 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1304 MessageParameterListOpt
1305 : MessageParameterList { $$ = $1; }
1310 : MessageParameterList { $$ = $1; }
1311 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1314 ClassMessageDeclaration
1315 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1318 ClassMessageDeclarationListOpt
1319 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1320 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1325 : Identifier { $$ = $1; }
1326 | "(" AssignmentExpression ")" { $$ = $2; }
1330 : ClassName { $$ = $1; }
1334 // XXX: this should be AssignmentExpressionNoRight
1336 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1340 : "," ClassProtocols { $$ = $2; }
1344 ClassProtocolListOpt
1345 : "<" ClassProtocols ">" { $$ = $2; }
1350 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1354 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1362 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1366 : ClassExpression { $$ = $1; }
1370 : ClassStatement { $$ = $1; }
1371 | CategoryStatement { $$ = $1; }
1374 /* Cycript (Objective-C): Send Message {{{ */
1376 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1381 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1382 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1386 : SelectorCall { $$ = $1; }
1387 | VariadicCall { $$ = $1; }
1391 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1395 : SelectorCall { $$ = $1; }
1396 | Word { $$ = CYNew CYArgument($1, NULL); }
1400 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1401 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1405 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1409 : SelectorExpression_ { $$ = $1; }
1410 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1413 SelectorExpressionOpt
1414 : SelectorExpression_ { $$ = $1; }
1419 : MessageExpression { $$ = $1; }
1420 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1423 /* Cycript (Objective-C): @import Directive {{{ */
1437 : "@import" ImportPath { $$ = CYNew CYImport(); }
1443 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1444 LeftHandSideExpression
1445 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1449 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1453 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1454 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1455 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1460 /* YUI: Documentation Comments {{{ */
1462 : Comment { $$ = $1; }
1467 /* Lexer State {{{ */
1469 : { driver.PushCondition(CYDriver::RegExpCondition); }
1473 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1477 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1481 : { driver.PopCondition(); }
1485 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1489 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1498 /* 8.1 Context Keywords {{{ */
1500 : "namespace" { $$ = $1; }
1501 | "xml" { $$ = $1; }
1504 /* 8.3 XML Initialiser Input Elements {{{ */
1506 : XMLComment { $$ = $1; }
1507 | XMLCDATA { $$ = $1; }
1508 | XMLPI { $$ = $1; }
1511 /* 11.1 Primary Expressions {{{ */
1513 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1514 | XMLInitialiser { $$ = $1; }
1515 | XMLListInitialiser { $$ = $1; }
1519 : AttributeIdentifier { $$ = $1; }
1520 | QualifiedIdentifier { $$ = $1; }
1521 | WildcardIdentifier { $$ = $1; }
1524 /* 11.1.1 Attribute Identifiers {{{ */
1526 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1530 : PropertySelector { $$ = $1; }
1531 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1535 : Identifier { $$ = CYNew CYSelector($1); }
1536 | WildcardIdentifier { $$ = $1; }
1539 /* 11.1.2 Qualified Identifiers {{{ */
1540 QualifiedIdentifier_
1541 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1542 | QualifiedIdentifier { $$ = $1; }
1546 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1549 /* 11.1.3 Wildcard Identifiers {{{ */
1551 : "*" { $$ = CYNew CYWildcard(); }
1554 /* 11.1.4 XML Initialiser {{{ */
1556 : XMLMarkup { $$ = $1; }
1557 | XMLElement { $$ = $1; }
1561 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1562 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1566 : LexPushXMLTag XMLTagName XMLAttributes
1570 : BRACE LexPushRegExp Expression LexPop "}"
1579 : XMLAttributes_ XMLAttribute
1584 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1585 | XMLAttributes_ XMLWhitespaceOpt
1594 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1598 : XMLExpression XMLElementContentOpt
1599 | XMLMarkup XMLElementContentOpt
1600 | XMLText XMLElementContentOpt
1601 | XMLElement XMLElementContentOpt
1604 XMLElementContentOpt
1609 /* 11.1.5 XMLList Initialiser {{{ */
1611 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1614 /* 11.2 Left-Hand-Side Expressions {{{ */
1616 : Identifier { $$ = $1; }
1617 | PropertyIdentifier { $$ = $1; }
1621 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1622 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1623 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1626 /* 12.1 The default xml namespace Statement {{{ */
1627 /* XXX: DefaultXMLNamespaceStatement
1628 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1632 : DefaultXMLNamespaceStatement { $$ = $1; }
1637 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1638 PropertyNameAndValueList_
1639 : "," { $$ = NULL; }
1643 /* JavaScript 1.7: Array Comprehensions {{{ */
1645 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1649 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1650 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
1654 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1657 ComprehensionListOpt
1658 : ComprehensionList { $$ = $1; }
1659 | IfComprehension { $$ = $1; }
1664 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1667 /* JavaScript 1.7: for each {{{ */
1669 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
1672 /* JavaScript 1.7: let Statements {{{ */
1674 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1682 /* JavaScript FTW: Ruby Blocks {{{ */
1683 RubyProcParameterList_
1684 : "," RubyProcParameterList { $$ = $2; }
1688 RubyProcParameterList
1689 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1694 : "|" RubyProcParameterList "|" { $$ = $2; }
1695 | "||" { $$ = NULL; }
1698 RubyProcParametersOpt
1699 : RubyProcParameters
1704 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1708 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1712 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }