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