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