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