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 <expression_> UnaryAssigneeExpression
448 %type <statement_> CategoryStatement
449 %type <expression_> ClassExpression
450 %type <statement_> ClassStatement
451 %type <expression_> ClassSuperOpt
452 %type <field_> ClassFieldList
453 %type <message_> ClassMessageDeclaration
454 %type <message_> ClassMessageDeclarationListOpt
455 %type <className_> ClassName
456 %type <className_> ClassNameOpt
457 %type <protocol_> ClassProtocolListOpt
458 %type <protocol_> ClassProtocols
459 %type <protocol_> ClassProtocolsOpt
460 %type <expression_> MessageExpression
461 %type <messageParameter_> MessageParameter
462 %type <messageParameter_> MessageParameters
463 %type <messageParameter_> MessageParameterList
464 %type <messageParameter_> MessageParameterListOpt
465 %type <bool_> MessageScope
466 %type <argument_> SelectorCall_
467 %type <argument_> SelectorCall
468 %type <selector_> SelectorExpression_
469 %type <selector_> SelectorExpression
470 %type <selector_> SelectorExpressionOpt
471 %type <argument_> SelectorList
472 %type <word_> SelectorWordOpt
473 %type <expression_> TypeOpt
474 %type <argument_> VariadicCall
476 %type <word_> WordOpt
480 %type <propertyIdentifier_> PropertyIdentifier_
481 %type <selector_> PropertySelector_
482 %type <selector_> PropertySelector
483 %type <identifier_> QualifiedIdentifier_
484 %type <identifier_> QualifiedIdentifier
485 %type <identifier_> WildcardIdentifier
486 %type <identifier_> XMLComment
487 %type <identifier_> XMLCDATA
488 %type <identifier_> XMLElement
489 %type <identifier_> XMLElementContent
490 %type <identifier_> XMLMarkup
491 %type <identifier_> XMLPI
493 %type <attribute_> AttributeIdentifier
494 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
495 %type <expression_> PropertyIdentifier
496 %type <expression_> XMLListInitialiser
497 %type <expression_> XMLInitialiser
510 /* Lexer State {{{ */
512 : { driver.in_.push(true); }
516 : { driver.in_.push(false); }
520 : { driver.in_.pop(); }
524 : { driver.SetCondition(CYDriver::RegExpCondition); }
530 driver.statement_ = true;
531 else switch (yychar) {
532 case cy::parser::token::Function:
533 yychar = cy::parser::token::Function_;
536 case cy::parser::token::OpenBrace:
537 case cy::parser::token::OpenBrace_:
538 yychar = cy::parser::token::OpenBrace__;
551 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
561 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
566 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
581 : Identifier { $$ = $1; }
582 | "break" NewLineOpt { $$ = $1; }
583 | "case" { $$ = $1; }
584 | "catch" { $$ = $1; }
585 | "class" { $$ = $1; }
586 | "const" { $$ = $1; }
587 | "continue" NewLineOpt { $$ = $1; }
588 | "debugger" { $$ = $1; }
589 | "default" { $$ = $1; }
590 | "delete" { $$ = $1; }
592 | "else" { $$ = $1; }
593 | "enum" { $$ = $1; }
594 | "export" { $$ = $1; }
595 | "extends" { $$ = $1; }
596 | "false" { $$ = $1; }
597 | "finally" { $$ = $1; }
598 /* XXX: | "for" { $$ = $1; } */
599 | "function" { $$ = $1; }
601 | "import" { $$ = $1; }
602 /* XXX: | "in" { $$ = $1; } */
603 /* XXX: | "instanceof" { $$ = $1; } */
605 | "null" { $$ = $1; }
606 | "return" NewLineOpt { $$ = $1; }
607 | "super" { $$ = $1; }
608 | "switch" { $$ = $1; }
609 | "this" { $$ = $1; }
610 | "throw" NewLineOpt { $$ = $1; }
611 | "true" { $$ = $1; }
613 | "typeof" { $$ = $1; }
615 | "void" { $$ = $1; }
616 | "while" { $$ = $1; }
617 | "with" { $$ = $1; }
626 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
627 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
628 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
629 | "@" Parenthetical { $$ = CYNew CYBox($2); }
634 : Identifier_ { $$ = $1; }
636 | "implements" { $$ = $1; }
637 | "interface" { $$ = $1; }
638 | "package" { $$ = $1; }
639 | "private" { $$ = $1; }
640 | "protected" { $$ = $1; }
641 | "public" { $$ = $1; }
642 | "static" { $$ = $1; }
644 | "abstract" { $$ = $1; }
645 | "boolean" { $$ = $1; }
646 | "byte" { $$ = $1; }
647 | "char" { $$ = $1; }
648 | "double" { $$ = $1; }
649 | "final" { $$ = $1; }
650 | "float" { $$ = $1; }
651 | "goto" { $$ = $1; }
653 | "long" { $$ = $1; }
654 | "native" { $$ = $1; }
655 | "short" { $$ = $1; }
656 | "synchronized" { $$ = $1; }
657 | "throws" { $$ = $1; }
658 | "transient" { $$ = $1; }
659 | "volatile" { $$ = $1; }
661 // XXX: is this allowed?! | "let" { $$ = $1; }
662 | "yield" { $$ = $1; }
664 | "each" { $$ = $1; }
668 : Identifier { $$ = $1; }
673 : NullLiteral { $$ = $1; }
674 | BooleanLiteral { $$ = $1; }
675 | NumericLiteral { $$ = $1; }
676 | StringLiteral { $$ = $1; }
680 : LiteralNoRE { $$ = $1; }
681 | RegularExpressionLiteral { $$ = $1; }
685 : "null" { $$ = $1; }
689 : "true" { $$ = $1; }
690 | "false" { $$ = $1; }
693 /* 11.1 Primary Expressions {{{ */
695 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
699 : "this" { $$ = $1; }
700 | Identifier { $$ = CYNew CYVariable($1); }
701 | Literal { $$ = $1; }
702 | ArrayLiteral { $$ = $1; }
703 | ObjectLiteral { $$ = $1; }
704 | FunctionExpression { $$ = $1; }
705 | Parenthetical { $$ = $1; }
706 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
709 /* 11.1.4.1 Array Initialiser {{{ */
711 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
715 : AssignmentExpression { $$ = $1; }
719 : Element { $$ = $1; }
720 | LexSetRegExp { $$ = NULL; }
724 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
725 | Element { $$ = CYNew CYElement($1, NULL); }
729 : ElementList { $$ = $1; }
730 | LexSetRegExp { $$ = NULL; }
733 /* 11.1.5 Object Initialiser {{{ */
735 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
738 PropertyNameAndValueList_
739 : "," PropertyNameAndValueList { $$ = $2; }
743 PropertyNameAndValueList
744 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
747 PropertyNameAndValueListOpt
748 : PropertyNameAndValueList { $$ = $1; }
753 : Identifier { $$ = $1; }
754 | StringLiteral { $$ = $1; }
755 | NumericLiteral { $$ = $1; }
759 : LexSetRegExp PropertyName_ { $$ = $2; }
763 /* 11.2 Left-Hand-Side Expressions {{{ */
765 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
766 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
767 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
771 : MemberExpression { $$ = $1; }
772 //| "super" { $$ = $1; }
776 : LexSetRegExp PrimaryExpression { $$ = $2; }
777 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
778 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
782 : MemberExpression { $$ = $1; }
783 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
792 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
793 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
797 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
801 : "," ArgumentList { $$ = $2; }
806 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
810 : ArgumentList { $$ = $1; }
811 | LexSetRegExp { $$ = NULL; }
814 LeftHandSideExpression
815 : NewExpression { $$ = $1; }
816 | CallExpression { $$ = $1; }
819 /* 11.3 Postfix Expressions {{{ */
821 : %prec "" LeftHandSideExpression { $$ = $1; }
822 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
823 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
826 /* 11.4 Unary Operators {{{ */
828 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
829 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
830 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
831 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
832 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
833 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
834 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
835 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
836 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
837 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
838 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
842 : PostfixExpression { $$ = $1; }
843 | LexSetRegExp UnaryExpression_ { $$ = $2; }
846 /* 11.5 Multiplicative Operators {{{ */
847 MultiplicativeExpression
848 : UnaryExpression { $$ = $1; }
849 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
850 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
851 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
854 /* 11.6 Additive Operators {{{ */
856 : MultiplicativeExpression { $$ = $1; }
857 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
858 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
861 /* 11.7 Bitwise Shift Operators {{{ */
863 : AdditiveExpression { $$ = $1; }
864 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
865 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
866 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
869 /* 11.8 Relational Operators {{{ */
870 RelationalExpression_
871 : ShiftExpression { $$ = $1; }
875 : RelationalExpression_ { $$ = $1; }
876 | RelationalExpression "<" RelationalExpression_ { $$ = CYNew CYLess($1, $3); }
877 | RelationalExpression ">" RelationalExpression_ { $$ = CYNew CYGreater($1, $3); }
878 | RelationalExpression "<=" RelationalExpression_ { $$ = CYNew CYLessOrEqual($1, $3); }
879 | RelationalExpression ">=" RelationalExpression_ { $$ = CYNew CYGreaterOrEqual($1, $3); }
880 | RelationalExpression "instanceof" RelationalExpression_ { $$ = CYNew CYInstanceOf($1, $3); }
881 | RelationalExpression "in" RelationalExpression_ { $$ = CYNew CYIn($1, $3); }
884 /* 11.9 Equality Operators {{{ */
886 : RelationalExpression { $$ = $1; }
887 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
888 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
889 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
890 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
893 /* 11.10 Binary Bitwise Operators {{{ */
895 : EqualityExpression { $$ = $1; }
896 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
900 : BitwiseANDExpression { $$ = $1; }
901 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
905 : BitwiseXORExpression { $$ = $1; }
906 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
909 /* 11.11 Binary Logical Operators {{{ */
911 : BitwiseORExpression { $$ = $1; }
912 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
916 : LogicalANDExpression { $$ = $1; }
917 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
920 /* 11.12 Conditional Operator ( ? : ) {{{ */
921 ConditionalExpression
922 : LogicalORExpression { $$ = $1; }
923 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
926 /* 11.13 Assignment Operators {{{ */
927 AssignmentExpression_
928 : "=" AssignmentExpression { $$ = CYNew CYAssign(NULL, $2); }
929 | "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign(NULL, $2); }
930 | "/=" AssignmentExpression { $$ = CYNew CYDivideAssign(NULL, $2); }
931 | "%=" AssignmentExpression { $$ = CYNew CYModulusAssign(NULL, $2); }
932 | "+=" AssignmentExpression { $$ = CYNew CYAddAssign(NULL, $2); }
933 | "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign(NULL, $2); }
934 | "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign(NULL, $2); }
935 | ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign(NULL, $2); }
936 | ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign(NULL, $2); }
937 | "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign(NULL, $2); }
938 | "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign(NULL, $2); }
939 | "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign(NULL, $2); }
943 LeftHandSideExpression
944 : LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
949 : ConditionalExpression { $$ = $1; }
950 | LeftHandSideExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
953 /* 11.14 Comma Operator {{{ */
955 : "," Expression { $$ = CYNew CYCompound($2); }
960 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
964 : Expression { $$ = $1; }
965 | LexSetRegExp { $$ = NULL; }
969 /* 12 Statements {{{ */
972 | VariableStatement { $$ = $1; }
973 | EmptyStatement { $$ = $1; }
974 | IfStatement { $$ = $1; }
975 | BreakableStatement { $$ = $1; }
976 | ContinueStatement { $$ = $1; }
977 | BreakStatement { $$ = $1; }
978 | ReturnStatement { $$ = $1; }
979 | WithStatement { $$ = $1; }
980 | LabelledStatement { $$ = $1; }
981 | ThrowStatement { $$ = $1; }
982 | TryStatement { $$ = $1; }
983 | DebuggerStatement { $$ = $1; }
987 : LexSetRegExp Statement__ { $$ = $2; }
988 | ExpressionStatement { $$ = $1; }
992 : LexSetStatement Statement_ { $$ = $2; }
996 : FunctionDeclaration { $$ = $1; }
997 | LexicalDeclaration { $$ = $1; }
1001 : LexSetRegExp Declaration__ { $$ = $2; }
1005 : LexSetStatement Declaration_ { $$ = $2; }
1009 : IterationStatement { $$ = $1; }
1010 | SwitchStatement { $$ = $1; }
1013 /* 12.1 Block {{{ */
1015 : BRACE StatementListOpt "}" { $$ = $2; }
1019 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1023 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1027 : StatementList { $$ = $1; }
1028 | LexSetRegExp { $$ = NULL; }
1032 : Statement { $$ = $1; }
1033 | Declaration { $$ = $1; }
1036 /* 12.2 Declarations {{{ */
1038 : Identifier { $$ = $1; }
1041 // XXX: BindingPattern
1043 /* 12.2.1 Let and Const Declarations {{{ */
1045 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1053 /* 12.2.2 Variable Statement {{{ */
1055 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1058 VariableDeclarationList_
1059 : "," VariableDeclarationList { $$ = $2; }
1063 VariableDeclarationList
1064 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1068 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1069 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1073 : "=" AssignmentExpression { $$ = $2; }
1077 : Initialiser { $$ = $1; }
1081 /* 12.2.4 Destructuring Binding Patterns {{{ */
1085 : SingleNameBinding { $$ = $1; }
1089 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1092 /* 12.3 Empty Statement {{{ */
1094 : ";" { $$ = CYNew CYEmpty(); }
1097 /* 12.4 Expression Statement {{{ */
1099 : Expression Terminator { $$ = CYNew CYExpress($1); }
1102 /* 12.5 The if Statement {{{ */
1104 : "else" Statement { $$ = $2; }
1105 | %prec "if" { $$ = NULL; }
1109 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1113 /* 12.6 Iteration Statements {{{ */
1115 : DoWhileStatement { $$ = $1; }
1116 | WhileStatement { $$ = $1; }
1117 | ForStatement { $$ = $1; }
1118 | ForInStatement { $$ = $1; }
1121 /* 12.6.1 The do-while Statement {{{ */
1123 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1126 /* 12.6.2 The while Statement {{{ */
1128 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1131 /* 12.6.3 The for Statement {{{ */
1133 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1136 ForStatementInitialiser
1137 : ExpressionOpt { $$ = $1; }
1138 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1141 /* 12.6.4 The for-in Statement {{{ */
1143 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1146 ForInStatementInitialiser
1147 : LeftHandSideExpression { $$ = $1; }
1148 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1152 /* 12.7 The continue Statement {{{ */
1154 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1157 /* 12.8 The break Statement {{{ */
1159 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1162 /* 12.9 The return Statement {{{ */
1164 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1167 /* 12.10 The with Statement {{{ */
1169 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1173 /* 12.11 The switch Statement {{{ */
1175 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1179 : BRACE CaseClausesOpt "}" { $$ = $2; }
1183 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1187 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1188 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1193 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1196 /* 12.12 Labelled Statements {{{ */
1198 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1201 /* 12.13 The throw Statement {{{ */
1203 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1206 /* 12.14 The try Statement {{{ */
1208 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1212 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1217 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1221 /* 12.14 The debugger Statement {{{ */
1223 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1227 /* 13 Function Definition {{{ */
1229 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1233 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1236 FormalParameterList_
1237 : "," FormalParameterList { $$ = $2; }
1242 // XXX: : FunctionRestParameter { $$ = $1; }
1243 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1246 FormalParameterListOpt
1247 : FormalParameterList
1251 /* XXX: FunctionRestParameter
1252 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1256 : BindingElement { $$ = $1; }
1260 : StatementListOpt { $$ = $1; }
1263 /* 14 Program {{{ */
1265 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1269 : StatementList { $$ = $1; }
1273 : ProgramBody { $$ = $1; }
1279 /* Cycript (Objective-C): @class Declaration {{{ */
1281 /* XXX: why the hell did I choose MemberExpression? */
1282 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1287 : Expression Identifier ";"
1291 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1295 : ClassFieldListOpt ClassField
1300 : "+" { $$ = false; }
1301 | "-" { $$ = true; }
1305 : "(" Expression ")" { $$ = $2; }
1306 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1311 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1314 MessageParameterList
1315 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1318 MessageParameterListOpt
1319 : MessageParameterList { $$ = $1; }
1324 : MessageParameterList { $$ = $1; }
1325 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1328 ClassMessageDeclaration
1329 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1332 ClassMessageDeclarationListOpt
1333 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1334 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1339 : Identifier { $$ = $1; }
1340 | "(" AssignmentExpression ")" { $$ = $2; }
1344 : ClassName { $$ = $1; }
1348 // XXX: this should be AssignmentExpressionNoRight
1350 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1354 : "," ClassProtocols { $$ = $2; }
1358 ClassProtocolListOpt
1359 : "<" ClassProtocols ">" { $$ = $2; }
1364 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1368 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1376 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1380 : ClassExpression { $$ = $1; }
1384 : ClassStatement { $$ = $1; }
1385 | CategoryStatement { $$ = $1; }
1388 /* Cycript (Objective-C): Send Message {{{ */
1390 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1395 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1396 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1400 : SelectorCall { $$ = $1; }
1401 | VariadicCall { $$ = $1; }
1405 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1409 : SelectorCall { $$ = $1; }
1410 | Word { $$ = CYNew CYArgument($1, NULL); }
1414 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1415 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1419 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1423 : SelectorExpression_ { $$ = $1; }
1424 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1427 SelectorExpressionOpt
1428 : SelectorExpression_ { $$ = $1; }
1433 : MessageExpression { $$ = $1; }
1434 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1437 /* Cycript (Objective-C): @import Directive {{{ */
1451 : "@import" ImportPath { $$ = CYNew CYImport(); }
1457 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1458 UnaryAssigneeExpression
1459 : "*" UnaryExpression { $$ = CYNew CYIndirect($2); }
1463 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1467 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1468 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1469 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1474 /* YUI: Documentation Comments {{{ */
1476 : Comment { $$ = $1; }
1481 /* Lexer State {{{ */
1483 : { driver.PushCondition(CYDriver::RegExpCondition); }
1487 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1491 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1495 : { driver.PopCondition(); }
1499 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1503 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1512 /* 8.1 Context Keywords {{{ */
1514 : "namespace" { $$ = $1; }
1515 | "xml" { $$ = $1; }
1518 /* 8.3 XML Initialiser Input Elements {{{ */
1520 : XMLComment { $$ = $1; }
1521 | XMLCDATA { $$ = $1; }
1522 | XMLPI { $$ = $1; }
1525 /* 11.1 Primary Expressions {{{ */
1527 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1528 | XMLInitialiser { $$ = $1; }
1529 | XMLListInitialiser { $$ = $1; }
1533 : AttributeIdentifier { $$ = $1; }
1534 | QualifiedIdentifier { $$ = $1; }
1535 | WildcardIdentifier { $$ = $1; }
1538 /* 11.1.1 Attribute Identifiers {{{ */
1540 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1544 : PropertySelector { $$ = $1; }
1545 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1549 : Identifier { $$ = CYNew CYSelector($1); }
1550 | WildcardIdentifier { $$ = $1; }
1553 /* 11.1.2 Qualified Identifiers {{{ */
1554 QualifiedIdentifier_
1555 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1556 | QualifiedIdentifier { $$ = $1; }
1560 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1563 /* 11.1.3 Wildcard Identifiers {{{ */
1565 : "*" { $$ = CYNew CYWildcard(); }
1568 /* 11.1.4 XML Initialiser {{{ */
1570 : XMLMarkup { $$ = $1; }
1571 | XMLElement { $$ = $1; }
1575 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1576 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1580 : LexPushXMLTag XMLTagName XMLAttributes
1584 : BRACE LexPushRegExp Expression LexPop "}"
1593 : XMLAttributes_ XMLAttribute
1598 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1599 | XMLAttributes_ XMLWhitespaceOpt
1608 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1612 : XMLExpression XMLElementContentOpt
1613 | XMLMarkup XMLElementContentOpt
1614 | XMLText XMLElementContentOpt
1615 | XMLElement XMLElementContentOpt
1618 XMLElementContentOpt
1623 /* 11.1.5 XMLList Initialiser {{{ */
1625 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1628 /* 11.2 Left-Hand-Side Expressions {{{ */
1630 : Identifier { $$ = $1; }
1631 | PropertyIdentifier { $$ = $1; }
1635 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1636 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1637 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1640 /* 12.1 The default xml namespace Statement {{{ */
1641 /* XXX: DefaultXMLNamespaceStatement
1642 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1646 : DefaultXMLNamespaceStatement { $$ = $1; }
1651 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1652 PropertyNameAndValueList_
1653 : "," { $$ = NULL; }
1657 /* JavaScript 1.7: Array Comprehensions {{{ */
1659 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1663 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1664 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
1668 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1671 ComprehensionListOpt
1672 : ComprehensionList { $$ = $1; }
1673 | IfComprehension { $$ = $1; }
1678 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1681 /* JavaScript 1.7: for each {{{ */
1683 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
1686 /* JavaScript 1.7: let Statements {{{ */
1688 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1696 /* JavaScript FTW: Ruby Blocks {{{ */
1697 RubyProcParameterList_
1698 : "," RubyProcParameterList { $$ = $2; }
1702 RubyProcParameterList
1703 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1708 : "|" RubyProcParameterList "|" { $$ = $2; }
1709 | "||" { $$ = NULL; }
1712 RubyProcParametersOpt
1713 : RubyProcParameters
1718 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1722 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1726 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }