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