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