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