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 <expression_> AssignmentExpression
331 %type <identifier_> BindingIdentifier
332 %type <expression_> BitwiseANDExpression
333 %type <statement_> Block_
334 %type <statement_> Block
335 %type <boolean_> BooleanLiteral
336 %type <declaration_> BindingElement
337 %type <expression_> BitwiseORExpression
338 %type <expression_> BitwiseXORExpression
339 %type <statement_> BreakStatement
340 %type <statement_> BreakableStatement
341 %type <expression_> CallExpression_
342 %type <expression_> CallExpression
343 %type <clause_> CaseBlock
344 %type <clause_> CaseClause
345 %type <clause_> CaseClausesOpt
346 %type <catch_> CatchOpt
347 %type <comprehension_> ComprehensionList
348 %type <comprehension_> ComprehensionListOpt
349 %type <expression_> ConditionalExpression
350 %type <statement_> ContinueStatement
351 %type <statement_> DebuggerStatement
352 %type <statement_> Declaration__
353 %type <statement_> Declaration_
354 %type <statement_> Declaration
355 %type <clause_> DefaultClause
356 %type <statement_> DoWhileStatement
357 %type <expression_> Element
358 %type <expression_> ElementOpt
359 %type <element_> ElementList
360 %type <element_> ElementListOpt
361 %type <statement_> ElseStatementOpt
362 %type <statement_> EmptyStatement
363 %type <expression_> EqualityExpression
364 %type <compound_> Expression_
365 %type <expression_> Expression
366 %type <expression_> ExpressionOpt
367 %type <statement_> ExpressionStatement
368 %type <finally_> FinallyOpt
369 %type <comprehension_> ForComprehension
370 %type <statement_> ForStatement
371 %type <for_> ForStatementInitialiser
372 %type <statement_> ForInStatement
373 %type <forin_> ForInStatementInitialiser
374 %type <declaration_> FormalParameter
375 %type <functionParameter_> FormalParameterList_
376 %type <functionParameter_> FormalParameterList
377 %type <functionParameter_> FormalParameterListOpt
378 %type <statement_> FunctionBody
379 %type <statement_> FunctionDeclaration
380 %type <expression_> FunctionExpression
381 %type <identifier_> Identifier
382 %type <identifier_> IdentifierOpt
383 %type <comprehension_> IfComprehension
384 %type <statement_> IfStatement
385 %type <expression_> Initialiser
386 %type <expression_> InitialiserOpt
387 %type <statement_> IterationStatement
388 %type <statement_> LabelledStatement
389 %type <expression_> LeftHandSideExpression
390 %type <statement_> LetStatement
391 %type <statement_> LexicalDeclaration
392 %type <literal_> Literal
393 %type <literal_> LiteralNoRE
394 %type <expression_> LogicalANDExpression
395 %type <expression_> LogicalORExpression
396 %type <member_> MemberAccess
397 %type <expression_> MemberExpression_
398 %type <expression_> MemberExpression
399 %type <expression_> MultiplicativeExpression
400 %type <expression_> NewExpression
401 %type <null_> NullLiteral
402 %type <literal_> ObjectLiteral
403 %type <expression_> Parenthetical
404 %type <expression_> PostfixExpression
405 %type <expression_> PrimaryExpression
406 %type <statement_> Program
407 %type <statement_> ProgramBody
408 %type <statement_> ProgramBodyOpt
409 %type <propertyName_> PropertyName_
410 %type <propertyName_> PropertyName
411 %type <property_> PropertyNameAndValueList_
412 %type <property_> PropertyNameAndValueList
413 %type <property_> PropertyNameAndValueListOpt
414 %type <expression_> RelationalExpression
415 %type <statement_> ReturnStatement
416 %type <rubyProc_> RubyProcExpression
417 %type <functionParameter_> RubyProcParameterList_
418 %type <functionParameter_> RubyProcParameterList
419 %type <functionParameter_> RubyProcParameters
420 %type <functionParameter_> RubyProcParametersOpt
421 %type <expression_> ShiftExpression
422 %type <declaration_> SingleNameBinding
423 %type <statement_> Statement__
424 %type <statement_> Statement_
425 %type <statement_> Statement
426 %type <statement_> StatementList
427 %type <statement_> StatementListOpt
428 %type <statement_> StatementListItem
429 %type <statement_> SwitchStatement
430 %type <statement_> ThrowStatement
431 %type <statement_> TryStatement
432 %type <expression_> UnaryExpression_
433 %type <expression_> UnaryExpression
434 %type <declaration_> VariableDeclaration
435 %type <declarations_> VariableDeclarationList_
436 %type <declarations_> VariableDeclarationList
437 %type <statement_> VariableStatement
438 %type <statement_> WhileStatement
439 %type <statement_> WithStatement
442 %type <statement_> CategoryStatement
443 %type <expression_> ClassExpression
444 %type <statement_> ClassStatement
445 %type <expression_> ClassSuperOpt
446 %type <field_> ClassFieldList
447 %type <message_> ClassMessageDeclaration
448 %type <message_> ClassMessageDeclarationListOpt
449 %type <className_> ClassName
450 %type <className_> ClassNameOpt
451 %type <protocol_> ClassProtocolListOpt
452 %type <protocol_> ClassProtocols
453 %type <protocol_> ClassProtocolsOpt
454 %type <expression_> MessageExpression
455 %type <messageParameter_> MessageParameter
456 %type <messageParameter_> MessageParameters
457 %type <messageParameter_> MessageParameterList
458 %type <messageParameter_> MessageParameterListOpt
459 %type <bool_> MessageScope
460 %type <argument_> SelectorCall_
461 %type <argument_> SelectorCall
462 %type <selector_> SelectorExpression_
463 %type <selector_> SelectorExpression
464 %type <selector_> SelectorExpressionOpt
465 %type <argument_> SelectorList
466 %type <word_> SelectorWordOpt
467 %type <expression_> TypeOpt
468 %type <argument_> VariadicCall
470 %type <word_> WordOpt
474 %type <propertyIdentifier_> PropertyIdentifier_
475 %type <selector_> PropertySelector_
476 %type <selector_> PropertySelector
477 %type <identifier_> QualifiedIdentifier_
478 %type <identifier_> QualifiedIdentifier
479 %type <identifier_> WildcardIdentifier
480 %type <identifier_> XMLComment
481 %type <identifier_> XMLCDATA
482 %type <identifier_> XMLElement
483 %type <identifier_> XMLElementContent
484 %type <identifier_> XMLMarkup
485 %type <identifier_> XMLPI
487 %type <attribute_> AttributeIdentifier
488 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
489 %type <expression_> PropertyIdentifier
490 %type <expression_> XMLListInitialiser
491 %type <expression_> XMLInitialiser
504 /* Lexer State {{{ */
506 : { driver.in_.push(true); }
510 : { driver.in_.push(false); }
514 : { driver.in_.pop(); }
518 : { driver.SetCondition(CYDriver::RegExpCondition); }
522 : { switch (yychar) {
523 case token::Function:
524 yychar = token::Function_;
527 case token::OpenBrace:
528 case token::OpenBrace_:
529 yychar = token::OpenBrace__;
541 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
551 | error { if (yychar != 0 && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
556 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
571 : Identifier { $$ = $1; }
572 | "break" NewLineOpt { $$ = $1; }
573 | "case" { $$ = $1; }
574 | "catch" { $$ = $1; }
575 | "class" { $$ = $1; }
576 | "const" { $$ = $1; }
577 | "continue" NewLineOpt { $$ = $1; }
578 | "debugger" { $$ = $1; }
579 | "default" { $$ = $1; }
580 | "delete" { $$ = $1; }
582 | "else" { $$ = $1; }
583 | "enum" { $$ = $1; }
584 | "export" { $$ = $1; }
585 | "extends" { $$ = $1; }
586 | "false" { $$ = $1; }
587 | "finally" { $$ = $1; }
588 /* XXX: | "for" { $$ = $1; } */
589 | "function" { $$ = $1; }
591 | "import" { $$ = $1; }
592 /* XXX: | "in" { $$ = $1; } */
593 /* XXX: | "instanceof" { $$ = $1; } */
595 | "null" { $$ = $1; }
596 | "return" NewLineOpt { $$ = $1; }
597 | "super" { $$ = $1; }
598 | "switch" { $$ = $1; }
599 | "this" { $$ = $1; }
600 | "throw" NewLineOpt { $$ = $1; }
601 | "true" { $$ = $1; }
603 | "typeof" { $$ = $1; }
605 | "void" { $$ = $1; }
606 | "while" { $$ = $1; }
607 | "with" { $$ = $1; }
616 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
617 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
618 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
619 | "@" Parenthetical { $$ = CYNew CYBox($2); }
624 : Identifier_ { $$ = $1; }
626 | "implements" { $$ = $1; }
627 | "interface" { $$ = $1; }
628 | "package" { $$ = $1; }
629 | "private" { $$ = $1; }
630 | "protected" { $$ = $1; }
631 | "public" { $$ = $1; }
632 | "static" { $$ = $1; }
634 | "abstract" { $$ = $1; }
635 | "boolean" { $$ = $1; }
636 | "byte" { $$ = $1; }
637 | "char" { $$ = $1; }
638 | "double" { $$ = $1; }
639 | "final" { $$ = $1; }
640 | "float" { $$ = $1; }
641 | "goto" { $$ = $1; }
643 | "long" { $$ = $1; }
644 | "native" { $$ = $1; }
645 | "short" { $$ = $1; }
646 | "synchronized" { $$ = $1; }
647 | "throws" { $$ = $1; }
648 | "transient" { $$ = $1; }
649 | "volatile" { $$ = $1; }
651 // XXX: is this allowed?! | "let" { $$ = $1; }
652 | "yield" { $$ = $1; }
654 | "each" { $$ = $1; }
658 : Identifier { $$ = $1; }
663 : NullLiteral { $$ = $1; }
664 | BooleanLiteral { $$ = $1; }
665 | NumericLiteral { $$ = $1; }
666 | StringLiteral { $$ = $1; }
670 : LiteralNoRE { $$ = $1; }
671 | RegularExpressionLiteral { $$ = $1; }
675 : "null" { $$ = $1; }
679 : "true" { $$ = $1; }
680 | "false" { $$ = $1; }
683 /* 11.1 Primary Expressions {{{ */
685 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
689 : "this" { $$ = $1; }
690 | Identifier { $$ = CYNew CYVariable($1); }
691 | Literal { $$ = $1; }
692 | ArrayLiteral { $$ = $1; }
693 | ObjectLiteral { $$ = $1; }
694 | FunctionExpression { $$ = $1; }
695 | Parenthetical { $$ = $1; }
696 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
699 /* 11.1.4.1 Array Initialiser {{{ */
701 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
705 : AssignmentExpression { $$ = $1; }
709 : Element { $$ = $1; }
710 | LexSetRegExp { $$ = NULL; }
714 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
715 | Element { $$ = CYNew CYElement($1, NULL); }
719 : ElementList { $$ = $1; }
720 | LexSetRegExp { $$ = NULL; }
723 /* 11.1.5 Object Initialiser {{{ */
725 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
728 PropertyNameAndValueList_
729 : "," PropertyNameAndValueList { $$ = $2; }
733 PropertyNameAndValueList
734 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
737 PropertyNameAndValueListOpt
738 : PropertyNameAndValueList { $$ = $1; }
743 : Identifier { $$ = $1; }
744 | StringLiteral { $$ = $1; }
745 | NumericLiteral { $$ = $1; }
749 : LexSetRegExp PropertyName_ { $$ = $2; }
753 /* 11.2 Left-Hand-Side Expressions {{{ */
755 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
756 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
757 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
761 : MemberExpression { $$ = $1; }
762 //| "super" { $$ = $1; }
766 : LexSetRegExp PrimaryExpression { $$ = $2; }
767 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
768 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
772 : MemberExpression { $$ = $1; }
773 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
782 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
783 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
787 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
791 : "," ArgumentList { $$ = $2; }
796 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
800 : ArgumentList { $$ = $1; }
801 | LexSetRegExp { $$ = NULL; }
804 LeftHandSideExpression
805 : NewExpression { $$ = $1; }
806 | CallExpression { $$ = $1; }
809 /* 11.3 Postfix Expressions {{{ */
811 : %prec "" LeftHandSideExpression { $$ = $1; }
812 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
813 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
816 /* 11.4 Unary Operators {{{ */
818 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
819 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
820 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
821 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
822 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
823 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
824 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
825 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
826 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
827 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
828 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
832 : PostfixExpression { $$ = $1; }
833 | LexSetRegExp UnaryExpression_ { $$ = $2; }
836 /* 11.5 Multiplicative Operators {{{ */
837 MultiplicativeExpression
838 : UnaryExpression { $$ = $1; }
839 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
840 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
841 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
844 /* 11.6 Additive Operators {{{ */
846 : MultiplicativeExpression { $$ = $1; }
847 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
848 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
851 /* 11.7 Bitwise Shift Operators {{{ */
853 : AdditiveExpression { $$ = $1; }
854 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
855 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
856 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
859 /* 11.8 Relational Operators {{{ */
861 : ShiftExpression { $$ = $1; }
862 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
863 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
864 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
865 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
866 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
867 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
870 /* 11.9 Equality Operators {{{ */
872 : RelationalExpression { $$ = $1; }
873 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
874 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
875 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
876 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
879 /* 11.10 Binary Bitwise Operators {{{ */
881 : EqualityExpression { $$ = $1; }
882 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
886 : BitwiseANDExpression { $$ = $1; }
887 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
891 : BitwiseXORExpression { $$ = $1; }
892 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
895 /* 11.11 Binary Logical Operators {{{ */
897 : BitwiseORExpression { $$ = $1; }
898 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
902 : LogicalANDExpression { $$ = $1; }
903 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
906 /* 11.12 Conditional Operator ( ? : ) {{{ */
907 ConditionalExpression
908 : LogicalORExpression { $$ = $1; }
909 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
912 /* 11.13 Assignment Operators {{{ */
914 : ConditionalExpression { $$ = $1; }
915 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
916 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
917 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
918 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
919 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
920 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
921 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
922 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
923 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
924 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
925 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
926 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
929 /* 11.14 Comma Operator {{{ */
931 : "," Expression { $$ = CYNew CYCompound($2); }
936 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
940 : Expression { $$ = $1; }
941 | LexSetRegExp { $$ = NULL; }
945 /* 12 Statements {{{ */
948 | VariableStatement { $$ = $1; }
949 | EmptyStatement { $$ = $1; }
950 | IfStatement { $$ = $1; }
951 | BreakableStatement { $$ = $1; }
952 | ContinueStatement { $$ = $1; }
953 | BreakStatement { $$ = $1; }
954 | ReturnStatement { $$ = $1; }
955 | WithStatement { $$ = $1; }
956 | LabelledStatement { $$ = $1; }
957 | ThrowStatement { $$ = $1; }
958 | TryStatement { $$ = $1; }
959 | DebuggerStatement { $$ = $1; }
963 : LexSetRegExp Statement__ { $$ = $2; }
964 | ExpressionStatement { $$ = $1; }
968 : LexSetStatement Statement_ { $$ = $2; }
972 : FunctionDeclaration { $$ = $1; }
973 | LexicalDeclaration { $$ = $1; }
977 : LexSetRegExp Declaration__ { $$ = $2; }
981 : LexSetStatement Declaration_ { $$ = $2; }
985 : IterationStatement { $$ = $1; }
986 | SwitchStatement { $$ = $1; }
991 : BRACE StatementListOpt "}" { $$ = $2; }
995 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
999 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1003 : StatementList { $$ = $1; }
1004 | LexSetRegExp { $$ = NULL; }
1008 : Statement { $$ = $1; }
1009 | Declaration { $$ = $1; }
1012 /* 12.2 Declarations {{{ */
1014 : Identifier { $$ = $1; }
1017 // XXX: BindingPattern
1019 /* 12.2.1 Let and Const Declarations {{{ */
1021 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1029 /* 12.2.2 Variable Statement {{{ */
1031 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1034 VariableDeclarationList_
1035 : "," VariableDeclarationList { $$ = $2; }
1039 VariableDeclarationList
1040 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1044 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1045 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1049 : "=" AssignmentExpression { $$ = $2; }
1053 : Initialiser { $$ = $1; }
1057 /* 12.2.4 Destructuring Binding Patterns {{{ */
1061 : SingleNameBinding { $$ = $1; }
1065 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1068 /* 12.3 Empty Statement {{{ */
1070 : ";" { $$ = CYNew CYEmpty(); }
1073 /* 12.4 Expression Statement {{{ */
1075 : Expression Terminator { $$ = CYNew CYExpress($1); }
1078 /* 12.5 The if Statement {{{ */
1080 : "else" Statement { $$ = $2; }
1081 | %prec "if" { $$ = NULL; }
1085 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1089 /* 12.6 Iteration Statements {{{ */
1091 : DoWhileStatement { $$ = $1; }
1092 | WhileStatement { $$ = $1; }
1093 | ForStatement { $$ = $1; }
1094 | ForInStatement { $$ = $1; }
1097 /* 12.6.1 The do-while Statement {{{ */
1099 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1102 /* 12.6.2 The while Statement {{{ */
1104 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1107 /* 12.6.3 The for Statement {{{ */
1109 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1112 ForStatementInitialiser
1113 : ExpressionOpt { $$ = $1; }
1114 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1117 /* 12.6.4 The for-in Statement {{{ */
1119 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1122 ForInStatementInitialiser
1123 : LeftHandSideExpression { $$ = $1; }
1124 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1128 /* 12.7 The continue Statement {{{ */
1130 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1133 /* 12.8 The break Statement {{{ */
1135 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1138 /* 12.9 The return Statement {{{ */
1140 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1143 /* 12.10 The with Statement {{{ */
1145 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1149 /* 12.11 The switch Statement {{{ */
1151 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1155 : BRACE CaseClausesOpt "}" { $$ = $2; }
1159 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1163 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1164 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1169 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1172 /* 12.12 Labelled Statements {{{ */
1174 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1177 /* 12.13 The throw Statement {{{ */
1179 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1182 /* 12.14 The try Statement {{{ */
1184 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1188 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1193 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1197 /* 12.14 The debugger Statement {{{ */
1199 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1203 /* 13 Function Definition {{{ */
1205 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1209 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1212 FormalParameterList_
1213 : "," FormalParameterList { $$ = $2; }
1218 // XXX: : FunctionRestParameter { $$ = $1; }
1219 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1222 FormalParameterListOpt
1223 : FormalParameterList
1227 /* XXX: FunctionRestParameter
1228 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1232 : BindingElement { $$ = $1; }
1236 : StatementListOpt { $$ = $1; }
1239 /* 14 Program {{{ */
1241 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1245 : StatementList { $$ = $1; }
1249 : ProgramBody { $$ = $1; }
1255 /* Cycript (Objective-C): @class Declaration {{{ */
1257 /* XXX: why the hell did I choose MemberExpression? */
1258 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1263 : Expression Identifier ";"
1267 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1271 : ClassFieldListOpt ClassField
1276 : "+" { $$ = false; }
1277 | "-" { $$ = true; }
1281 : "(" Expression ")" { $$ = $2; }
1282 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1287 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1290 MessageParameterList
1291 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1294 MessageParameterListOpt
1295 : MessageParameterList { $$ = $1; }
1300 : MessageParameterList { $$ = $1; }
1301 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1304 ClassMessageDeclaration
1305 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1308 ClassMessageDeclarationListOpt
1309 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1310 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1315 : Identifier { $$ = $1; }
1316 | "(" AssignmentExpression ")" { $$ = $2; }
1320 : ClassName { $$ = $1; }
1324 // XXX: this should be AssignmentExpressionNoRight
1326 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1330 : "," ClassProtocols { $$ = $2; }
1334 ClassProtocolListOpt
1335 : "<" ClassProtocols ">" { $$ = $2; }
1340 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1344 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1352 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1356 : ClassExpression { $$ = $1; }
1360 : ClassStatement { $$ = $1; }
1361 | CategoryStatement { $$ = $1; }
1364 /* Cycript (Objective-C): Send Message {{{ */
1366 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1371 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1372 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1376 : SelectorCall { $$ = $1; }
1377 | VariadicCall { $$ = $1; }
1381 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1385 : SelectorCall { $$ = $1; }
1386 | Word { $$ = CYNew CYArgument($1, NULL); }
1390 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1391 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1395 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1399 : SelectorExpression_ { $$ = $1; }
1400 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1403 SelectorExpressionOpt
1404 : SelectorExpression_ { $$ = $1; }
1409 : MessageExpression { $$ = $1; }
1410 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1413 /* Cycript (Objective-C): @import Directive {{{ */
1427 : "@import" ImportPath { $$ = CYNew CYImport(); }
1433 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1434 LeftHandSideExpression
1435 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1439 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1443 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1444 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1445 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1450 /* YUI: Documentation Comments {{{ */
1452 : Comment { $$ = $1; }
1457 /* Lexer State {{{ */
1459 : { driver.PushCondition(CYDriver::RegExpCondition); }
1463 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1467 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1471 : { driver.PopCondition(); }
1475 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1479 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1488 /* 8.1 Context Keywords {{{ */
1490 : "namespace" { $$ = $1; }
1491 | "xml" { $$ = $1; }
1494 /* 8.3 XML Initialiser Input Elements {{{ */
1496 : XMLComment { $$ = $1; }
1497 | XMLCDATA { $$ = $1; }
1498 | XMLPI { $$ = $1; }
1501 /* 11.1 Primary Expressions {{{ */
1503 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1504 | XMLInitialiser { $$ = $1; }
1505 | XMLListInitialiser { $$ = $1; }
1509 : AttributeIdentifier { $$ = $1; }
1510 | QualifiedIdentifier { $$ = $1; }
1511 | WildcardIdentifier { $$ = $1; }
1514 /* 11.1.1 Attribute Identifiers {{{ */
1516 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1520 : PropertySelector { $$ = $1; }
1521 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1525 : Identifier { $$ = CYNew CYSelector($1); }
1526 | WildcardIdentifier { $$ = $1; }
1529 /* 11.1.2 Qualified Identifiers {{{ */
1530 QualifiedIdentifier_
1531 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1532 | QualifiedIdentifier { $$ = $1; }
1536 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1539 /* 11.1.3 Wildcard Identifiers {{{ */
1541 : "*" { $$ = CYNew CYWildcard(); }
1544 /* 11.1.4 XML Initialiser {{{ */
1546 : XMLMarkup { $$ = $1; }
1547 | XMLElement { $$ = $1; }
1551 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1552 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1556 : LexPushXMLTag XMLTagName XMLAttributes
1560 : BRACE LexPushRegExp Expression LexPop "}"
1569 : XMLAttributes_ XMLAttribute
1574 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1575 | XMLAttributes_ XMLWhitespaceOpt
1584 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1588 : XMLExpression XMLElementContentOpt
1589 | XMLMarkup XMLElementContentOpt
1590 | XMLText XMLElementContentOpt
1591 | XMLElement XMLElementContentOpt
1594 XMLElementContentOpt
1599 /* 11.1.5 XMLList Initialiser {{{ */
1601 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1604 /* 11.2 Left-Hand-Side Expressions {{{ */
1606 : Identifier { $$ = $1; }
1607 | PropertyIdentifier { $$ = $1; }
1611 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1612 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1613 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1616 /* 12.1 The default xml namespace Statement {{{ */
1617 /* XXX: DefaultXMLNamespaceStatement
1618 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1622 : DefaultXMLNamespaceStatement { $$ = $1; }
1627 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1628 PropertyNameAndValueList_
1629 : "," { $$ = NULL; }
1633 /* JavaScript 1.7: Array Comprehensions {{{ */
1635 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1639 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1640 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
1644 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1647 ComprehensionListOpt
1648 : ComprehensionList { $$ = $1; }
1649 | IfComprehension { $$ = $1; }
1654 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1657 /* JavaScript 1.7: for each {{{ */
1659 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
1662 /* JavaScript 1.7: let Statements {{{ */
1664 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1672 /* JavaScript FTW: Ruby Blocks {{{ */
1673 RubyProcParameterList_
1674 : "," RubyProcParameterList { $$ = $2; }
1678 RubyProcParameterList
1679 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1684 : "|" RubyProcParameterList "|" { $$ = $2; }
1685 | "||" { $$ = NULL; }
1688 RubyProcParametersOpt
1689 : RubyProcParameters
1694 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1698 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1702 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }