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