]> git.saurik.com Git - cycript.git/blame_incremental - Cycript.yy.in
Remove AssignmentExpression_: merge to parent.
[cycript.git] / Cycript.yy.in
... / ...
CommitLineData
1/* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
3*/
4
5/* GNU Lesser General Public License, Version 3 {{{ */
6/*
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.
11 *
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.
16 *
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/>.
19**/
20/* }}} */
21
22@if Bison23 %{
23
24@if Bison24 %code top {
25#define cyscanner driver.scanner_
26#define YYSTACKEXPANDABLE 1
27@if Bison23 #define yyerrok (yyerrstatus_ = 0)
28@if Bison24 }
29
30@if Bison24 %code requires {
31#include "Parser.hpp"
32#define CYNew new($pool)
33
34@begin ObjectiveC
35#include "ObjectiveC/Syntax.hpp"
36@end
37
38@begin E4X
39#include "E4X/Syntax.hpp"
40@end
41
42typedef struct {
43 bool newline_;
44
45 union {
46 bool bool_;
47
48 CYDriver::Condition condition_;
49
50 CYArgument *argument_;
51 CYAssignment *assignment_;
52 CYBoolean *boolean_;
53 CYClause *clause_;
54 cy::Syntax::Catch *catch_;
55 CYComment *comment_;
56 CYComprehension *comprehension_;
57 CYCompound *compound_;
58 CYDeclaration *declaration_;
59 CYDeclarations *declarations_;
60 CYElement *element_;
61 CYExpression *expression_;
62 CYFalse *false_;
63 CYFinally *finally_;
64 CYForInitialiser *for_;
65 CYForInInitialiser *forin_;
66 CYFunctionParameter *functionParameter_;
67 CYIdentifier *identifier_;
68 CYInfix *infix_;
69 CYLiteral *literal_;
70 CYMember *member_;
71 CYNull *null_;
72 CYNumber *number_;
73 CYProgram *program_;
74 CYProperty *property_;
75 CYPropertyName *propertyName_;
76 CYRubyProc *rubyProc_;
77 CYStatement *statement_;
78 CYString *string_;
79 CYThis *this_;
80 CYTrue *true_;
81 CYWord *word_;
82
83@begin ObjectiveC
84 CYClassName *className_;
85 CYField *field_;
86 CYMessage *message_;
87 CYMessageParameter *messageParameter_;
88 CYProtocol *protocol_;
89 CYSelectorPart *selector_;
90@end
91
92@begin E4X
93 CYAttribute *attribute_;
94 CYPropertyIdentifier *propertyIdentifier_;
95 CYSelector *selector_;
96@end
97 };
98} YYSTYPE;
99
100#define YYSTYPE YYSTYPE
101@if Bison24 }
102
103@if Bison24 %code provides {
104int cylex(YYSTYPE *, cy::location *, void *);
105@if Bison24 }
106
107@if Bison23 %}
108
109%name-prefix="cy"
110
111@if Bison23 %skeleton "lalr1.cc"
112@if Bison24 %language "C++"
113
114%initial-action {
115 @$.begin.filename = @$.end.filename = &driver.filename_;
116};
117
118%locations
119%defines
120
121//%glr-parser
122//%expect 1
123
124%error-verbose
125
126%parse-param { CYDriver &driver }
127%lex-param { void *cyscanner }
128
129@begin E4X
130%token XMLCDATA
131%token XMLComment
132%token XMLPI
133
134%token XMLAttributeValue
135%token XMLName
136%token XMLTagCharacters
137%token XMLText
138%token XMLWhitespace
139@end
140
141@begin E4X
142%token LeftRight "<>"
143%token LeftSlashRight "</>"
144
145%token SlashRight "/>"
146%token LeftSlash "</"
147
148%token ColonColon "::"
149%token PeriodPeriod ".."
150@end
151
152@begin E4X ObjectiveC
153%token At "@"
154@end
155
156%token Ampersand "&"
157%token AmpersandAmpersand "&&"
158%token AmpersandEqual "&="
159%token Carrot "^"
160%token CarrotEqual "^="
161%token Equal "="
162%token EqualEqual "=="
163%token EqualEqualEqual "==="
164%token Exclamation "!"
165%token ExclamationEqual "!="
166%token ExclamationEqualEqual "!=="
167%token Hyphen "-"
168%token HyphenEqual "-="
169%token HyphenHyphen "--"
170%token HyphenHyphen_ "\n--"
171%token HyphenRight "->"
172%token Left "<"
173%token LeftEqual "<="
174%token LeftLeft "<<"
175%token LeftLeftEqual "<<="
176%token Percent "%"
177%token PercentEqual "%="
178%token Period "."
179%token PeriodPeriodPeriod "..."
180%token Pipe "|"
181%token PipeEqual "|="
182%token PipePipe "||"
183%token Plus "+"
184%token PlusEqual "+="
185%token PlusPlus "++"
186%token PlusPlus_ "\n++"
187%token Right ">"
188%token RightEqual ">="
189%token RightRight ">>"
190%token RightRightEqual ">>="
191%token RightRightRight ">>>"
192%token RightRightRightEqual ">>>="
193%token Slash "/"
194%token SlashEqual "/="
195%token Star "*"
196%token StarEqual "*="
197%token Tilde "~"
198
199%token Colon ":"
200%token Comma ","
201%token Question "?"
202%token SemiColon ";"
203%token NewLine "\n"
204
205%token <comment_> Comment
206
207%token OpenParen "("
208%token CloseParen ")"
209
210%token OpenBrace "{"
211%token OpenBrace_ "\n{"
212%token OpenBrace__ ";{"
213%token CloseBrace "}"
214
215%token OpenBracket "["
216%token CloseBracket "]"
217
218@begin Java
219%token AtClass "@class"
220@end
221
222@begin ObjectiveC
223%token AtImplementation "@implementation"
224%token AtImplementation_ ";@implementation"
225%token AtImport "@import"
226%token AtEnd "@end"
227%token AtSelector "@selector"
228@end
229
230%token <false_> False "false"
231%token <null_> Null "null"
232%token <true_> True "true"
233
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"
262
263// ES3/IE6 Future, ES5/JSC Reserved
264%token <word_> Debugger "debugger"
265
266// ES3/ES5/IE6 Future, JSC Reserved
267%token <word_> Const "const"
268
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"
276
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"
285
286// ES3 Future
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"
303
304// ES5 Strict
305%token <identifier_> Let "let"
306%token <identifier_> Yield "yield"
307
308// Woah?!
309%token <identifier_> Each "each"
310
311@begin E4X
312// E4X Conditional
313%token <identifier_> Namespace "namespace"
314%token <identifier_> XML "xml"
315@end
316
317%token AutoComplete
318
319%token <identifier_> Identifier_
320%token <number_> NumericLiteral
321%token <string_> StringLiteral
322%token <literal_> RegularExpressionLiteral
323
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 <expression_> RelationalExpression
416%type <statement_> ReturnStatement
417%type <rubyProc_> RubyProcExpression
418%type <functionParameter_> RubyProcParameterList_
419%type <functionParameter_> RubyProcParameterList
420%type <functionParameter_> RubyProcParameters
421%type <functionParameter_> RubyProcParametersOpt
422%type <expression_> ShiftExpression
423%type <declaration_> SingleNameBinding
424%type <statement_> Statement__
425%type <statement_> Statement_
426%type <statement_> Statement
427%type <statement_> StatementList
428%type <statement_> StatementListOpt
429%type <statement_> StatementListItem
430%type <statement_> SwitchStatement
431%type <statement_> ThrowStatement
432%type <statement_> TryStatement
433%type <expression_> UnaryExpression_
434%type <expression_> UnaryExpression
435%type <declaration_> VariableDeclaration
436%type <declarations_> VariableDeclarationList_
437%type <declarations_> VariableDeclarationList
438%type <statement_> VariableStatement
439%type <statement_> WhileStatement
440%type <statement_> WithStatement
441
442@begin ObjectiveC
443%type <statement_> CategoryStatement
444%type <expression_> ClassExpression
445%type <statement_> ClassStatement
446%type <expression_> ClassSuperOpt
447%type <field_> ClassFieldList
448%type <message_> ClassMessageDeclaration
449%type <message_> ClassMessageDeclarationListOpt
450%type <className_> ClassName
451%type <className_> ClassNameOpt
452%type <protocol_> ClassProtocolListOpt
453%type <protocol_> ClassProtocols
454%type <protocol_> ClassProtocolsOpt
455%type <expression_> MessageExpression
456%type <messageParameter_> MessageParameter
457%type <messageParameter_> MessageParameters
458%type <messageParameter_> MessageParameterList
459%type <messageParameter_> MessageParameterListOpt
460%type <bool_> MessageScope
461%type <argument_> SelectorCall_
462%type <argument_> SelectorCall
463%type <selector_> SelectorExpression_
464%type <selector_> SelectorExpression
465%type <selector_> SelectorExpressionOpt
466%type <argument_> SelectorList
467%type <word_> SelectorWordOpt
468%type <expression_> TypeOpt
469%type <argument_> VariadicCall
470%type <word_> Word
471%type <word_> WordOpt
472@end
473
474@begin E4X
475%type <propertyIdentifier_> PropertyIdentifier_
476%type <selector_> PropertySelector_
477%type <selector_> PropertySelector
478%type <identifier_> QualifiedIdentifier_
479%type <identifier_> QualifiedIdentifier
480%type <identifier_> WildcardIdentifier
481%type <identifier_> XMLComment
482%type <identifier_> XMLCDATA
483%type <identifier_> XMLElement
484%type <identifier_> XMLElementContent
485%type <identifier_> XMLMarkup
486%type <identifier_> XMLPI
487
488%type <attribute_> AttributeIdentifier
489/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
490%type <expression_> PropertyIdentifier
491%type <expression_> XMLListInitialiser
492%type <expression_> XMLInitialiser
493@end
494
495%nonassoc ""
496%left "++" "--"
497
498%nonassoc "if"
499%nonassoc "else"
500
501%start Program
502
503%%
504
505/* Lexer State {{{ */
506LexPushInOn
507 : { driver.in_.push(true); }
508 ;
509
510LexPushInOff
511 : { driver.in_.push(false); }
512 ;
513
514LexPopIn
515 : { driver.in_.pop(); }
516 ;
517
518LexSetRegExp
519 : { driver.SetCondition(CYDriver::RegExpCondition); }
520 ;
521
522LexSetStatement
523 : { switch (yychar) {
524 case token::Function:
525 yychar = token::Function_;
526 break;
527
528 case token::OpenBrace:
529 case token::OpenBrace_:
530 yychar = token::OpenBrace__;
531 break;
532 } }
533 ;
534/* }}} */
535
536BRACE
537 : "{"
538 | "\n{"
539 ;
540
541StrictSemi
542 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
543 ;
544
545Terminator_
546 : ";"
547 | "\n" StrictSemi
548 ;
549
550Terminator
551 : Terminator_
552 | error { if (yychar != 0 && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
553 ;
554
555TerminatorOpt
556 : Terminator_
557 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
558 ;
559
560/*CommaOpt
561 : ","
562 |
563 ;*/
564
565@begin ObjectiveC
566NewLineOpt
567 : "\n"
568 |
569 ;
570
571Word
572 : Identifier { $$ = $1; }
573 | "break" NewLineOpt { $$ = $1; }
574 | "case" { $$ = $1; }
575 | "catch" { $$ = $1; }
576 | "class" { $$ = $1; }
577 | "const" { $$ = $1; }
578 | "continue" NewLineOpt { $$ = $1; }
579 | "debugger" { $$ = $1; }
580 | "default" { $$ = $1; }
581 | "delete" { $$ = $1; }
582 | "do" { $$ = $1; }
583 | "else" { $$ = $1; }
584 | "enum" { $$ = $1; }
585 | "export" { $$ = $1; }
586 | "extends" { $$ = $1; }
587 | "false" { $$ = $1; }
588 | "finally" { $$ = $1; }
589 /* XXX: | "for" { $$ = $1; } */
590 | "function" { $$ = $1; }
591 | "if" { $$ = $1; }
592 | "import" { $$ = $1; }
593 /* XXX: | "in" { $$ = $1; } */
594 /* XXX: | "instanceof" { $$ = $1; } */
595 | "new" { $$ = $1; }
596 | "null" { $$ = $1; }
597 | "return" NewLineOpt { $$ = $1; }
598 | "super" { $$ = $1; }
599 | "switch" { $$ = $1; }
600 | "this" { $$ = $1; }
601 | "throw" NewLineOpt { $$ = $1; }
602 | "true" { $$ = $1; }
603 | "try" { $$ = $1; }
604 | "typeof" { $$ = $1; }
605 | "var" { $$ = $1; }
606 | "void" { $$ = $1; }
607 | "while" { $$ = $1; }
608 | "with" { $$ = $1; }
609 ;
610
611WordOpt
612 : Word { $$ = $1; }
613 | { $$ = NULL; }
614 ;
615
616PrimaryExpression
617 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
618 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
619 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
620 | "@" Parenthetical { $$ = CYNew CYBox($2); }
621 ;
622@end
623
624Identifier
625 : Identifier_ { $$ = $1; }
626
627 | "implements" { $$ = $1; }
628 | "interface" { $$ = $1; }
629 | "package" { $$ = $1; }
630 | "private" { $$ = $1; }
631 | "protected" { $$ = $1; }
632 | "public" { $$ = $1; }
633 | "static" { $$ = $1; }
634
635 | "abstract" { $$ = $1; }
636 | "boolean" { $$ = $1; }
637 | "byte" { $$ = $1; }
638 | "char" { $$ = $1; }
639 | "double" { $$ = $1; }
640 | "final" { $$ = $1; }
641 | "float" { $$ = $1; }
642 | "goto" { $$ = $1; }
643 | "int" { $$ = $1; }
644 | "long" { $$ = $1; }
645 | "native" { $$ = $1; }
646 | "short" { $$ = $1; }
647 | "synchronized" { $$ = $1; }
648 | "throws" { $$ = $1; }
649 | "transient" { $$ = $1; }
650 | "volatile" { $$ = $1; }
651
652 // XXX: is this allowed?! | "let" { $$ = $1; }
653 | "yield" { $$ = $1; }
654
655 | "each" { $$ = $1; }
656 ;
657
658IdentifierOpt
659 : Identifier { $$ = $1; }
660 | { $$ = NULL; }
661 ;
662
663LiteralNoRE
664 : NullLiteral { $$ = $1; }
665 | BooleanLiteral { $$ = $1; }
666 | NumericLiteral { $$ = $1; }
667 | StringLiteral { $$ = $1; }
668 ;
669
670Literal
671 : LiteralNoRE { $$ = $1; }
672 | RegularExpressionLiteral { $$ = $1; }
673 ;
674
675NullLiteral
676 : "null" { $$ = $1; }
677 ;
678
679BooleanLiteral
680 : "true" { $$ = $1; }
681 | "false" { $$ = $1; }
682 ;
683
684/* 11.1 Primary Expressions {{{ */
685Parenthetical
686 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
687 ;
688
689PrimaryExpression
690 : "this" { $$ = $1; }
691 | Identifier { $$ = CYNew CYVariable($1); }
692 | Literal { $$ = $1; }
693 | ArrayLiteral { $$ = $1; }
694 | ObjectLiteral { $$ = $1; }
695 | FunctionExpression { $$ = $1; }
696 | Parenthetical { $$ = $1; }
697 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
698 ;
699/* }}} */
700/* 11.1.4.1 Array Initialiser {{{ */
701ArrayLiteral
702 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
703 ;
704
705Element
706 : AssignmentExpression { $$ = $1; }
707 ;
708
709ElementOpt
710 : Element { $$ = $1; }
711 | LexSetRegExp { $$ = NULL; }
712 ;
713
714ElementList
715 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
716 | Element { $$ = CYNew CYElement($1, NULL); }
717 ;
718
719ElementListOpt
720 : ElementList { $$ = $1; }
721 | LexSetRegExp { $$ = NULL; }
722 ;
723/* }}} */
724/* 11.1.5 Object Initialiser {{{ */
725ObjectLiteral
726 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
727 ;
728
729PropertyNameAndValueList_
730 : "," PropertyNameAndValueList { $$ = $2; }
731 | { $$ = NULL; }
732 ;
733
734PropertyNameAndValueList
735 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
736 ;
737
738PropertyNameAndValueListOpt
739 : PropertyNameAndValueList { $$ = $1; }
740 | { $$ = NULL; }
741 ;
742
743PropertyName_
744 : Identifier { $$ = $1; }
745 | StringLiteral { $$ = $1; }
746 | NumericLiteral { $$ = $1; }
747 ;
748
749PropertyName
750 : LexSetRegExp PropertyName_ { $$ = $2; }
751 ;
752/* }}} */
753
754/* 11.2 Left-Hand-Side Expressions {{{ */
755MemberAccess
756 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
757 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
758 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
759 ;
760
761MemberExpression_
762 : MemberExpression { $$ = $1; }
763 //| "super" { $$ = $1; }
764 ;
765
766MemberExpression
767 : LexSetRegExp PrimaryExpression { $$ = $2; }
768 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
769 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
770 ;
771
772NewExpression
773 : MemberExpression { $$ = $1; }
774 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
775 ;
776
777CallExpression_
778 : MemberExpression_
779 | CallExpression
780 ;
781
782CallExpression
783 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
784 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
785 ;
786
787Arguments
788 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
789 ;
790
791ArgumentList_
792 : "," ArgumentList { $$ = $2; }
793 | { $$ = NULL; }
794 ;
795
796ArgumentList
797 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
798 ;
799
800ArgumentListOpt
801 : ArgumentList { $$ = $1; }
802 | LexSetRegExp { $$ = NULL; }
803 ;
804
805LeftHandSideExpression
806 : NewExpression { $$ = $1; }
807 | CallExpression { $$ = $1; }
808 ;
809/* }}} */
810/* 11.3 Postfix Expressions {{{ */
811PostfixExpression
812 : %prec "" LeftHandSideExpression { $$ = $1; }
813 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
814 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
815 ;
816/* }}} */
817/* 11.4 Unary Operators {{{ */
818UnaryExpression_
819 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
820 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
821 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
822 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
823 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
824 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
825 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
826 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
827 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
828 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
829 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
830 ;
831
832UnaryExpression
833 : PostfixExpression { $$ = $1; }
834 | LexSetRegExp UnaryExpression_ { $$ = $2; }
835 ;
836/* }}} */
837/* 11.5 Multiplicative Operators {{{ */
838MultiplicativeExpression
839 : UnaryExpression { $$ = $1; }
840 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
841 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
842 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
843 ;
844/* }}} */
845/* 11.6 Additive Operators {{{ */
846AdditiveExpression
847 : MultiplicativeExpression { $$ = $1; }
848 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
849 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
850 ;
851/* }}} */
852/* 11.7 Bitwise Shift Operators {{{ */
853ShiftExpression
854 : AdditiveExpression { $$ = $1; }
855 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
856 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
857 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
858 ;
859/* }}} */
860/* 11.8 Relational Operators {{{ */
861RelationalExpression_
862 : ShiftExpression { $$ = $1; }
863 ;
864
865RelationalExpression
866 : RelationalExpression_ { $$ = $1; }
867 | RelationalExpression "<" RelationalExpression_ { $$ = CYNew CYLess($1, $3); }
868 | RelationalExpression ">" RelationalExpression_ { $$ = CYNew CYGreater($1, $3); }
869 | RelationalExpression "<=" RelationalExpression_ { $$ = CYNew CYLessOrEqual($1, $3); }
870 | RelationalExpression ">=" RelationalExpression_ { $$ = CYNew CYGreaterOrEqual($1, $3); }
871 | RelationalExpression "instanceof" RelationalExpression_ { $$ = CYNew CYInstanceOf($1, $3); }
872 | RelationalExpression "in" RelationalExpression_ { $$ = CYNew CYIn($1, $3); }
873 ;
874/* }}} */
875/* 11.9 Equality Operators {{{ */
876EqualityExpression
877 : RelationalExpression { $$ = $1; }
878 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
879 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
880 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
881 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
882 ;
883/* }}} */
884/* 11.10 Binary Bitwise Operators {{{ */
885BitwiseANDExpression
886 : EqualityExpression { $$ = $1; }
887 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
888 ;
889
890BitwiseXORExpression
891 : BitwiseANDExpression { $$ = $1; }
892 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
893 ;
894
895BitwiseORExpression
896 : BitwiseXORExpression { $$ = $1; }
897 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
898 ;
899/* }}} */
900/* 11.11 Binary Logical Operators {{{ */
901LogicalANDExpression
902 : BitwiseORExpression { $$ = $1; }
903 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
904 ;
905
906LogicalORExpression
907 : LogicalANDExpression { $$ = $1; }
908 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
909 ;
910/* }}} */
911/* 11.12 Conditional Operator ( ? : ) {{{ */
912ConditionalExpression
913 : LogicalORExpression { $$ = $1; }
914 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
915 ;
916/* }}} */
917/* 11.13 Assignment Operators {{{ */
918AssignmentExpression
919 : ConditionalExpression { $$ = $1; }
920 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
921 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
922 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
923 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
924 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
925 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
926 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
927 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
928 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
929 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
930 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
931 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
932 ;
933/* }}} */
934/* 11.14 Comma Operator {{{ */
935Expression_
936 : "," Expression { $$ = CYNew CYCompound($2); }
937 | { $$ = NULL; }
938 ;
939
940Expression
941 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
942 ;
943
944ExpressionOpt
945 : Expression { $$ = $1; }
946 | LexSetRegExp { $$ = NULL; }
947 ;
948/* }}} */
949
950/* 12 Statements {{{ */
951Statement__
952 : Block { $$ = $1; }
953 | VariableStatement { $$ = $1; }
954 | EmptyStatement { $$ = $1; }
955 | IfStatement { $$ = $1; }
956 | BreakableStatement { $$ = $1; }
957 | ContinueStatement { $$ = $1; }
958 | BreakStatement { $$ = $1; }
959 | ReturnStatement { $$ = $1; }
960 | WithStatement { $$ = $1; }
961 | LabelledStatement { $$ = $1; }
962 | ThrowStatement { $$ = $1; }
963 | TryStatement { $$ = $1; }
964 | DebuggerStatement { $$ = $1; }
965 ;
966
967Statement_
968 : LexSetRegExp Statement__ { $$ = $2; }
969 | ExpressionStatement { $$ = $1; }
970 ;
971
972Statement
973 : LexSetStatement Statement_ { $$ = $2; }
974 ;
975
976Declaration__
977 : FunctionDeclaration { $$ = $1; }
978 | LexicalDeclaration { $$ = $1; }
979 ;
980
981Declaration_
982 : LexSetRegExp Declaration__ { $$ = $2; }
983 ;
984
985Declaration
986 : LexSetStatement Declaration_ { $$ = $2; }
987 ;
988
989BreakableStatement
990 : IterationStatement { $$ = $1; }
991 | SwitchStatement { $$ = $1; }
992 ;
993/* }}} */
994/* 12.1 Block {{{ */
995Block_
996 : BRACE StatementListOpt "}" { $$ = $2; }
997 ;
998
999Block
1000 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1001 ;
1002
1003StatementList
1004 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1005 ;
1006
1007StatementListOpt
1008 : StatementList { $$ = $1; }
1009 | LexSetRegExp { $$ = NULL; }
1010 ;
1011
1012StatementListItem
1013 : Statement { $$ = $1; }
1014 | Declaration { $$ = $1; }
1015 ;
1016/* }}} */
1017/* 12.2 Declarations {{{ */
1018BindingIdentifier
1019 : Identifier { $$ = $1; }
1020 ;
1021
1022// XXX: BindingPattern
1023/* }}} */
1024/* 12.2.1 Let and Const Declarations {{{ */
1025LexicalDeclaration
1026 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1027 ;
1028
1029LetOrConst
1030 : "let"
1031 | "const"
1032 ;
1033/* }}} */
1034/* 12.2.2 Variable Statement {{{ */
1035VariableStatement
1036 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1037 ;
1038
1039VariableDeclarationList_
1040 : "," VariableDeclarationList { $$ = $2; }
1041 | { $$ = NULL; }
1042 ;
1043
1044VariableDeclarationList
1045 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1046 ;
1047
1048VariableDeclaration
1049 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1050 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1051 ;
1052
1053Initialiser
1054 : "=" AssignmentExpression { $$ = $2; }
1055 ;
1056
1057InitialiserOpt
1058 : Initialiser { $$ = $1; }
1059 | { $$ = NULL; }
1060 ;
1061/* }}} */
1062/* 12.2.4 Destructuring Binding Patterns {{{ */
1063// XXX: *
1064
1065BindingElement
1066 : SingleNameBinding { $$ = $1; }
1067 ;
1068
1069SingleNameBinding
1070 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1071 ;
1072/* }}} */
1073/* 12.3 Empty Statement {{{ */
1074EmptyStatement
1075 : ";" { $$ = CYNew CYEmpty(); }
1076 ;
1077/* }}} */
1078/* 12.4 Expression Statement {{{ */
1079ExpressionStatement
1080 : Expression Terminator { $$ = CYNew CYExpress($1); }
1081 ;
1082/* }}} */
1083/* 12.5 The if Statement {{{ */
1084ElseStatementOpt
1085 : "else" Statement { $$ = $2; }
1086 | %prec "if" { $$ = NULL; }
1087 ;
1088
1089IfStatement
1090 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1091 ;
1092/* }}} */
1093
1094/* 12.6 Iteration Statements {{{ */
1095IterationStatement
1096 : DoWhileStatement { $$ = $1; }
1097 | WhileStatement { $$ = $1; }
1098 | ForStatement { $$ = $1; }
1099 | ForInStatement { $$ = $1; }
1100 ;
1101/* }}} */
1102/* 12.6.1 The do-while Statement {{{ */
1103DoWhileStatement
1104 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1105 ;
1106/* }}} */
1107/* 12.6.2 The while Statement {{{ */
1108WhileStatement
1109 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1110 ;
1111/* }}} */
1112/* 12.6.3 The for Statement {{{ */
1113ForStatement
1114 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1115 ;
1116
1117ForStatementInitialiser
1118 : ExpressionOpt { $$ = $1; }
1119 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1120 ;
1121/* }}} */
1122/* 12.6.4 The for-in Statement {{{ */
1123ForInStatement
1124 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1125 ;
1126
1127ForInStatementInitialiser
1128 : LeftHandSideExpression { $$ = $1; }
1129 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1130 ;
1131/* }}} */
1132
1133/* 12.7 The continue Statement {{{ */
1134ContinueStatement
1135 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1136 ;
1137/* }}} */
1138/* 12.8 The break Statement {{{ */
1139BreakStatement
1140 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1141 ;
1142/* }}} */
1143/* 12.9 The return Statement {{{ */
1144ReturnStatement
1145 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1146 ;
1147/* }}} */
1148/* 12.10 The with Statement {{{ */
1149WithStatement
1150 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1151 ;
1152/* }}} */
1153
1154/* 12.11 The switch Statement {{{ */
1155SwitchStatement
1156 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1157 ;
1158
1159CaseBlock
1160 : BRACE CaseClausesOpt "}" { $$ = $2; }
1161 ;
1162
1163CaseClause
1164 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1165 ;
1166
1167CaseClausesOpt
1168 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1169 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1170 | { $$ = NULL; }
1171 ;
1172
1173DefaultClause
1174 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1175 ;
1176/* }}} */
1177/* 12.12 Labelled Statements {{{ */
1178LabelledStatement
1179 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1180 ;
1181/* }}} */
1182/* 12.13 The throw Statement {{{ */
1183ThrowStatement
1184 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1185 ;
1186/* }}} */
1187/* 12.14 The try Statement {{{ */
1188TryStatement
1189 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1190 ;
1191
1192CatchOpt
1193 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1194 | { $$ = NULL; }
1195 ;
1196
1197FinallyOpt
1198 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1199 | { $$ = NULL; }
1200 ;
1201/* }}} */
1202/* 12.14 The debugger Statement {{{ */
1203DebuggerStatement
1204 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1205 ;
1206/* }}} */
1207
1208/* 13 Function Definition {{{ */
1209FunctionDeclaration
1210 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1211 ;
1212
1213FunctionExpression
1214 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1215 ;
1216
1217FormalParameterList_
1218 : "," FormalParameterList { $$ = $2; }
1219 | { $$ = NULL; }
1220 ;
1221
1222FormalParameterList
1223 // XXX: : FunctionRestParameter { $$ = $1; }
1224 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1225 ;
1226
1227FormalParameterListOpt
1228 : FormalParameterList
1229 | { $$ = NULL; }
1230 ;
1231
1232/* XXX: FunctionRestParameter
1233 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1234 ;*/
1235
1236FormalParameter
1237 : BindingElement { $$ = $1; }
1238 ;
1239
1240FunctionBody
1241 : StatementListOpt { $$ = $1; }
1242 ;
1243/* }}} */
1244/* 14 Program {{{ */
1245Program
1246 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1247 ;
1248
1249ProgramBody
1250 : StatementList { $$ = $1; }
1251 ;
1252
1253ProgramBodyOpt
1254 : ProgramBody { $$ = $1; }
1255 | { $$ = NULL; }
1256 ;
1257/* }}} */
1258
1259@begin ObjectiveC
1260/* Cycript (Objective-C): @class Declaration {{{ */
1261ClassSuperOpt
1262 /* XXX: why the hell did I choose MemberExpression? */
1263 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1264 | { $$ = NULL; }
1265 ;
1266
1267ClassField
1268 : Expression Identifier ";"
1269 ;
1270
1271ClassFieldList
1272 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1273 ;
1274
1275ClassFieldListOpt
1276 : ClassFieldListOpt ClassField
1277 |
1278 ;
1279
1280MessageScope
1281 : "+" { $$ = false; }
1282 | "-" { $$ = true; }
1283 ;
1284
1285TypeOpt
1286 : "(" Expression ")" { $$ = $2; }
1287 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1288 | { $$ = NULL; }
1289 ;
1290
1291MessageParameter
1292 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1293 ;
1294
1295MessageParameterList
1296 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1297 ;
1298
1299MessageParameterListOpt
1300 : MessageParameterList { $$ = $1; }
1301 | { $$ = NULL; }
1302 ;
1303
1304MessageParameters
1305 : MessageParameterList { $$ = $1; }
1306 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1307 ;
1308
1309ClassMessageDeclaration
1310 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1311 ;
1312
1313ClassMessageDeclarationListOpt
1314 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1315 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1316 | { $$ = NULL; }
1317 ;
1318
1319ClassName
1320 : Identifier { $$ = $1; }
1321 | "(" AssignmentExpression ")" { $$ = $2; }
1322 ;
1323
1324ClassNameOpt
1325 : ClassName { $$ = $1; }
1326 | { $$ = NULL; }
1327 ;
1328
1329// XXX: this should be AssignmentExpressionNoRight
1330ClassProtocols
1331 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1332 ;
1333
1334ClassProtocolsOpt
1335 : "," ClassProtocols { $$ = $2; }
1336 | { $$ = NULL; }
1337 ;
1338
1339ClassProtocolListOpt
1340 : "<" ClassProtocols ">" { $$ = $2; }
1341 | { $$ = NULL; }
1342 ;
1343
1344ClassExpression
1345 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1346 ;
1347
1348ClassStatement
1349 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1350 ;
1351
1352CategoryName
1353 : "(" WordOpt ")"
1354 ;
1355
1356CategoryStatement
1357 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1358 ;
1359
1360PrimaryExpression
1361 : ClassExpression { $$ = $1; }
1362 ;
1363
1364Statement__
1365 : ClassStatement { $$ = $1; }
1366 | CategoryStatement { $$ = $1; }
1367 ;
1368/* }}} */
1369/* Cycript (Objective-C): Send Message {{{ */
1370VariadicCall
1371 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1372 | { $$ = NULL; }
1373 ;
1374
1375SelectorWordOpt
1376 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1377 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1378 ;
1379
1380SelectorCall_
1381 : SelectorCall { $$ = $1; }
1382 | VariadicCall { $$ = $1; }
1383 ;
1384
1385SelectorCall
1386 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1387 ;
1388
1389SelectorList
1390 : SelectorCall { $$ = $1; }
1391 | Word { $$ = CYNew CYArgument($1, NULL); }
1392 ;
1393
1394MessageExpression
1395 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1396 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1397 ;
1398
1399SelectorExpression_
1400 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1401 ;
1402
1403SelectorExpression
1404 : SelectorExpression_ { $$ = $1; }
1405 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1406 ;
1407
1408SelectorExpressionOpt
1409 : SelectorExpression_ { $$ = $1; }
1410 | { $$ = NULL; }
1411 ;
1412
1413PrimaryExpression
1414 : MessageExpression { $$ = $1; }
1415 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1416 ;
1417/* }}} */
1418/* Cycript (Objective-C): @import Directive {{{ */
1419PathName
1420 : "/" PathName
1421 | "." PathName
1422 | Word PathName
1423 |
1424 ;
1425
1426ImportPath
1427 : "<" PathName ">"
1428 | StringLiteral
1429 ;
1430
1431StatementListItem
1432 : "@import" ImportPath { $$ = CYNew CYImport(); }
1433 ;
1434/* }}} */
1435@end
1436
1437@begin C
1438/* Cycript (C): Pointer Indirection/Addressing {{{ */
1439LeftHandSideExpression
1440 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1441 ;
1442
1443UnaryExpression_
1444 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1445 ;
1446
1447MemberAccess
1448 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1449 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1450 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1451 ;
1452/* }}} */
1453@end
1454
1455/* YUI: Documentation Comments {{{ */
1456Statement__
1457 : Comment { $$ = $1; }
1458 ;
1459/* }}} */
1460
1461@begin E4X
1462/* Lexer State {{{ */
1463LexPushRegExp
1464 : { driver.PushCondition(CYDriver::RegExpCondition); }
1465 ;
1466
1467LexPushXMLContent
1468 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1469 ;
1470
1471LexPushXMLTag
1472 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1473 ;
1474
1475LexPop
1476 : { driver.PopCondition(); }
1477 ;
1478
1479LexSetXMLContent
1480 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1481 ;
1482
1483LexSetXMLTag
1484 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1485 ;
1486/* }}} */
1487
1488XMLWhitespaceOpt
1489 : XMLWhitespace
1490 |
1491 ;
1492
1493/* 8.1 Context Keywords {{{ */
1494Identifier
1495 : "namespace" { $$ = $1; }
1496 | "xml" { $$ = $1; }
1497 ;
1498/* }}} */
1499/* 8.3 XML Initialiser Input Elements {{{ */
1500XMLMarkup
1501 : XMLComment { $$ = $1; }
1502 | XMLCDATA { $$ = $1; }
1503 | XMLPI { $$ = $1; }
1504 ;
1505/* }}} */
1506/* 11.1 Primary Expressions {{{ */
1507PrimaryExpression
1508 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1509 | XMLInitialiser { $$ = $1; }
1510 | XMLListInitialiser { $$ = $1; }
1511 ;
1512
1513PropertyIdentifier
1514 : AttributeIdentifier { $$ = $1; }
1515 | QualifiedIdentifier { $$ = $1; }
1516 | WildcardIdentifier { $$ = $1; }
1517 ;
1518/* }}} */
1519/* 11.1.1 Attribute Identifiers {{{ */
1520AttributeIdentifier
1521 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1522 ;
1523
1524PropertySelector_
1525 : PropertySelector { $$ = $1; }
1526 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1527 ;
1528
1529PropertySelector
1530 : Identifier { $$ = CYNew CYSelector($1); }
1531 | WildcardIdentifier { $$ = $1; }
1532 ;
1533/* }}} */
1534/* 11.1.2 Qualified Identifiers {{{ */
1535QualifiedIdentifier_
1536 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1537 | QualifiedIdentifier { $$ = $1; }
1538 ;
1539
1540QualifiedIdentifier
1541 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1542 ;
1543/* }}} */
1544/* 11.1.3 Wildcard Identifiers {{{ */
1545WildcardIdentifier
1546 : "*" { $$ = CYNew CYWildcard(); }
1547 ;
1548/* }}} */
1549/* 11.1.4 XML Initialiser {{{ */
1550XMLInitialiser
1551 : XMLMarkup { $$ = $1; }
1552 | XMLElement { $$ = $1; }
1553 ;
1554
1555XMLElement
1556 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1557 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1558 ;
1559
1560XMLTagContent
1561 : LexPushXMLTag XMLTagName XMLAttributes
1562 ;
1563
1564XMLExpression
1565 : BRACE LexPushRegExp Expression LexPop "}"
1566 ;
1567
1568XMLTagName
1569 : XMLExpression
1570 | XMLName
1571 ;
1572
1573XMLAttributes_
1574 : XMLAttributes_ XMLAttribute
1575 |
1576 ;
1577
1578XMLAttributes
1579 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1580 | XMLAttributes_ XMLWhitespaceOpt
1581 ;
1582
1583XMLAttributeValue_
1584 : XMLExpression
1585 | XMLAttributeValue
1586 ;
1587
1588XMLAttribute
1589 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1590 ;
1591
1592XMLElementContent
1593 : XMLExpression XMLElementContentOpt
1594 | XMLMarkup XMLElementContentOpt
1595 | XMLText XMLElementContentOpt
1596 | XMLElement XMLElementContentOpt
1597 ;
1598
1599XMLElementContentOpt
1600 : XMLElementContent
1601 |
1602 ;
1603/* }}} */
1604/* 11.1.5 XMLList Initialiser {{{ */
1605XMLListInitialiser
1606 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1607 ;
1608/* }}} */
1609/* 11.2 Left-Hand-Side Expressions {{{ */
1610PropertyIdentifier_
1611 : Identifier { $$ = $1; }
1612 | PropertyIdentifier { $$ = $1; }
1613 ;
1614
1615MemberAccess
1616 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1617 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1618 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1619 ;
1620/* }}} */
1621/* 12.1 The default xml namespace Statement {{{ */
1622/* XXX: DefaultXMLNamespaceStatement
1623 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1624 ;
1625
1626Statement__
1627 : DefaultXMLNamespaceStatement { $$ = $1; }
1628 ; */
1629/* }}} */
1630@end
1631
1632/* ECMAScript5: Object Literal Trailing Comma {{{ */
1633PropertyNameAndValueList_
1634 : "," { $$ = NULL; }
1635 ;
1636/* }}} */
1637
1638/* JavaScript 1.7: Array Comprehensions {{{ */
1639IfComprehension
1640 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1641 ;
1642
1643ForComprehension
1644 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1645 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
1646 ;
1647
1648ComprehensionList
1649 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1650 ;
1651
1652ComprehensionListOpt
1653 : ComprehensionList { $$ = $1; }
1654 | IfComprehension { $$ = $1; }
1655 | { $$ = NULL; }
1656 ;
1657
1658PrimaryExpression
1659 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1660 ;
1661/* }}} */
1662/* JavaScript 1.7: for each {{{ */
1663ForInStatement
1664 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
1665 ;
1666/* }}} */
1667/* JavaScript 1.7: let Statements {{{ */
1668LetStatement
1669 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1670 ;
1671
1672Statement__
1673 : LetStatement
1674 ;
1675/* }}} */
1676
1677/* JavaScript FTW: Ruby Blocks {{{ */
1678RubyProcParameterList_
1679 : "," RubyProcParameterList { $$ = $2; }
1680 | { $$ = NULL; }
1681 ;
1682
1683RubyProcParameterList
1684 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1685 | { $$ = NULL; }
1686 ;
1687
1688RubyProcParameters
1689 : "|" RubyProcParameterList "|" { $$ = $2; }
1690 | "||" { $$ = NULL; }
1691 ;
1692
1693RubyProcParametersOpt
1694 : RubyProcParameters
1695 | { $$ = NULL; }
1696 ;
1697
1698RubyProcExpression
1699 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1700 ;
1701
1702PrimaryExpression
1703 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1704 ;
1705
1706CallExpression
1707 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
1708 ;
1709/* }}} */
1710
1711%%