]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
ec7c221f1246aad3ab78200970f3fd211ed0b752
[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 EqualRight "=>"
165 %token Exclamation "!"
166 %token ExclamationEqual "!="
167 %token ExclamationEqualEqual "!=="
168 %token Hyphen "-"
169 %token HyphenEqual "-="
170 %token HyphenHyphen "--"
171 %token HyphenHyphen_ "\n--"
172 %token HyphenRight "->"
173 %token Left "<"
174 %token LeftEqual "<="
175 %token LeftLeft "<<"
176 %token LeftLeftEqual "<<="
177 %token Percent "%"
178 %token PercentEqual "%="
179 %token Period "."
180 %token PeriodPeriodPeriod "..."
181 %token Pipe "|"
182 %token PipeEqual "|="
183 %token PipePipe "||"
184 %token Plus "+"
185 %token PlusEqual "+="
186 %token PlusPlus "++"
187 %token PlusPlus_ "\n++"
188 %token Right ">"
189 %token RightEqual ">="
190 %token RightRight ">>"
191 %token RightRightEqual ">>="
192 %token RightRightRight ">>>"
193 %token RightRightRightEqual ">>>="
194 %token Slash "/"
195 %token SlashEqual "/="
196 %token Star "*"
197 %token StarEqual "*="
198 %token Tilde "~"
199
200 %token Colon ":"
201 %token Comma ","
202 %token Question "?"
203 %token SemiColon ";"
204 %token NewLine "\n"
205
206 %token <comment_> Comment
207
208 %token OpenParen "("
209 %token CloseParen ")"
210
211 %token OpenBrace "{"
212 %token OpenBrace_ "\n{"
213 %token OpenBrace__ ";{"
214 %token CloseBrace "}"
215
216 %token OpenBracket "["
217 %token CloseBracket "]"
218
219 @begin Java
220 %token AtClass "@class"
221 @end
222
223 @begin ObjectiveC
224 %token AtImplementation "@implementation"
225 %token AtImplementation_ ";@implementation"
226 %token AtImport "@import"
227 %token AtEnd "@end"
228 %token AtSelector "@selector"
229 @end
230
231 %token <false_> False "false"
232 %token <null_> Null "null"
233 %token <true_> True "true"
234
235 // ES3/ES5/WIE/JSC Reserved
236 %token <word_> Break "break"
237 %token <word_> Case "case"
238 %token <word_> Catch "catch"
239 %token <word_> Continue "continue"
240 %token <word_> Default "default"
241 %token <word_> Delete "delete"
242 %token <word_> Do "do"
243 %token <word_> Else "else"
244 %token <word_> Finally "finally"
245 %token <word_> For "for"
246 %token <word_> Function "function"
247 %token <word_> Function_ ";function"
248 %token <word_> If "if"
249 %token <word_> In "in"
250 %token <word_> In_ "!in"
251 %token <word_> InstanceOf "instanceof"
252 %token <word_> New "new"
253 %token <word_> Return "return"
254 %token <word_> Switch "switch"
255 %token <this_> This "this"
256 %token <word_> Throw "throw"
257 %token <word_> Try "try"
258 %token <word_> TypeOf "typeof"
259 %token <word_> Var "var"
260 %token <word_> Void "void"
261 %token <word_> While "while"
262 %token <word_> With "with"
263
264 // ES3/IE6 Future, ES5/JSC Reserved
265 %token <word_> Debugger "debugger"
266
267 // ES3/ES5/IE6 Future, JSC Reserved
268 %token <word_> Const "const"
269
270 // ES3/ES5/IE6/JSC Future
271 %token <word_> Class "class"
272 %token <word_> Enum "enum"
273 %token <word_> Export "export"
274 %token <word_> Extends "extends"
275 %token <word_> Import "import"
276 %token <word_> Super "super"
277
278 // ES3 Future, ES5 Strict Future
279 %token <identifier_> Implements "implements"
280 %token <identifier_> Interface "interface"
281 %token <identifier_> Package "package"
282 %token <identifier_> Private "private"
283 %token <identifier_> Protected "protected"
284 %token <identifier_> Public "public"
285 %token <identifier_> Static "static"
286
287 // ES3 Future
288 %token <identifier_> Abstract "abstract"
289 %token <identifier_> Boolean "boolean"
290 %token <identifier_> Byte "byte"
291 %token <identifier_> Char "char"
292 %token <identifier_> Double "double"
293 %token <identifier_> Final "final"
294 %token <identifier_> Float "float"
295 %token <identifier_> Goto "goto"
296 %token <identifier_> Int "int"
297 %token <identifier_> Long "long"
298 %token <identifier_> Native "native"
299 %token <identifier_> Short "short"
300 %token <identifier_> Synchronized "synchronized"
301 %token <identifier_> Throws "throws"
302 %token <identifier_> Transient "transient"
303 %token <identifier_> Volatile "volatile"
304
305 // ES5 Strict
306 %token <identifier_> Let "let"
307 %token <identifier_> Yield "yield"
308
309 // Woah?!
310 %token <identifier_> Each "each"
311 %token <identifier_> Of "of"
312
313 @begin E4X
314 // E4X Conditional
315 %token <identifier_> Namespace "namespace"
316 %token <identifier_> XML "xml"
317 @end
318
319 %token AutoComplete
320
321 %token <identifier_> Identifier_
322 %token <number_> NumericLiteral
323 %token <string_> StringLiteral
324 %token <literal_> RegularExpressionLiteral
325
326 %type <expression_> AdditiveExpression
327 %type <argument_> ArgumentList_
328 %type <argument_> ArgumentList
329 %type <argument_> ArgumentListOpt
330 %type <argument_> Arguments
331 %type <literal_> ArrayLiteral
332 %type <expression_> ArrowFunction
333 %type <functionParameter_> ArrowParameters
334 %type <expression_> AssignmentExpression
335 %type <identifier_> BindingIdentifier
336 %type <expression_> BitwiseANDExpression
337 %type <statement_> Block_
338 %type <statement_> Block
339 %type <boolean_> BooleanLiteral
340 %type <declaration_> BindingElement
341 %type <expression_> BitwiseORExpression
342 %type <expression_> BitwiseXORExpression
343 %type <statement_> BreakStatement
344 %type <statement_> BreakableStatement
345 %type <expression_> CallExpression_
346 %type <expression_> CallExpression
347 %type <clause_> CaseBlock
348 %type <clause_> CaseClause
349 %type <clause_> CaseClausesOpt
350 %type <catch_> CatchOpt
351 %type <comprehension_> ComprehensionList
352 %type <comprehension_> ComprehensionListOpt
353 %type <expression_> ConditionalExpression
354 %type <statement_> ContinueStatement
355 %type <statement_> ConciseBody
356 %type <statement_> DebuggerStatement
357 %type <statement_> Declaration__
358 %type <statement_> Declaration_
359 %type <statement_> Declaration
360 %type <clause_> DefaultClause
361 %type <expression_> Element
362 %type <expression_> ElementOpt
363 %type <element_> ElementList
364 %type <element_> ElementListOpt
365 %type <statement_> ElseStatementOpt
366 %type <statement_> EmptyStatement
367 %type <expression_> EqualityExpression
368 %type <compound_> Expression_
369 %type <compound_> Expression
370 %type <expression_> ExpressionOpt
371 %type <statement_> ExpressionStatement
372 %type <finally_> FinallyOpt
373 %type <comprehension_> ForComprehension
374 %type <for_> ForStatementInitialiser
375 %type <forin_> ForInStatementInitialiser
376 %type <declaration_> FormalParameter
377 %type <functionParameter_> FormalParameterList_
378 %type <functionParameter_> FormalParameterList
379 %type <functionParameter_> FormalParameterListOpt
380 %type <statement_> FunctionBody
381 %type <statement_> FunctionDeclaration
382 %type <expression_> FunctionExpression
383 %type <identifier_> Identifier
384 %type <identifier_> IdentifierOpt
385 %type <word_> IdentifierName
386 %type <comprehension_> IfComprehension
387 %type <statement_> IfStatement
388 %type <expression_> Initialiser
389 %type <expression_> InitialiserOpt
390 %type <statement_> IterationStatement
391 %type <statement_> LabelledStatement
392 %type <expression_> LeftHandSideExpression
393 %type <statement_> LetStatement
394 %type <statement_> LexicalDeclaration
395 %type <literal_> Literal
396 %type <literal_> LiteralNoRE
397 %type <expression_> LogicalANDExpression
398 %type <expression_> LogicalORExpression
399 %type <member_> MemberAccess
400 %type <expression_> MemberExpression_
401 %type <expression_> MemberExpression
402 %type <expression_> MultiplicativeExpression
403 %type <expression_> NewExpression
404 %type <null_> NullLiteral
405 %type <literal_> ObjectLiteral
406 %type <compound_> Parenthetical
407 %type <compound_> ParentheticalOpt
408 %type <expression_> PostfixExpression
409 %type <expression_> PrimaryExpression
410 %type <statement_> Program
411 %type <statement_> ProgramBody
412 %type <statement_> ProgramBodyOpt
413 %type <propertyName_> PropertyName_
414 %type <propertyName_> PropertyName
415 %type <property_> PropertyNameAndValueList_
416 %type <property_> PropertyNameAndValueList
417 %type <property_> PropertyNameAndValueListOpt
418 %type <expression_> RelationalExpression
419 %type <statement_> ReturnStatement
420 %type <rubyProc_> RubyProcExpression
421 %type <functionParameter_> RubyProcParameterList_
422 %type <functionParameter_> RubyProcParameterList
423 %type <functionParameter_> RubyProcParameters
424 %type <functionParameter_> RubyProcParametersOpt
425 %type <expression_> ShiftExpression
426 %type <declaration_> SingleNameBinding
427 %type <statement_> Statement__
428 %type <statement_> Statement_
429 %type <statement_> Statement
430 %type <statement_> StatementList
431 %type <statement_> StatementListOpt
432 %type <statement_> StatementListItem
433 %type <statement_> SwitchStatement
434 %type <statement_> ThrowStatement
435 %type <statement_> TryStatement
436 %type <expression_> UnaryExpression_
437 %type <expression_> UnaryExpression
438 %type <declaration_> VariableDeclaration
439 %type <declarations_> VariableDeclarationList_
440 %type <declarations_> VariableDeclarationList
441 %type <statement_> VariableStatement
442 %type <statement_> WithStatement
443 %type <word_> Word
444 %type <word_> WordOpt
445
446 @begin ObjectiveC
447 %type <statement_> CategoryStatement
448 %type <expression_> ClassExpression
449 %type <statement_> ClassStatement
450 %type <expression_> ClassSuperOpt
451 %type <field_> ClassFieldList
452 %type <message_> ClassMessageDeclaration
453 %type <message_> ClassMessageDeclarationListOpt
454 %type <className_> ClassName
455 %type <className_> ClassNameOpt
456 %type <protocol_> ClassProtocolListOpt
457 %type <protocol_> ClassProtocols
458 %type <protocol_> ClassProtocolsOpt
459 %type <expression_> MessageExpression
460 %type <messageParameter_> MessageParameter
461 %type <messageParameter_> MessageParameters
462 %type <messageParameter_> MessageParameterList
463 %type <messageParameter_> MessageParameterListOpt
464 %type <bool_> MessageScope
465 %type <argument_> SelectorCall_
466 %type <argument_> SelectorCall
467 %type <selector_> SelectorExpression_
468 %type <selector_> SelectorExpression
469 %type <selector_> SelectorExpressionOpt
470 %type <argument_> SelectorList
471 %type <word_> SelectorWordOpt
472 %type <expression_> TypeOpt
473 %type <argument_> VariadicCall
474 @end
475
476 @begin E4X
477 %type <propertyIdentifier_> PropertyIdentifier_
478 %type <selector_> PropertySelector_
479 %type <selector_> PropertySelector
480 %type <identifier_> QualifiedIdentifier_
481 %type <identifier_> QualifiedIdentifier
482 %type <identifier_> WildcardIdentifier
483 %type <identifier_> XMLComment
484 %type <identifier_> XMLCDATA
485 %type <identifier_> XMLElement
486 %type <identifier_> XMLElementContent
487 %type <identifier_> XMLMarkup
488 %type <identifier_> XMLPI
489
490 %type <attribute_> AttributeIdentifier
491 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
492 %type <expression_> PropertyIdentifier
493 %type <expression_> XMLListInitialiser
494 %type <expression_> XMLInitialiser
495 @end
496
497 %nonassoc ""
498 %left "++" "--"
499
500 %nonassoc "if"
501 %nonassoc "else"
502
503 %start Program
504
505 %%
506
507 /* Lexer State {{{ */
508 LexPushInOn
509 : { driver.in_.push(true); }
510 ;
511
512 LexPushInOff
513 : { driver.in_.push(false); }
514 ;
515
516 LexPopIn
517 : { driver.in_.pop(); }
518 ;
519
520 LexSetRegExp
521 : { driver.SetCondition(CYDriver::RegExpCondition); }
522 ;
523
524 LexNoBrace
525 : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
526 ;
527
528 LexNoFunction
529 : { if (yychar == token::Function) yychar = token::Function_; }
530 ;
531
532 LexSetStatement
533 : LexNoBrace LexNoFunction
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 | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
549 ;
550
551 TerminatorOpt
552 : ";"
553 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
554 ;
555
556 /*CommaOpt
557 : ","
558 |
559 ;*/
560
561 NewLineOpt
562 : "\n"
563 |
564 ;
565
566 IdentifierName
567 : Word { $$ = $1; }
568 ;
569
570 Word
571 : Identifier { $$ = $1; }
572 | "break" NewLineOpt { $$ = $1; }
573 | "case" { $$ = $1; }
574 | "catch" { $$ = $1; }
575 | "class" { $$ = $1; }
576 | "const" { $$ = $1; }
577 | "continue" NewLineOpt { $$ = $1; }
578 | "debugger" { $$ = $1; }
579 | "default" { $$ = $1; }
580 | "delete" { $$ = $1; }
581 | "do" { $$ = $1; }
582 | "else" { $$ = $1; }
583 | "enum" { $$ = $1; }
584 | "export" { $$ = $1; }
585 | "extends" { $$ = $1; }
586 | "false" { $$ = $1; }
587 | "finally" { $$ = $1; }
588 /* XXX: | "for" { $$ = $1; } */
589 | "function" { $$ = $1; }
590 | "if" { $$ = $1; }
591 | "import" { $$ = $1; }
592 /* XXX: | "in" { $$ = $1; } */
593 | "!in" { $$ = $1; }
594 /* XXX: | "instanceof" { $$ = $1; } */
595
596 // XXX: as it currently is not an Identifier
597 | "let" { $$ = $1; }
598
599 | "new" { $$ = $1; }
600 | "null" { $$ = $1; }
601 | "return" NewLineOpt { $$ = $1; }
602 | "super" { $$ = $1; }
603 | "switch" { $$ = $1; }
604 | "this" { $$ = $1; }
605 | "throw" NewLineOpt { $$ = $1; }
606 | "true" { $$ = $1; }
607 | "try" { $$ = $1; }
608 | "typeof" { $$ = $1; }
609 | "var" { $$ = $1; }
610 | "void" { $$ = $1; }
611 | "while" { $$ = $1; }
612 | "with" { $$ = $1; }
613 ;
614
615 WordOpt
616 : Word { $$ = $1; }
617 | { $$ = NULL; }
618 ;
619
620 @begin ObjectiveC
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: currently I only have this as Word
658 // | "let" { $$ = $1; }
659
660 | "yield" { $$ = $1; }
661
662 | "each" { $$ = $1; }
663 | "of" { $$ = $1; }
664 ;
665
666 IdentifierOpt
667 : Identifier { $$ = $1; }
668 | { $$ = NULL; }
669 ;
670
671 LiteralNoRE
672 : NullLiteral { $$ = $1; }
673 | BooleanLiteral { $$ = $1; }
674 | NumericLiteral { $$ = $1; }
675 | StringLiteral { $$ = $1; }
676 ;
677
678 Literal
679 : LiteralNoRE { $$ = $1; }
680 | RegularExpressionLiteral { $$ = $1; }
681 ;
682
683 NullLiteral
684 : "null" { $$ = $1; }
685 ;
686
687 BooleanLiteral
688 : "true" { $$ = $1; }
689 | "false" { $$ = $1; }
690 ;
691
692 /* 11.1 Primary Expressions {{{ */
693 Parenthetical
694 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
695 ;
696
697 ParentheticalOpt
698 : Parenthetical { $$ = $1; }
699 | { $$ = NULL; }
700 ;
701
702 PrimaryExpression
703 : "this" { $$ = $1; }
704 | Identifier { $$ = CYNew CYVariable($1); }
705 | Literal { $$ = $1; }
706 | ArrayLiteral { $$ = $1; }
707 | ObjectLiteral { $$ = $1; }
708 | FunctionExpression { $$ = $1; }
709 | Parenthetical { $$ = $1; }
710 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
711 ;
712 /* }}} */
713 /* 11.1.4.1 Array Initialiser {{{ */
714 ArrayLiteral
715 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
716 ;
717
718 Element
719 : AssignmentExpression { $$ = $1; }
720 ;
721
722 ElementOpt
723 : Element { $$ = $1; }
724 | LexSetRegExp { $$ = NULL; }
725 ;
726
727 ElementList
728 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
729 | Element { $$ = CYNew CYElement($1, NULL); }
730 ;
731
732 ElementListOpt
733 : ElementList { $$ = $1; }
734 | LexSetRegExp { $$ = NULL; }
735 ;
736 /* }}} */
737 /* 11.1.5 Object Initialiser {{{ */
738 ObjectLiteral
739 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
740 ;
741
742 PropertyNameAndValueList_
743 : "," PropertyNameAndValueList { $$ = $2; }
744 | { $$ = NULL; }
745 ;
746
747 PropertyNameAndValueList
748 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
749 ;
750
751 PropertyNameAndValueListOpt
752 : PropertyNameAndValueList { $$ = $1; }
753 | { $$ = NULL; }
754 ;
755
756 PropertyName_
757 : IdentifierName { $$ = $1; }
758 | StringLiteral { $$ = $1; }
759 | NumericLiteral { $$ = $1; }
760 ;
761
762 PropertyName
763 : LexSetRegExp PropertyName_ { $$ = $2; }
764 ;
765 /* }}} */
766
767 /* 11.2 Left-Hand-Side Expressions {{{ */
768 MemberAccess
769 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
770 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
771 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
772 ;
773
774 MemberExpression_
775 : MemberExpression { $$ = $1; }
776 //| "super" { $$ = $1; }
777 ;
778
779 MemberExpression
780 : LexSetRegExp PrimaryExpression { $$ = $2; }
781 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
782 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
783 ;
784
785 NewExpression
786 : MemberExpression { $$ = $1; }
787 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
788 ;
789
790 CallExpression_
791 : MemberExpression_
792 | CallExpression
793 ;
794
795 CallExpression
796 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
797 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
798 ;
799
800 Arguments
801 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
802 ;
803
804 ArgumentList_
805 : "," ArgumentList { $$ = $2; }
806 | { $$ = NULL; }
807 ;
808
809 ArgumentList
810 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
811 ;
812
813 ArgumentListOpt
814 : ArgumentList { $$ = $1; }
815 | LexSetRegExp { $$ = NULL; }
816 ;
817
818 LeftHandSideExpression
819 : NewExpression { $$ = $1; }
820 | CallExpression { $$ = $1; }
821 ;
822 /* }}} */
823 /* 11.3 Postfix Expressions {{{ */
824 PostfixExpression
825 : %prec "" LeftHandSideExpression { $$ = $1; }
826 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
827 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
828 ;
829 /* }}} */
830 /* 11.4 Unary Operators {{{ */
831 UnaryExpression_
832 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
833 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
834 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
835 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
836 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
837 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
838 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
839 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
840 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
841 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
842 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
843 ;
844
845 UnaryExpression
846 : PostfixExpression { $$ = $1; }
847 | LexSetRegExp UnaryExpression_ { $$ = $2; }
848 ;
849 /* }}} */
850 /* 11.5 Multiplicative Operators {{{ */
851 MultiplicativeExpression
852 : UnaryExpression { $$ = $1; }
853 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
854 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
855 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
856 ;
857 /* }}} */
858 /* 11.6 Additive Operators {{{ */
859 AdditiveExpression
860 : MultiplicativeExpression { $$ = $1; }
861 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
862 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
863 ;
864 /* }}} */
865 /* 11.7 Bitwise Shift Operators {{{ */
866 ShiftExpression
867 : AdditiveExpression { $$ = $1; }
868 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
869 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
870 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
871 ;
872 /* }}} */
873 /* 11.8 Relational Operators {{{ */
874 RelationalExpression
875 : ShiftExpression { $$ = $1; }
876 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
877 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
878 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
879 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
880 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
881 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
882 ;
883 /* }}} */
884 /* 11.9 Equality Operators {{{ */
885 EqualityExpression
886 : RelationalExpression { $$ = $1; }
887 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
888 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
889 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
890 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
891 ;
892 /* }}} */
893 /* 11.10 Binary Bitwise Operators {{{ */
894 BitwiseANDExpression
895 : EqualityExpression { $$ = $1; }
896 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
897 ;
898
899 BitwiseXORExpression
900 : BitwiseANDExpression { $$ = $1; }
901 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
902 ;
903
904 BitwiseORExpression
905 : BitwiseXORExpression { $$ = $1; }
906 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
907 ;
908 /* }}} */
909 /* 11.11 Binary Logical Operators {{{ */
910 LogicalANDExpression
911 : BitwiseORExpression { $$ = $1; }
912 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
913 ;
914
915 LogicalORExpression
916 : LogicalANDExpression { $$ = $1; }
917 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
918 ;
919 /* }}} */
920 /* 11.12 Conditional Operator ( ? : ) {{{ */
921 ConditionalExpression
922 : LogicalORExpression { $$ = $1; }
923 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
924 ;
925 /* }}} */
926 /* 11.13 Assignment Operators {{{ */
927 AssignmentExpression
928 : ConditionalExpression { $$ = $1; }
929 | ArrowFunction { $$ = $1; }
930 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
931 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
932 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
933 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
934 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
935 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
936 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
937 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
938 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
939 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
940 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
941 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
942 ;
943 /* }}} */
944 /* 11.14 Comma Operator {{{ */
945 Expression_
946 : "," Expression { $$ = $2; }
947 | { $$ = CYNew CYCompound(); }
948 ;
949
950 Expression
951 : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
952 ;
953
954 ExpressionOpt
955 : Expression { $$ = $1; }
956 | LexSetRegExp { $$ = NULL; }
957 ;
958 /* }}} */
959
960 /* 12 Statements {{{ */
961 Statement__
962 : Block { $$ = $1; }
963 | VariableStatement { $$ = $1; }
964 | EmptyStatement { $$ = $1; }
965 | IfStatement { $$ = $1; }
966 | BreakableStatement { $$ = $1; }
967 | ContinueStatement { $$ = $1; }
968 | BreakStatement { $$ = $1; }
969 | ReturnStatement { $$ = $1; }
970 | WithStatement { $$ = $1; }
971 | LabelledStatement { $$ = $1; }
972 | ThrowStatement { $$ = $1; }
973 | TryStatement { $$ = $1; }
974 | DebuggerStatement { $$ = $1; }
975 ;
976
977 Statement_
978 : LexSetRegExp Statement__ { $$ = $2; }
979 | ExpressionStatement { $$ = $1; }
980 ;
981
982 Statement
983 : LexSetStatement Statement_ { $$ = $2; }
984 ;
985
986 Declaration__
987 : FunctionDeclaration { $$ = $1; }
988 | LexicalDeclaration { $$ = $1; }
989 ;
990
991 Declaration_
992 : LexSetRegExp Declaration__ { $$ = $2; }
993 ;
994
995 Declaration
996 : LexSetStatement Declaration_ { $$ = $2; }
997 ;
998
999 BreakableStatement
1000 : IterationStatement { $$ = $1; }
1001 | SwitchStatement { $$ = $1; }
1002 ;
1003 /* }}} */
1004 /* 12.1 Block {{{ */
1005 Block_
1006 : BRACE StatementListOpt "}" { $$ = $2; }
1007 ;
1008
1009 Block
1010 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1011 ;
1012
1013 StatementList
1014 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1015 ;
1016
1017 StatementListOpt
1018 : StatementList { $$ = $1; }
1019 | LexSetRegExp { $$ = NULL; }
1020 ;
1021
1022 StatementListItem
1023 : Statement { $$ = $1; }
1024 | Declaration { $$ = $1; }
1025 ;
1026 /* }}} */
1027 /* 12.2 Declarations {{{ */
1028 BindingIdentifier
1029 : Identifier { $$ = $1; }
1030 ;
1031
1032 // XXX: BindingPattern
1033 /* }}} */
1034 /* 12.2.1 Let and Const Declarations {{{ */
1035 LexicalDeclaration
1036 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1037 ;
1038
1039 LetOrConst
1040 : "let"
1041 | "const"
1042 ;
1043 /* }}} */
1044 /* 12.2.2 Variable Statement {{{ */
1045 VariableStatement
1046 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1047 ;
1048
1049 VariableDeclarationList_
1050 : "," VariableDeclarationList { $$ = $2; }
1051 | { $$ = NULL; }
1052 ;
1053
1054 VariableDeclarationList
1055 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1056 ;
1057
1058 VariableDeclaration
1059 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1060 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1061 ;
1062
1063 Initialiser
1064 : "=" AssignmentExpression { $$ = $2; }
1065 ;
1066
1067 InitialiserOpt
1068 : Initialiser { $$ = $1; }
1069 | { $$ = NULL; }
1070 ;
1071 /* }}} */
1072 /* 12.2.4 Destructuring Binding Patterns {{{ */
1073 // XXX: *
1074
1075 BindingElement
1076 : SingleNameBinding { $$ = $1; }
1077 ;
1078
1079 SingleNameBinding
1080 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1081 ;
1082 /* }}} */
1083 /* 12.3 Empty Statement {{{ */
1084 EmptyStatement
1085 : ";" { $$ = CYNew CYEmpty(); }
1086 ;
1087 /* }}} */
1088 /* 12.4 Expression Statement {{{ */
1089 ExpressionStatement
1090 : Expression Terminator { $$ = CYNew CYExpress($1); }
1091 ;
1092 /* }}} */
1093 /* 12.5 The if Statement {{{ */
1094 ElseStatementOpt
1095 : "else" Statement { $$ = $2; }
1096 | %prec "if" { $$ = NULL; }
1097 ;
1098
1099 IfStatement
1100 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1101 ;
1102 /* }}} */
1103
1104 /* 12.6.1 The do-while Statement {{{ */
1105 IterationStatement
1106 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1107 ;
1108 /* }}} */
1109 /* 12.6.2 The while Statement {{{ */
1110 IterationStatement
1111 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1112 ;
1113 /* }}} */
1114 /* 12.6.3 The for Statement {{{ */
1115 IterationStatement
1116 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1117 ;
1118
1119 ForStatementInitialiser
1120 : ExpressionOpt { $$ = $1; }
1121 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1122 ;
1123 /* }}} */
1124 /* 12.6.4 The for-in and for-of Statements {{{ */
1125 IterationStatement
1126 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1127 | "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "of" Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1128 ;
1129
1130 ForInStatementInitialiser
1131 : LeftHandSideExpression { $$ = $1; }
1132 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1133 ;
1134 /* }}} */
1135
1136 /* 12.7 The continue Statement {{{ */
1137 ContinueStatement
1138 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1139 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1140 ;
1141 /* }}} */
1142 /* 12.8 The break Statement {{{ */
1143 BreakStatement
1144 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1145 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1146 ;
1147 /* }}} */
1148 /* 12.9 The return Statement {{{ */
1149 ReturnStatement
1150 : "return" "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1151 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1152 ;
1153 /* }}} */
1154 /* 12.10 The with Statement {{{ */
1155 WithStatement
1156 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1157 ;
1158 /* }}} */
1159
1160 /* 12.11 The switch Statement {{{ */
1161 SwitchStatement
1162 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1163 ;
1164
1165 CaseBlock
1166 : BRACE CaseClausesOpt "}" { $$ = $2; }
1167 ;
1168
1169 CaseClause
1170 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1171 ;
1172
1173 CaseClausesOpt
1174 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1175 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1176 | { $$ = NULL; }
1177 ;
1178
1179 DefaultClause
1180 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1181 ;
1182 /* }}} */
1183 /* 12.12 Labelled Statements {{{ */
1184 LabelledStatement
1185 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1186 ;
1187 /* }}} */
1188 /* 12.13 The throw Statement {{{ */
1189 ThrowStatement
1190 : "throw" "\n" StrictSemi { YYABORT; }
1191 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1192 ;
1193 /* }}} */
1194 /* 12.14 The try Statement {{{ */
1195 TryStatement
1196 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1197 ;
1198
1199 CatchOpt
1200 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1201 | { $$ = NULL; }
1202 ;
1203
1204 FinallyOpt
1205 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1206 | { $$ = NULL; }
1207 ;
1208 /* }}} */
1209 /* 12.14 The debugger Statement {{{ */
1210 DebuggerStatement
1211 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1212 ;
1213 /* }}} */
1214
1215 /* 13.1 Function Definitions {{{ */
1216 FunctionDeclaration
1217 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1218 ;
1219
1220 FunctionExpression
1221 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1222 ;
1223
1224 FormalParameterList_
1225 : "," FormalParameterList { $$ = $2; }
1226 | { $$ = NULL; }
1227 ;
1228
1229 FormalParameterList
1230 // XXX: : FunctionRestParameter { $$ = $1; }
1231 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1232 ;
1233
1234 FormalParameterListOpt
1235 : FormalParameterList
1236 | { $$ = NULL; }
1237 ;
1238
1239 /* XXX: FunctionRestParameter
1240 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1241 ;*/
1242
1243 FormalParameter
1244 : BindingElement { $$ = $1; }
1245 ;
1246
1247 FunctionBody
1248 : StatementListOpt { $$ = $1; }
1249 ;
1250 /* }}} */
1251 /* 13.2 Arrow Function Definitions {{{ */
1252 ArrowFunction
1253 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFunctionExpression(NULL, $2, $5); }
1254 ;
1255
1256 ArrowParameters
1257 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1258 //| ParentheticalOpt { $$ = $1; }
1259 ;
1260
1261 ConciseBody
1262 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1263 | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; }
1264 ;
1265 /* }}} */
1266 /* 14 Program {{{ */
1267 Program
1268 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1269 ;
1270
1271 ProgramBody
1272 : StatementList { $$ = $1; }
1273 ;
1274
1275 ProgramBodyOpt
1276 : ProgramBody { $$ = $1; }
1277 | { $$ = NULL; }
1278 ;
1279 /* }}} */
1280
1281 @begin ObjectiveC
1282 /* Cycript (Objective-C): @class Declaration {{{ */
1283 ClassSuperOpt
1284 /* XXX: why the hell did I choose MemberExpression? */
1285 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1286 | { $$ = NULL; }
1287 ;
1288
1289 ClassField
1290 : Expression Identifier ";"
1291 ;
1292
1293 ClassFieldList
1294 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1295 ;
1296
1297 ClassFieldListOpt
1298 : ClassFieldListOpt ClassField
1299 |
1300 ;
1301
1302 MessageScope
1303 : "+" { $$ = false; }
1304 | "-" { $$ = true; }
1305 ;
1306
1307 TypeOpt
1308 : "(" Expression ")" { $$ = $2; }
1309 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1310 | { $$ = NULL; }
1311 ;
1312
1313 MessageParameter
1314 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1315 ;
1316
1317 MessageParameterList
1318 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1319 ;
1320
1321 MessageParameterListOpt
1322 : MessageParameterList { $$ = $1; }
1323 | { $$ = NULL; }
1324 ;
1325
1326 MessageParameters
1327 : MessageParameterList { $$ = $1; }
1328 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1329 ;
1330
1331 ClassMessageDeclaration
1332 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1333 ;
1334
1335 ClassMessageDeclarationListOpt
1336 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1337 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1338 | { $$ = NULL; }
1339 ;
1340
1341 ClassName
1342 : Identifier { $$ = $1; }
1343 | "(" AssignmentExpression ")" { $$ = $2; }
1344 ;
1345
1346 ClassNameOpt
1347 : ClassName { $$ = $1; }
1348 | { $$ = NULL; }
1349 ;
1350
1351 // XXX: this should be AssignmentExpressionNoRight
1352 ClassProtocols
1353 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1354 ;
1355
1356 ClassProtocolsOpt
1357 : "," ClassProtocols { $$ = $2; }
1358 | { $$ = NULL; }
1359 ;
1360
1361 ClassProtocolListOpt
1362 : "<" ClassProtocols ">" { $$ = $2; }
1363 | { $$ = NULL; }
1364 ;
1365
1366 ClassExpression
1367 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1368 ;
1369
1370 ClassStatement
1371 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1372 ;
1373
1374 CategoryName
1375 : "(" WordOpt ")"
1376 ;
1377
1378 CategoryStatement
1379 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1380 ;
1381
1382 PrimaryExpression
1383 : ClassExpression { $$ = $1; }
1384 ;
1385
1386 Statement__
1387 : ClassStatement { $$ = $1; }
1388 | CategoryStatement { $$ = $1; }
1389 ;
1390 /* }}} */
1391 /* Cycript (Objective-C): Send Message {{{ */
1392 VariadicCall
1393 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1394 | { $$ = NULL; }
1395 ;
1396
1397 SelectorWordOpt
1398 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1399 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1400 ;
1401
1402 SelectorCall_
1403 : SelectorCall { $$ = $1; }
1404 | VariadicCall { $$ = $1; }
1405 ;
1406
1407 SelectorCall
1408 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1409 ;
1410
1411 SelectorList
1412 : SelectorCall { $$ = $1; }
1413 | Word { $$ = CYNew CYArgument($1, NULL); }
1414 ;
1415
1416 MessageExpression
1417 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1418 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1419 ;
1420
1421 SelectorExpression_
1422 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1423 ;
1424
1425 SelectorExpression
1426 : SelectorExpression_ { $$ = $1; }
1427 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1428 ;
1429
1430 SelectorExpressionOpt
1431 : SelectorExpression_ { $$ = $1; }
1432 | { $$ = NULL; }
1433 ;
1434
1435 PrimaryExpression
1436 : MessageExpression { $$ = $1; }
1437 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1438 ;
1439 /* }}} */
1440 /* Cycript (Objective-C): @import Directive {{{ */
1441 PathName
1442 : "/" PathName
1443 | "." PathName
1444 | Word PathName
1445 |
1446 ;
1447
1448 ImportPath
1449 : "<" PathName ">"
1450 | StringLiteral
1451 ;
1452
1453 StatementListItem
1454 : "@import" ImportPath { $$ = CYNew CYImport(); }
1455 ;
1456 /* }}} */
1457 @end
1458
1459 @begin C
1460 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1461 LeftHandSideExpression
1462 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1463 ;
1464
1465 UnaryExpression_
1466 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1467 ;
1468
1469 MemberAccess
1470 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1471 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1472 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1473 ;
1474 /* }}} */
1475 @end
1476
1477 /* YUI: Documentation Comments {{{ */
1478 Statement__
1479 : Comment { $$ = $1; }
1480 ;
1481 /* }}} */
1482
1483 @begin E4X
1484 /* Lexer State {{{ */
1485 LexPushRegExp
1486 : { driver.PushCondition(CYDriver::RegExpCondition); }
1487 ;
1488
1489 LexPushXMLContent
1490 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1491 ;
1492
1493 LexPushXMLTag
1494 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1495 ;
1496
1497 LexPop
1498 : { driver.PopCondition(); }
1499 ;
1500
1501 LexSetXMLContent
1502 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1503 ;
1504
1505 LexSetXMLTag
1506 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1507 ;
1508 /* }}} */
1509
1510 XMLWhitespaceOpt
1511 : XMLWhitespace
1512 |
1513 ;
1514
1515 /* 8.1 Context Keywords {{{ */
1516 Identifier
1517 : "namespace" { $$ = $1; }
1518 | "xml" { $$ = $1; }
1519 ;
1520 /* }}} */
1521 /* 8.3 XML Initialiser Input Elements {{{ */
1522 XMLMarkup
1523 : XMLComment { $$ = $1; }
1524 | XMLCDATA { $$ = $1; }
1525 | XMLPI { $$ = $1; }
1526 ;
1527 /* }}} */
1528 /* 11.1 Primary Expressions {{{ */
1529 PrimaryExpression
1530 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1531 | XMLInitialiser { $$ = $1; }
1532 | XMLListInitialiser { $$ = $1; }
1533 ;
1534
1535 PropertyIdentifier
1536 : AttributeIdentifier { $$ = $1; }
1537 | QualifiedIdentifier { $$ = $1; }
1538 | WildcardIdentifier { $$ = $1; }
1539 ;
1540 /* }}} */
1541 /* 11.1.1 Attribute Identifiers {{{ */
1542 AttributeIdentifier
1543 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1544 ;
1545
1546 PropertySelector_
1547 : PropertySelector { $$ = $1; }
1548 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1549 ;
1550
1551 PropertySelector
1552 : Identifier { $$ = CYNew CYSelector($1); }
1553 | WildcardIdentifier { $$ = $1; }
1554 ;
1555 /* }}} */
1556 /* 11.1.2 Qualified Identifiers {{{ */
1557 QualifiedIdentifier_
1558 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1559 | QualifiedIdentifier { $$ = $1; }
1560 ;
1561
1562 QualifiedIdentifier
1563 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1564 ;
1565 /* }}} */
1566 /* 11.1.3 Wildcard Identifiers {{{ */
1567 WildcardIdentifier
1568 : "*" { $$ = CYNew CYWildcard(); }
1569 ;
1570 /* }}} */
1571 /* 11.1.4 XML Initialiser {{{ */
1572 XMLInitialiser
1573 : XMLMarkup { $$ = $1; }
1574 | XMLElement { $$ = $1; }
1575 ;
1576
1577 XMLElement
1578 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1579 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1580 ;
1581
1582 XMLTagContent
1583 : LexPushXMLTag XMLTagName XMLAttributes
1584 ;
1585
1586 XMLExpression
1587 : BRACE LexPushRegExp Expression LexPop "}"
1588 ;
1589
1590 XMLTagName
1591 : XMLExpression
1592 | XMLName
1593 ;
1594
1595 XMLAttributes_
1596 : XMLAttributes_ XMLAttribute
1597 |
1598 ;
1599
1600 XMLAttributes
1601 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1602 | XMLAttributes_ XMLWhitespaceOpt
1603 ;
1604
1605 XMLAttributeValue_
1606 : XMLExpression
1607 | XMLAttributeValue
1608 ;
1609
1610 XMLAttribute
1611 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1612 ;
1613
1614 XMLElementContent
1615 : XMLExpression XMLElementContentOpt
1616 | XMLMarkup XMLElementContentOpt
1617 | XMLText XMLElementContentOpt
1618 | XMLElement XMLElementContentOpt
1619 ;
1620
1621 XMLElementContentOpt
1622 : XMLElementContent
1623 |
1624 ;
1625 /* }}} */
1626 /* 11.1.5 XMLList Initialiser {{{ */
1627 XMLListInitialiser
1628 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1629 ;
1630 /* }}} */
1631 /* 11.2 Left-Hand-Side Expressions {{{ */
1632 PropertyIdentifier_
1633 : Identifier { $$ = $1; }
1634 | PropertyIdentifier { $$ = $1; }
1635 ;
1636
1637 MemberAccess
1638 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1639 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1640 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1641 ;
1642 /* }}} */
1643 /* 12.1 The default xml namespace Statement {{{ */
1644 /* XXX: DefaultXMLNamespaceStatement
1645 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1646 ;
1647
1648 Statement__
1649 : DefaultXMLNamespaceStatement { $$ = $1; }
1650 ; */
1651 /* }}} */
1652 @end
1653
1654 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1655 PropertyNameAndValueList_
1656 : "," { $$ = NULL; }
1657 ;
1658 /* }}} */
1659
1660 /* JavaScript 1.7: Array Comprehensions {{{ */
1661 IfComprehension
1662 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1663 ;
1664
1665 ForComprehension
1666 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1667 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
1668 ;
1669
1670 ComprehensionList
1671 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1672 ;
1673
1674 ComprehensionListOpt
1675 : ComprehensionList { $$ = $1; }
1676 | IfComprehension { $$ = $1; }
1677 | { $$ = NULL; }
1678 ;
1679
1680 PrimaryExpression
1681 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1682 ;
1683 /* }}} */
1684 /* JavaScript 1.7: for each {{{ */
1685 IterationStatement
1686 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1687 ;
1688 /* }}} */
1689 /* JavaScript 1.7: let Statements {{{ */
1690 LetStatement
1691 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1692 ;
1693
1694 Statement__
1695 : LetStatement
1696 ;
1697 /* }}} */
1698
1699 /* JavaScript FTW: Ruby Blocks {{{ */
1700 RubyProcParameterList_
1701 : "," RubyProcParameterList { $$ = $2; }
1702 | { $$ = NULL; }
1703 ;
1704
1705 RubyProcParameterList
1706 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1707 | { $$ = NULL; }
1708 ;
1709
1710 RubyProcParameters
1711 : "|" RubyProcParameterList "|" { $$ = $2; }
1712 | "||" { $$ = NULL; }
1713 ;
1714
1715 RubyProcParametersOpt
1716 : RubyProcParameters
1717 | { $$ = NULL; }
1718 ;
1719
1720 RubyProcExpression
1721 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1722 ;
1723
1724 PrimaryExpression
1725 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1726 ;
1727
1728 CallExpression
1729 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
1730 ;
1731 /* }}} */
1732
1733 %%