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