]> git.saurik.com Git - cycript.git/blame_incremental - Cycript.y
Support array ffi_type through some shady argumentaton, implement Type[] syntax for...
[cycript.git] / Cycript.y
... / ...
CommitLineData
1/* Cycript - Remove Execution Server and Disassembler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3*/
4
5/* Modified BSD License {{{ */
6/*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37*/
38/* }}} */
39
40%code top {
41#include "Cycript.tab.hh"
42#define scanner driver.scanner_
43#define YYSTACKEXPANDABLE 1
44}
45
46%code requires {
47#include "Parser.hpp"
48
49typedef struct {
50 bool newline_;
51
52 union {
53 bool bool_;
54
55 CYArgument *argument_;
56 CYAssignment *assignment_;
57 CYBoolean *boolean_;
58 CYClause *clause_;
59 CYCatch *catch_;
60 CYClass *class_;
61 CYClassName *className_;
62 CYComprehension *comprehension_;
63 CYCompound *compound_;
64 CYDeclaration *declaration_;
65 CYDeclarations *declarations_;
66 CYElement *element_;
67 CYExpression *expression_;
68 CYFalse *false_;
69 CYField *field_;
70 CYForInitialiser *for_;
71 CYForInInitialiser *forin_;
72 CYFunctionParameter *functionParameter_;
73 CYIdentifier *identifier_;
74 CYInfix *infix_;
75 CYLiteral *literal_;
76 CYMember *member_;
77 CYMessage *message_;
78 CYMessageParameter *messageParameter_;
79 CYNull *null_;
80 CYNumber *number_;
81 CYProperty *property_;
82 CYPropertyName *propertyName_;
83 CYSelectorPart *selector_;
84 CYSource *source_;
85 CYStatement *statement_;
86 CYString *string_;
87 CYThis *this_;
88 CYTrue *true_;
89 CYWord *word_;
90 };
91} YYSTYPE;
92
93}
94
95%code provides {
96int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
97}
98
99%name-prefix "cy"
100
101%language "C++"
102%locations
103
104%initial-action {
105 @$.begin.filename = @$.end.filename = &driver.filename_;
106};
107
108%defines
109
110//%glr-parser
111//%expect 1
112
113%debug
114
115%error-verbose
116
117%parse-param { CYDriver &driver }
118%lex-param { void *scanner }
119
120%token Ampersand "&"
121%token AmpersandAmpersand "&&"
122%token AmpersandEqual "&="
123%token Carrot "^"
124%token CarrotEqual "^="
125%token Equal "="
126%token EqualEqual "=="
127%token EqualEqualEqual "==="
128%token Exclamation "!"
129%token ExclamationEqual "!="
130%token ExclamationEqualEqual "!=="
131%token Hyphen "-"
132%token HyphenEqual "-="
133%token HyphenHyphen "--"
134%token HyphenHyphen_ "\n--"
135%token HyphenRight "->"
136%token Left "<"
137%token LeftEqual "<="
138%token LeftLeft "<<"
139%token LeftLeftEqual "<<="
140%token Percent "%"
141%token PercentEqual "%="
142%token Period "."
143%token Pipe "|"
144%token PipeEqual "|="
145%token PipePipe "||"
146%token Plus "+"
147%token PlusEqual "+="
148%token PlusPlus "++"
149%token PlusPlus_ "\n++"
150%token Right ">"
151%token RightEqual ">="
152%token RightRight ">>"
153%token RightRightEqual ">>="
154%token RightRightRight ">>>"
155%token RightRightRightEqual ">>>="
156%token Slash "/"
157%token SlashEqual "/="
158%token Star "*"
159%token StarEqual "*="
160%token Tilde "~"
161
162%token Colon ":"
163%token Comma ","
164%token Question "?"
165%token SemiColon ";"
166%token NewLine "\n"
167
168%token OpenParen "("
169%token CloseParen ")"
170
171%token OpenBrace "{"
172%token CloseBrace "}"
173
174%token OpenBracket "["
175%token CloseBracket "]"
176
177%token AtClass "@class"
178%token AtSelector "@selector"
179%token AtEnd "@end"
180
181%token <false_> False "false"
182%token <null_> Null "null"
183%token <true_> True "true"
184
185// ES3/ES5/WIE/JSC Reserved
186%token <word_> Break "break"
187%token <word_> Case "case"
188%token <word_> Catch "catch"
189%token <word_> Continue "continue"
190%token <word_> Default "default"
191%token <word_> Delete "delete"
192%token <word_> Do "do"
193%token <word_> Else "else"
194%token <word_> Finally "finally"
195%token <word_> For "for"
196%token <word_> Function "function"
197%token <word_> If "if"
198%token <word_> In "in"
199%token <word_> InstanceOf "instanceof"
200%token <word_> New "new"
201%token <word_> Return "return"
202%token <word_> Switch "switch"
203%token <this_> This "this"
204%token <word_> Throw "throw"
205%token <word_> Try "try"
206%token <word_> TypeOf "typeof"
207%token <word_> Var "var"
208%token <word_> Void "void"
209%token <word_> While "while"
210%token <word_> With "with"
211
212// ES3/IE6 Future, ES5/JSC Reserved
213%token <word_> Debugger "debugger"
214
215// ES3/ES5/IE6 Future, JSC Reserved
216%token <word_> Const "const"
217
218// ES3/ES5/IE6/JSC Future
219%token <word_> Class "class"
220%token <word_> Enum "enum"
221%token <word_> Export "export"
222%token <word_> Extends "extends"
223%token <word_> Import "import"
224%token <word_> Super "super"
225
226// ES3 Future, ES5 Strict Future
227%token <identifier_> Implements "implements"
228%token <identifier_> Interface "interface"
229%token <identifier_> Package "package"
230%token <identifier_> Private "private"
231%token <identifier_> Protected "protected"
232%token <identifier_> Public "public"
233%token <identifier_> Static "static"
234
235// ES3 Future
236%token <identifier_> Abstract "abstract"
237%token <identifier_> Boolean "boolean"
238%token <identifier_> Byte "byte"
239%token <identifier_> Char "char"
240%token <identifier_> Double "double"
241%token <identifier_> Final "final"
242%token <identifier_> Float "float"
243%token <identifier_> Goto "goto"
244%token <identifier_> Int "int"
245%token <identifier_> Long "long"
246%token <identifier_> Native "native"
247%token <identifier_> Short "short"
248%token <identifier_> Synchronized "synchronized"
249%token <identifier_> Throws "throws"
250%token <identifier_> Transient "transient"
251%token <identifier_> Volatile "volatile"
252
253// ES5 Strict
254%token <identifier_> Let "let"
255%token <identifier_> Yield "yield"
256
257// Woah?!
258%token <identifier_> Each "each"
259
260%token <identifier_> Identifier_
261%token <number_> NumericLiteral
262%token <string_> StringLiteral
263
264%type <expression_> AdditiveExpression
265%type <expression_> AdditiveExpressionNoBF
266%type <argument_> ArgumentList
267%type <argument_> ArgumentList_
268%type <argument_> ArgumentListOpt
269%type <argument_> Arguments
270%type <literal_> ArrayLiteral
271%type <expression_> AssigneeExpression
272%type <expression_> AssigneeExpression_
273%type <expression_> AssigneeExpressionNoBF
274%type <expression_> AssignmentExpression
275%type <assignment_> AssignmentExpression_
276%type <expression_> AssignmentExpressionNoBF
277%type <expression_> AssignmentExpressionNoIn
278%type <expression_> BitwiseANDExpression
279%type <expression_> BitwiseANDExpressionNoBF
280%type <expression_> BitwiseANDExpressionNoIn
281%type <statement_> Block
282%type <statement_> Block_
283%type <boolean_> BooleanLiteral
284%type <expression_> BitwiseORExpression
285%type <expression_> BitwiseORExpressionNoBF
286%type <expression_> BitwiseORExpressionNoIn
287%type <expression_> BitwiseXORExpression
288%type <expression_> BitwiseXORExpressionNoBF
289%type <expression_> BitwiseXORExpressionNoIn
290%type <statement_> BreakStatement
291%type <expression_> CallExpression
292%type <expression_> CallExpressionNoBF
293%type <clause_> CaseBlock
294%type <clause_> CaseClause
295%type <clause_> CaseClausesOpt
296%type <catch_> CatchOpt
297%type <statement_> CategoryStatement
298%type <class_> ClassDefinition
299%type <message_> ClassMessageDeclaration
300%type <message_> ClassMessageDeclarationListOpt
301%type <className_> ClassName
302%type <className_> ClassNameOpt
303%type <expression_> ClassSuperOpt
304%type <field_> ClassFieldList
305%type <comprehension_> ComprehensionList
306%type <comprehension_> ComprehensionListOpt
307%type <expression_> ConditionalExpression
308%type <expression_> ConditionalExpressionNoBF
309%type <expression_> ConditionalExpressionNoIn
310%type <statement_> ContinueStatement
311%type <clause_> DefaultClause
312%type <statement_> DoWhileStatement
313%type <expression_> Element
314%type <expression_> ElementOpt
315%type <element_> ElementList
316%type <element_> ElementListOpt
317%type <statement_> ElseStatementOpt
318%type <statement_> EmptyStatement
319%type <expression_> EqualityExpression
320%type <expression_> EqualityExpressionNoBF
321%type <expression_> EqualityExpressionNoIn
322%type <expression_> Expression
323%type <expression_> ExpressionOpt
324%type <compound_> Expression_
325%type <expression_> ExpressionNoBF
326%type <expression_> ExpressionNoIn
327%type <compound_> ExpressionNoIn_
328%type <expression_> ExpressionNoInOpt
329%type <statement_> ExpressionStatement
330%type <statement_> FinallyOpt
331%type <comprehension_> ForComprehension
332%type <statement_> ForStatement
333%type <for_> ForStatementInitialiser
334%type <statement_> ForInStatement
335%type <forin_> ForInStatementInitialiser
336%type <functionParameter_> FormalParameterList
337%type <functionParameter_> FormalParameterList_
338%type <source_> FunctionBody
339%type <source_> FunctionDeclaration
340%type <expression_> FunctionExpression
341%type <identifier_> Identifier
342%type <identifier_> IdentifierOpt
343%type <comprehension_> IfComprehension
344%type <statement_> IfStatement
345%type <expression_> Initialiser
346%type <expression_> InitialiserOpt
347%type <expression_> InitialiserNoIn
348%type <expression_> InitialiserNoInOpt
349%type <statement_> IterationStatement
350%type <statement_> LabelledStatement
351%type <expression_> LeftHandSideExpression
352%type <expression_> LeftHandSideExpressionNoBF
353//%type <statement_> LetStatement
354%type <literal_> Literal
355%type <expression_> LogicalANDExpression
356%type <expression_> LogicalANDExpressionNoBF
357%type <expression_> LogicalANDExpressionNoIn
358%type <expression_> LogicalORExpression
359%type <expression_> LogicalORExpressionNoBF
360%type <expression_> LogicalORExpressionNoIn
361%type <member_> MemberAccess
362%type <expression_> MemberExpression
363%type <expression_> MemberExpression_
364%type <expression_> MemberExpressionNoBF
365%type <messageParameter_> MessageParameter
366%type <messageParameter_> MessageParameters
367%type <messageParameter_> MessageParameterList
368%type <messageParameter_> MessageParameterListOpt
369%type <bool_> MessageScope
370%type <expression_> MultiplicativeExpression
371%type <expression_> MultiplicativeExpressionNoBF
372%type <expression_> NewExpression
373%type <expression_> NewExpression_
374%type <expression_> NewExpressionNoBF
375%type <null_> NullLiteral
376%type <literal_> ObjectLiteral
377%type <expression_> PostfixExpression
378%type <expression_> PostfixExpressionNoBF
379%type <expression_> PrimaryExpression
380%type <expression_> PrimaryExpression_
381%type <expression_> PrimaryExpressionNoBF
382%type <source_> Program
383%type <propertyName_> PropertyName
384%type <property_> PropertyNameAndValueList
385%type <property_> PropertyNameAndValueList_
386%type <property_> PropertyNameAndValueListOpt
387%type <expression_> RelationalExpression
388%type <infix_> RelationalExpression_
389%type <expression_> RelationalExpressionNoBF
390%type <expression_> RelationalExpressionNoIn
391%type <infix_> RelationalExpressionNoIn_
392%type <statement_> ReturnStatement
393%type <selector_> SelectorExpression
394%type <selector_> SelectorExpression_
395%type <selector_> SelectorExpressionOpt
396%type <expression_> ShiftExpression
397%type <expression_> ShiftExpressionNoBF
398%type <source_> SourceElement
399%type <source_> SourceElements
400%type <statement_> Statement
401%type <statement_> StatementList
402%type <statement_> StatementListOpt
403%type <statement_> SwitchStatement
404%type <statement_> ThrowStatement
405%type <statement_> TryStatement
406%type <expression_> TypeOpt
407%type <expression_> UnaryExpression
408%type <expression_> UnaryExpression_
409%type <expression_> UnaryExpressionNoBF
410%type <declaration_> VariableDeclaration
411%type <declaration_> VariableDeclarationNoIn
412%type <declarations_> VariableDeclarationList
413%type <declarations_> VariableDeclarationList_
414%type <declarations_> VariableDeclarationListNoIn
415%type <declarations_> VariableDeclarationListNoIn_
416%type <statement_> VariableStatement
417%type <statement_> WhileStatement
418%type <statement_> WithStatement
419%type <word_> Word
420%type <word_> WordOpt
421
422%type <expression_> MessageExpression
423%type <argument_> SelectorCall
424%type <argument_> SelectorCall_
425%type <argument_> SelectorList
426%type <argument_> VariadicCall
427
428%left "*" "/" "%"
429%left "+" "-"
430%left "<<" ">>" ">>>"
431%left "<" ">" "<=" ">=" "instanceof" "in"
432%left "==" "!=" "===" "!=="
433%left "&"
434%left "^"
435%left "|"
436%left "&&"
437%left "||"
438
439%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
440
441%nonassoc "if"
442%nonassoc "else"
443
444%start Program
445
446%%
447
448TerminatorOpt
449 : ";"
450 | "\n"
451 | error { yyerrok; driver.errors_.pop_back(); }
452 ;
453
454Terminator
455 : ";"
456 | "\n"
457 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
458 ;
459
460/*CommaOpt
461 : ","
462 |
463 ;*/
464
465NewLineOpt
466 : "\n"
467 |
468 ;
469
470WordOpt
471 : Word { $$ = $1; }
472 | { $$ = NULL; }
473 ;
474
475Word
476 : Identifier { $$ = $1; }
477 | "break" NewLineOpt { $$ = $1; }
478 | "case" { $$ = $1; }
479 | "catch" { $$ = $1; }
480 | "class" { $$ = $1; }
481 | "const" { $$ = $1; }
482 | "continue" NewLineOpt { $$ = $1; }
483 | "debugger" { $$ = $1; }
484 | "default" { $$ = $1; }
485 | "delete" { $$ = $1; }
486 | "do" { $$ = $1; }
487 | "else" { $$ = $1; }
488 | "enum" { $$ = $1; }
489 | "export" { $$ = $1; }
490 | "extends" { $$ = $1; }
491 | "false" { $$ = $1; }
492 | "finally" { $$ = $1; }
493 | "for" { $$ = $1; }
494 | "function" { $$ = $1; }
495 | "if" { $$ = $1; }
496 | "import" { $$ = $1; }
497 /* XXX: | "in" { $$ = $1; } */
498 /* XXX: | "instanceof" { $$ = $1; } */
499 | "new" { $$ = $1; }
500 | "null" { $$ = $1; }
501 | "return" NewLineOpt { $$ = $1; }
502 | "super" { $$ = $1; }
503 | "switch" { $$ = $1; }
504 | "this" { $$ = $1; }
505 | "throw" NewLineOpt { $$ = $1; }
506 | "true" { $$ = $1; }
507 | "try" { $$ = $1; }
508 | "typeof" { $$ = $1; }
509 | "var" { $$ = $1; }
510 | "void" { $$ = $1; }
511 | "while" { $$ = $1; }
512 | "with" { $$ = $1; }
513 ;
514
515Identifier
516 : Identifier_ { $$ = $1; }
517
518 | "implements" { $$ = $1; }
519 | "interface" { $$ = $1; }
520 | "package" { $$ = $1; }
521 | "private" { $$ = $1; }
522 | "protected" { $$ = $1; }
523 | "public" { $$ = $1; }
524 | "static" { $$ = $1; }
525
526 | "abstract" { $$ = $1; }
527 | "boolean" { $$ = $1; }
528 | "byte" { $$ = $1; }
529 | "char" { $$ = $1; }
530 | "double" { $$ = $1; }
531 | "final" { $$ = $1; }
532 | "float" { $$ = $1; }
533 | "goto" { $$ = $1; }
534 | "int" { $$ = $1; }
535 | "long" { $$ = $1; }
536 | "native" { $$ = $1; }
537 | "short" { $$ = $1; }
538 | "synchronized" { $$ = $1; }
539 | "throws" { $$ = $1; }
540 | "transient" { $$ = $1; }
541 | "volatile" { $$ = $1; }
542
543 | "let" { $$ = $1; }
544 | "yield" { $$ = $1; }
545
546 | "each" { $$ = $1; }
547 ;
548
549IdentifierOpt
550 : Identifier { $$ = $1; }
551 | { $$ = NULL; }
552 ;
553
554Literal
555 : NullLiteral { $$ = $1; }
556 | BooleanLiteral { $$ = $1; }
557 | NumericLiteral { $$ = $1; }
558 | StringLiteral { $$ = $1; }
559 ;
560
561NullLiteral
562 : "null" { $$ = $1; }
563 ;
564
565BooleanLiteral
566 : "true" { $$ = $1; }
567 | "false" { $$ = $1; }
568 ;
569
570/* 11.1 Primary Expressions {{{ */
571PrimaryExpression_
572 : "this" { $$ = $1; }
573 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
574 | Literal { $$ = $1; }
575 | ArrayLiteral { $$ = $1; }
576 | "(" Expression ")" { $$ = $2; }
577 ;
578
579PrimaryExpression
580 : ObjectLiteral { $$ = $1; }
581 | PrimaryExpression_ { $$ = $1; }
582 ;
583
584PrimaryExpressionNoBF
585 : PrimaryExpression_ { $$ = $1; }
586 ;
587/* }}} */
588/* 11.1.4 Array Initialiser {{{ */
589ArrayLiteral
590 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
591 ;
592
593Element
594 : AssignmentExpression { $$ = $1; }
595 ;
596
597ElementOpt
598 : Element { $$ = $1; }
599 | { $$ = NULL; }
600 ;
601
602ElementListOpt
603 : ElementList { $$ = $1; }
604 | { $$ = NULL; }
605 ;
606
607ElementList
608 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
609 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
610 ;
611/* }}} */
612/* 11.1.5 Object Initialiser {{{ */
613ObjectLiteral
614 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
615 ;
616
617PropertyNameAndValueList_
618 : "," PropertyNameAndValueList { $$ = $2; }
619 | { $$ = NULL; }
620 ;
621
622PropertyNameAndValueListOpt
623 : PropertyNameAndValueList { $$ = $1; }
624 | { $$ = NULL; }
625 ;
626
627PropertyNameAndValueList
628 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
629 ;
630
631PropertyName
632 : Identifier { $$ = $1; }
633 | StringLiteral { $$ = $1; }
634 | NumericLiteral { $$ = $1; }
635 ;
636/* }}} */
637
638MemberExpression_
639 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
640 ;
641
642MemberAccess
643 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
644 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
645 ;
646
647MemberExpression
648 : PrimaryExpression { $$ = $1; }
649 | FunctionExpression { $$ = $1; }
650 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
651 | MemberExpression_ { $$ = $1; }
652 ;
653
654MemberExpressionNoBF
655 : PrimaryExpressionNoBF { $$ = $1; }
656 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
657 | MemberExpression_ { $$ = $1; }
658 ;
659
660NewExpression_
661 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
662 ;
663
664NewExpression
665 : MemberExpression { $$ = $1; }
666 | NewExpression_ { $$ = $1; }
667 ;
668
669NewExpressionNoBF
670 : MemberExpressionNoBF { $$ = $1; }
671 | NewExpression_ { $$ = $1; }
672 ;
673
674CallExpression
675 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
676 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
677 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
678 ;
679
680CallExpressionNoBF
681 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
682 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
683 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
684 ;
685
686ArgumentList_
687 : "," ArgumentList { $$ = $2; }
688 | { $$ = NULL; }
689 ;
690
691ArgumentListOpt
692 : ArgumentList { $$ = $1; }
693 | { $$ = NULL; }
694 ;
695
696ArgumentList
697 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
698 ;
699
700Arguments
701 : "(" ArgumentListOpt ")" { $$ = $2; }
702 ;
703
704LeftHandSideExpression
705 : NewExpression { $$ = $1; }
706 | CallExpression { $$ = $1; }
707 ;
708
709LeftHandSideExpressionNoBF
710 : NewExpressionNoBF { $$ = $1; }
711 | CallExpressionNoBF { $$ = $1; }
712 ;
713
714PostfixExpression
715 : AssigneeExpression { $$ = $1; }
716 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
717 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
718 ;
719
720PostfixExpressionNoBF
721 : AssigneeExpressionNoBF { $$ = $1; }
722 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
723 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
724 ;
725
726UnaryExpression_
727 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
728 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
729 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
730 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
731 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
732 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
733 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
734 | "+" UnaryExpression { $$ = $2; }
735 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
736 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
737 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
738 ;
739
740UnaryExpression
741 : PostfixExpression { $$ = $1; }
742 | UnaryExpression_ { $$ = $1; }
743 ;
744
745UnaryExpressionNoBF
746 : PostfixExpressionNoBF { $$ = $1; }
747 | UnaryExpression_ { $$ = $1; }
748 ;
749
750MultiplicativeExpression
751 : UnaryExpression { $$ = $1; }
752 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
753 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
754 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
755 ;
756
757MultiplicativeExpressionNoBF
758 : UnaryExpressionNoBF { $$ = $1; }
759 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
760 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
761 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
762 ;
763
764AdditiveExpression
765 : MultiplicativeExpression { $$ = $1; }
766 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
767 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
768 ;
769
770AdditiveExpressionNoBF
771 : MultiplicativeExpressionNoBF { $$ = $1; }
772 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
773 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
774 ;
775
776ShiftExpression
777 : AdditiveExpression { $$ = $1; }
778 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
779 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
780 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
781 ;
782
783ShiftExpressionNoBF
784 : AdditiveExpressionNoBF { $$ = $1; }
785 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
786 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
787 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
788 ;
789
790RelationalExpressionNoIn_
791 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
792 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
793 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
794 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
795 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
796 ;
797
798RelationalExpression_
799 : RelationalExpressionNoIn_ { $$ = $1; }
800 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
801 ;
802
803RelationalExpression
804 : ShiftExpression { $$ = $1; }
805 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
806 ;
807
808RelationalExpressionNoIn
809 : ShiftExpression { $$ = $1; }
810 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
811 ;
812
813RelationalExpressionNoBF
814 : ShiftExpressionNoBF { $$ = $1; }
815 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
816 ;
817
818EqualityExpression
819 : RelationalExpression { $$ = $1; }
820 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
821 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
822 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
823 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
824 ;
825
826EqualityExpressionNoIn
827 : RelationalExpressionNoIn { $$ = $1; }
828 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
829 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
830 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
831 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
832 ;
833
834EqualityExpressionNoBF
835 : RelationalExpressionNoBF { $$ = $1; }
836 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
837 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
838 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
839 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
840 ;
841
842BitwiseANDExpression
843 : EqualityExpression { $$ = $1; }
844 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
845 ;
846
847BitwiseANDExpressionNoIn
848 : EqualityExpressionNoIn { $$ = $1; }
849 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
850 ;
851
852BitwiseANDExpressionNoBF
853 : EqualityExpressionNoBF { $$ = $1; }
854 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
855 ;
856
857BitwiseXORExpression
858 : BitwiseANDExpression { $$ = $1; }
859 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
860 ;
861
862BitwiseXORExpressionNoIn
863 : BitwiseANDExpressionNoIn { $$ = $1; }
864 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
865 ;
866
867BitwiseXORExpressionNoBF
868 : BitwiseANDExpressionNoBF { $$ = $1; }
869 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
870 ;
871
872BitwiseORExpression
873 : BitwiseXORExpression { $$ = $1; }
874 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
875 ;
876
877BitwiseORExpressionNoIn
878 : BitwiseXORExpressionNoIn { $$ = $1; }
879 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
880 ;
881
882BitwiseORExpressionNoBF
883 : BitwiseXORExpressionNoBF { $$ = $1; }
884 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
885 ;
886
887LogicalANDExpression
888 : BitwiseORExpression { $$ = $1; }
889 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
890 ;
891
892LogicalANDExpressionNoIn
893 : BitwiseORExpressionNoIn { $$ = $1; }
894 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
895 ;
896
897LogicalANDExpressionNoBF
898 : BitwiseORExpressionNoBF { $$ = $1; }
899 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
900 ;
901
902LogicalORExpression
903 : LogicalANDExpression { $$ = $1; }
904 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
905 ;
906
907LogicalORExpressionNoIn
908 : LogicalANDExpressionNoIn { $$ = $1; }
909 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
910 ;
911
912LogicalORExpressionNoBF
913 : LogicalANDExpressionNoBF { $$ = $1; }
914 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
915 ;
916
917ConditionalExpression
918 : LogicalORExpression { $$ = $1; }
919 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
920 ;
921
922ConditionalExpressionNoIn
923 : LogicalORExpressionNoIn { $$ = $1; }
924 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
925 ;
926
927ConditionalExpressionNoBF
928 : LogicalORExpressionNoBF { $$ = $1; }
929 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
930 ;
931
932AssignmentExpression_
933 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
934 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
935 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
936 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
937 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
938 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
939 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
940 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
941 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
942 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
943 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
944 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
945 ;
946
947AssigneeExpression
948 : LeftHandSideExpression { $$ = $1; }
949 | AssigneeExpression_ { $$ = $1; }
950 ;
951
952AssigneeExpressionNoBF
953 : LeftHandSideExpressionNoBF { $$ = $1; }
954 | AssigneeExpression_ { $$ = $1; }
955 ;
956
957AssignmentExpression
958 : ConditionalExpression { $$ = $1; }
959 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
960 ;
961
962AssignmentExpressionNoIn
963 : ConditionalExpressionNoIn { $$ = $1; }
964 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
965 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
966 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
967 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
968 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
969 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
970 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
971 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
972 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
973 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
974 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
975 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
976 ;
977
978AssignmentExpressionNoBF
979 : ConditionalExpressionNoBF { $$ = $1; }
980 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
981 ;
982
983Expression_
984 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
985 | { $$ = NULL; }
986 ;
987
988ExpressionNoIn_
989 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
990 | { $$ = NULL; }
991 ;
992
993ExpressionOpt
994 : Expression { $$ = $1; }
995 | { $$ = NULL; }
996 ;
997
998ExpressionNoInOpt
999 : ExpressionNoIn { $$ = $1; }
1000 | { $$ = NULL; }
1001 ;
1002
1003Expression
1004 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1005 ;
1006
1007ExpressionNoIn
1008 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1009 ;
1010
1011ExpressionNoBF
1012 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1013 ;
1014
1015Statement
1016 : Block { $$ = $1; }
1017 | VariableStatement { $$ = $1; }
1018 | EmptyStatement { $$ = $1; }
1019 | ExpressionStatement { $$ = $1; }
1020 | IfStatement { $$ = $1; }
1021 | IterationStatement { $$ = $1; }
1022 | ContinueStatement { $$ = $1; }
1023 | BreakStatement { $$ = $1; }
1024 | ReturnStatement { $$ = $1; }
1025 | WithStatement { $$ = $1; }
1026 | LabelledStatement { $$ = $1; }
1027 | SwitchStatement { $$ = $1; }
1028 | ThrowStatement { $$ = $1; }
1029 | TryStatement { $$ = $1; }
1030 ;
1031
1032Block_
1033 : "{" StatementListOpt "}" { $$ = $2; }
1034 ;
1035
1036Block
1037 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1038 ;
1039
1040StatementList
1041 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
1042 ;
1043
1044StatementListOpt
1045 : StatementList { $$ = $1; }
1046 | { $$ = NULL; }
1047 ;
1048
1049VariableStatement
1050 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1051 ;
1052
1053VariableDeclarationList_
1054 : "," VariableDeclarationList { $$ = $2; }
1055 | { $$ = NULL; }
1056 ;
1057
1058VariableDeclarationListNoIn_
1059 : "," VariableDeclarationListNoIn { $$ = $2; }
1060 | { $$ = NULL; }
1061 ;
1062
1063VariableDeclarationList
1064 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1065 ;
1066
1067VariableDeclarationListNoIn
1068 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1069 ;
1070
1071VariableDeclaration
1072 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1073 ;
1074
1075VariableDeclarationNoIn
1076 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1077 ;
1078
1079InitialiserOpt
1080 : Initialiser { $$ = $1; }
1081 | { $$ = NULL; }
1082 ;
1083
1084InitialiserNoInOpt
1085 : InitialiserNoIn { $$ = $1; }
1086 | { $$ = NULL; }
1087 ;
1088
1089Initialiser
1090 : "=" AssignmentExpression { $$ = $2; }
1091 ;
1092
1093InitialiserNoIn
1094 : "=" AssignmentExpressionNoIn { $$ = $2; }
1095 ;
1096
1097EmptyStatement
1098 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1099 ;
1100
1101ExpressionStatement
1102 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1103 ;
1104
1105ElseStatementOpt
1106 : "else" Statement { $$ = $2; }
1107 | %prec "if" { $$ = NULL; }
1108 ;
1109
1110IfStatement
1111 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1112 ;
1113
1114IterationStatement
1115 : DoWhileStatement { $$ = $1; }
1116 | WhileStatement { $$ = $1; }
1117 | ForStatement { $$ = $1; }
1118 | ForInStatement { $$ = $1; }
1119 ;
1120
1121DoWhileStatement
1122 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1123 ;
1124
1125WhileStatement
1126 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1127 ;
1128
1129ForStatement
1130 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1131 ;
1132
1133ForStatementInitialiser
1134 : ExpressionNoInOpt { $$ = $1; }
1135 | "var" VariableDeclarationListNoIn { $$ = $2; }
1136 ;
1137
1138ForInStatement
1139 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1140 ;
1141
1142ForInStatementInitialiser
1143 : LeftHandSideExpression { $$ = $1; }
1144 | "var" VariableDeclarationNoIn { $$ = $2; }
1145 ;
1146
1147ContinueStatement
1148 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1149 ;
1150
1151BreakStatement
1152 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1153 ;
1154
1155ReturnStatement
1156 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1157 ;
1158
1159WithStatement
1160 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1161 ;
1162
1163SwitchStatement
1164 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1165 ;
1166
1167CaseBlock
1168 : "{" CaseClausesOpt "}" { $$ = $2; }
1169 ;
1170
1171CaseClausesOpt
1172 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1173 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1174 | { $$ = NULL; }
1175 ;
1176
1177CaseClause
1178 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1179 ;
1180
1181DefaultClause
1182 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1183 ;
1184
1185LabelledStatement
1186 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1187 ;
1188
1189ThrowStatement
1190 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1191 ;
1192
1193TryStatement
1194 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1195 ;
1196
1197CatchOpt
1198 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
1199 | { $$ = NULL; }
1200 ;
1201
1202FinallyOpt
1203 : "finally" Block_ { $$ = $2; }
1204 | { $$ = NULL; }
1205 ;
1206
1207FunctionDeclaration
1208 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1209 ;
1210
1211FunctionExpression
1212 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1213 ;
1214
1215FormalParameterList_
1216 : "," FormalParameterList { $$ = $2; }
1217 | { $$ = NULL; }
1218 ;
1219
1220FormalParameterList
1221 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1222 | { $$ = NULL; }
1223 ;
1224
1225FunctionBody
1226 : SourceElements { $$ = $1; }
1227 ;
1228
1229Program
1230 : SourceElements { driver.source_ = $1; }
1231 ;
1232
1233SourceElements
1234 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1235 | { $$ = NULL; }
1236 ;
1237
1238SourceElement
1239 : Statement { $$ = $1; }
1240 | FunctionDeclaration { $$ = $1; }
1241 ;
1242
1243/* Cycript: @class Declaration {{{ */
1244ClassSuperOpt
1245 : ":" MemberExpressionNoBF { $$ = $2; }
1246 | { $$ = NULL; }
1247 ;
1248
1249ClassFieldList
1250 : "{" "}" { $$ = NULL; }
1251 ;
1252
1253MessageScope
1254 : "+" { $$ = false; }
1255 | "-" { $$ = true; }
1256 ;
1257
1258TypeOpt
1259 : "(" Expression ")" { $$ = $2; }
1260 | { $$ = NULL; }
1261 ;
1262
1263MessageParameter
1264 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
1265 ;
1266
1267MessageParameterListOpt
1268 : MessageParameterList { $$ = $1; }
1269 | { $$ = NULL; }
1270 ;
1271
1272MessageParameterList
1273 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1274 ;
1275
1276MessageParameters
1277 : MessageParameterList { $$ = $1; }
1278 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
1279 ;
1280
1281ClassMessageDeclaration
1282 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
1283 ;
1284
1285ClassMessageDeclarationListOpt
1286 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1287 | { $$ = NULL; }
1288 ;
1289
1290ClassName
1291 : Identifier { $$ = $1; }
1292 | "(" AssignmentExpression ")" { $$ = $2; }
1293 ;
1294
1295ClassNameOpt
1296 : ClassName { $$ = $1; }
1297 | { $$ = NULL; }
1298 ;
1299
1300ClassDefinition
1301 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClass($2, $3, $4, $5); }
1302 ;
1303
1304CategoryStatement
1305 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
1306 ;
1307
1308PrimaryExpression
1309 : ClassDefinition { $$ = $1; }
1310 ;
1311
1312Statement
1313 : ClassDefinition { $$ = $1; }
1314 | CategoryStatement { $$ = $1; }
1315 ;
1316/* }}} */
1317/* Cycript: Send Message {{{ */
1318VariadicCall
1319 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1320 | { $$ = NULL; }
1321 ;
1322
1323SelectorCall_
1324 : SelectorCall { $$ = $1; }
1325 | VariadicCall { $$ = $1; }
1326 ;
1327
1328SelectorCall
1329 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1330 ;
1331
1332SelectorList
1333 : SelectorCall { $$ = $1; }
1334 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1335 ;
1336
1337MessageExpression
1338 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
1339 ;
1340
1341SelectorExpressionOpt
1342 : SelectorExpression_ { $$ = $1; }
1343 | { $$ = NULL; }
1344 ;
1345
1346SelectorExpression_
1347 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1348 ;
1349
1350SelectorExpression
1351 : SelectorExpression_ { $$ = $1; }
1352 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1353 ;
1354
1355PrimaryExpression_
1356 : MessageExpression { $$ = $1; }
1357 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
1358 ;
1359/* }}} */
1360/* Cycript: Pointer Indirection/Addressing {{{ */
1361AssigneeExpression_
1362 : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
1363 ;
1364
1365UnaryExpression_
1366 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1367 ;
1368
1369MemberAccess
1370 : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
1371 ;
1372/* }}} */
1373/* ECMAScript5: Object Literal Trailing Comma {{{ */
1374PropertyNameAndValueList_
1375 : "," { $$ = NULL; }
1376 ;
1377/* }}} */
1378/* JavaScript 1.7: Array Comprehensions {{{ */
1379IfComprehension
1380 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
1381 ;
1382
1383ForComprehension
1384 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1385 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
1386 ;
1387
1388ComprehensionListOpt
1389 : ComprehensionList { $$ = $1; }
1390 | IfComprehension { $$ = $1; }
1391 | { $$ = NULL; }
1392 ;
1393
1394ComprehensionList
1395 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1396 ;
1397
1398PrimaryExpression_
1399 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
1400 ;
1401/* }}} */
1402/* JavaScript 1.7: for each {{{ */
1403ForInStatement
1404 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1405 ;
1406/* }}} */
1407/* JavaScript 1.7: Let Statements {{{ *//*
1408LetStatement
1409 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
1410 ;
1411
1412Statement
1413 : LetStatement
1414 ;
1415*//* }}} */
1416
1417%%