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