]> git.saurik.com Git - cycript.git/blob - Cycript.y
31fd1bc9d49bbfde70725c235b1e5cc5b3c519be
[cycript.git] / Cycript.y
1 %code top {
2 #include "Cycript.tab.hh"
3 #define scanner driver.scanner_
4 #define YYSTACKEXPANDABLE 1
5 }
6
7 %code requires {
8 #include "Parser.hpp"
9
10 typedef struct {
11 bool newline_;
12
13 union {
14 CYArgument *argument_;
15 CYBoolean *boolean_;
16 CYClause *clause_;
17 CYCatch *catch_;
18 CYDeclaration *declaration_;
19 CYDeclarations *declarations_;
20 CYElement *element_;
21 CYExpression *expression_;
22 CYFalse *false_;
23 CYForInitialiser *for_;
24 CYForInInitialiser *forin_;
25 CYIdentifier *identifier_;
26 CYLiteral *literal_;
27 CYName *name_;
28 CYNull *null_;
29 CYNumber *number_;
30 CYParameter *parameter_;
31 CYProperty *property_;
32 CYSelectorPart *selector_;
33 CYSource *source_;
34 CYStatement *statement_;
35 CYString *string_;
36 CYThis *this_;
37 CYTrue *true_;
38 CYWord *word_;
39 };
40 } YYSTYPE;
41
42 }
43
44 %code provides {
45 int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
46 }
47
48 %name-prefix "cy"
49
50 %language "C++"
51 %locations
52
53 %initial-action {
54 @$.begin.filename = @$.end.filename = &driver.filename_;
55 };
56
57 %defines
58
59 %debug
60 %error-verbose
61
62 %parse-param { CYDriver &driver }
63 %lex-param { void *scanner }
64
65 %token Ampersand "&"
66 %token AmpersandAmpersand "&&"
67 %token AmpersandEqual "&="
68 %token Carrot "^"
69 %token CarrotEqual "^="
70 %token Equal "="
71 %token EqualEqual "=="
72 %token EqualEqualEqual "==="
73 %token Exclamation "!"
74 %token ExclamationEqual "!="
75 %token ExclamationEqualEqual "!=="
76 %token Hyphen "-"
77 %token HyphenEqual "-="
78 %token HyphenHyphen "--"
79 %token HyphenHyphen_ "\n--"
80 %token HyphenRight "->"
81 %token Left "<"
82 %token LeftEqual "<="
83 %token LeftLeft "<<"
84 %token LeftLeftEqual "<<="
85 %token Percent "%"
86 %token PercentEqual "%="
87 %token Period "."
88 %token Pipe "|"
89 %token PipeEqual "|="
90 %token PipePipe "||"
91 %token Plus "+"
92 %token PlusEqual "+="
93 %token PlusPlus "++"
94 %token PlusPlus_ "\n++"
95 %token Right ">"
96 %token RightEqual ">="
97 %token RightRight ">>"
98 %token RightRightEqual ">>="
99 %token RightRightRight ">>>"
100 %token RightRightRightEqual ">>>="
101 %token Slash "/"
102 %token SlashEqual "/="
103 %token Star "*"
104 %token StarEqual "*="
105 %token Tilde "~"
106
107 %token Colon ":"
108 %token Comma ","
109 %token Question "?"
110 %token SemiColon ";"
111 %token NewLine "\n"
112
113 %token OpenParen "("
114 %token CloseParen ")"
115
116 %token OpenBrace "{"
117 %token CloseBrace "}"
118
119 %token OpenBracket "["
120 %token CloseBracket "]"
121
122 %token AtSelector "@selector"
123
124 %token <word_> Break "break"
125 %token <word_> Case "case"
126 %token <word_> Catch "catch"
127 %token <word_> Continue "continue"
128 %token <word_> Default "default"
129 %token <word_> Delete "delete"
130 %token <word_> Do "do"
131 %token <word_> Else "else"
132 %token <false_> False "false"
133 %token <word_> Finally "finally"
134 %token <word_> For "for"
135 %token <word_> Function "function"
136 %token <word_> If "if"
137 %token <word_> In "in"
138 %token <word_> InstanceOf "instanceof"
139 %token <word_> New "new"
140 %token <null_> Null "null"
141 %token <word_> Return "return"
142 %token <word_> Switch "switch"
143 %token <this_> This "this"
144 %token <word_> Throw "throw"
145 %token <true_> True "true"
146 %token <word_> Try "try"
147 %token <word_> TypeOf "typeof"
148 %token <word_> Var "var"
149 %token <word_> Void "void"
150 %token <word_> While "while"
151 %token <word_> With "with"
152
153 %token <identifier_> Identifier
154 %token <number_> NumericLiteral
155 %token <string_> StringLiteral
156
157 %type <expression_> AdditiveExpression
158 %type <expression_> AdditiveExpressionNoBF
159 %type <argument_> ArgumentList
160 %type <argument_> ArgumentList_
161 %type <argument_> ArgumentListOpt
162 %type <argument_> Arguments
163 %type <literal_> ArrayLiteral
164 %type <expression_> AssignmentExpression
165 %type <expression_> AssignmentExpressionNoBF
166 %type <expression_> AssignmentExpressionNoIn
167 %type <expression_> BitwiseANDExpression
168 %type <expression_> BitwiseANDExpressionNoBF
169 %type <expression_> BitwiseANDExpressionNoIn
170 %type <statement_> Block
171 %type <boolean_> BooleanLiteral
172 %type <expression_> BitwiseORExpression
173 %type <expression_> BitwiseORExpressionNoBF
174 %type <expression_> BitwiseORExpressionNoIn
175 %type <expression_> BitwiseXORExpression
176 %type <expression_> BitwiseXORExpressionNoBF
177 %type <expression_> BitwiseXORExpressionNoIn
178 %type <statement_> BreakStatement
179 %type <expression_> CallExpression
180 %type <expression_> CallExpressionNoBF
181 %type <clause_> CaseBlock
182 %type <clause_> CaseClause
183 %type <clause_> CaseClausesOpt
184 %type <catch_> CatchOpt
185 %type <expression_> ConditionalExpression
186 %type <expression_> ConditionalExpressionNoBF
187 %type <expression_> ConditionalExpressionNoIn
188 %type <statement_> ContinueStatement
189 %type <clause_> DefaultClause
190 %type <statement_> DoWhileStatement
191 %type <expression_> Element
192 %type <expression_> ElementOpt
193 %type <element_> ElementList
194 %type <element_> ElementListOpt
195 %type <statement_> ElseStatementOpt
196 %type <statement_> EmptyStatement
197 %type <expression_> EqualityExpression
198 %type <expression_> EqualityExpressionNoBF
199 %type <expression_> EqualityExpressionNoIn
200 %type <expression_> Expression
201 %type <expression_> ExpressionOpt
202 %type <expression_> Expression_
203 %type <expression_> ExpressionNoBF
204 %type <expression_> ExpressionNoIn
205 %type <expression_> ExpressionNoIn_
206 %type <expression_> ExpressionNoInOpt
207 %type <statement_> ExpressionStatement
208 %type <statement_> FinallyOpt
209 %type <statement_> ForStatement
210 %type <for_> ForStatementInitialiser
211 %type <statement_> ForInStatement
212 %type <forin_> ForInStatementInitialiser
213 %type <parameter_> FormalParameterList
214 %type <parameter_> FormalParameterList_
215 %type <source_> FunctionBody
216 %type <source_> FunctionDeclaration
217 %type <expression_> FunctionExpression
218 %type <identifier_> IdentifierOpt
219 %type <statement_> IfStatement
220 %type <expression_> Initialiser
221 %type <expression_> InitialiserOpt
222 %type <expression_> InitialiserNoIn
223 %type <expression_> InitialiserNoInOpt
224 %type <statement_> IterationStatement
225 %type <statement_> LabelledStatement
226 %type <expression_> LeftHandSideExpression
227 %type <expression_> LeftHandSideExpression_
228 %type <expression_> LeftHandSideExpressionNoBF
229 %type <literal_> Literal
230 %type <expression_> LogicalANDExpression
231 %type <expression_> LogicalANDExpressionNoBF
232 %type <expression_> LogicalANDExpressionNoIn
233 %type <expression_> LogicalORExpression
234 %type <expression_> LogicalORExpressionNoBF
235 %type <expression_> LogicalORExpressionNoIn
236 %type <expression_> MemberExpression
237 %type <expression_> MemberExpression_
238 %type <expression_> MemberExpressionNoBF
239 %type <expression_> MultiplicativeExpression
240 %type <expression_> MultiplicativeExpressionNoBF
241 %type <expression_> NewExpression
242 %type <expression_> NewExpression_
243 %type <expression_> NewExpressionNoBF
244 %type <null_> NullLiteral
245 %type <literal_> ObjectLiteral
246 %type <expression_> PostfixExpression
247 %type <expression_> PostfixExpressionNoBF
248 %type <expression_> PrimaryExpression
249 %type <expression_> PrimaryExpression_
250 %type <expression_> PrimaryExpressionNoBF
251 %type <source_> Program
252 %type <name_> PropertyName
253 %type <property_> PropertyNameAndValueList
254 %type <property_> PropertyNameAndValueList_
255 %type <property_> PropertyNameAndValueListOpt
256 %type <expression_> RelationalExpression
257 %type <expression_> RelationalExpressionNoBF
258 %type <expression_> RelationalExpressionNoIn
259 %type <statement_> ReturnStatement
260 %type <selector_> SelectorExpression
261 %type <selector_> SelectorExpression_
262 %type <selector_> SelectorExpressionOpt
263 %type <expression_> ShiftExpression
264 %type <expression_> ShiftExpressionNoBF
265 %type <source_> SourceElement
266 %type <source_> SourceElements
267 %type <statement_> Statement
268 %type <statement_> StatementList
269 %type <statement_> StatementListOpt
270 %type <statement_> SwitchStatement
271 %type <statement_> ThrowStatement
272 %type <statement_> TryStatement
273 %type <expression_> UnaryExpression
274 %type <expression_> UnaryExpression_
275 %type <expression_> UnaryExpressionNoBF
276 %type <declaration_> VariableDeclaration
277 %type <declaration_> VariableDeclarationNoIn
278 %type <declarations_> VariableDeclarationList
279 %type <declarations_> VariableDeclarationList_
280 %type <declarations_> VariableDeclarationListNoIn
281 %type <declarations_> VariableDeclarationListNoIn_
282 %type <statement_> VariableStatement
283 %type <statement_> WhileStatement
284 %type <statement_> WithStatement
285 %type <word_> Word
286 %type <word_> WordOpt
287
288 %type <expression_> MessageExpression
289 %type <argument_> SelectorCall
290 %type <argument_> SelectorCall_
291 %type <argument_> SelectorList
292 %type <argument_> VariadicCall
293
294 %nonassoc "if"
295 %nonassoc "else"
296
297 %start Program
298
299 %%
300
301 TerminatorOpt
302 : ";"
303 | "\n"
304 | error { yyerrok; driver.errors_.pop_back(); }
305 ;
306
307 Terminator
308 : ";"
309 | "\n"
310 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
311 ;
312
313 CommaOpt
314 : ","
315 |
316 ;
317
318 NewLineOpt
319 : "\n"
320 |
321 ;
322
323 WordOpt
324 : Word { $$ = $1; }
325 | { $$ = NULL; }
326 ;
327
328 Word
329 : Identifier { $$ = $1; }
330 | "break" NewLineOpt { $$ = $1; }
331 | "case" { $$ = $1; }
332 | "catch" { $$ = $1; }
333 | "continue" NewLineOpt { $$ = $1; }
334 | "default" { $$ = $1; }
335 | "delete" { $$ = $1; }
336 | "do" { $$ = $1; }
337 | "else" { $$ = $1; }
338 | "false" { $$ = $1; }
339 | "finally" { $$ = $1; }
340 | "for" { $$ = $1; }
341 | "function" { $$ = $1; }
342 | "if" { $$ = $1; }
343 /* XXX: | "in" { $$ = $1; } */
344 /* XXX: | "instanceof" { $$ = $1; } */
345 | "new" { $$ = $1; }
346 | "null" { $$ = $1; }
347 | "return" NewLineOpt { $$ = $1; }
348 | "switch" { $$ = $1; }
349 | "this" { $$ = $1; }
350 | "throw" NewLineOpt { $$ = $1; }
351 | "true" { $$ = $1; }
352 | "try" { $$ = $1; }
353 | "typeof" { $$ = $1; }
354 | "var" { $$ = $1; }
355 | "void" { $$ = $1; }
356 | "while" { $$ = $1; }
357 | "with" { $$ = $1; }
358 ;
359
360 IdentifierOpt
361 : Identifier { $$ = $1; }
362 | { $$ = NULL; }
363 ;
364
365 Literal
366 : NullLiteral { $$ = $1; }
367 | BooleanLiteral { $$ = $1; }
368 | NumericLiteral { $$ = $1; }
369 | StringLiteral { $$ = $1; }
370 ;
371
372 NullLiteral
373 : "null" { $$ = $1; }
374 ;
375
376 BooleanLiteral
377 : "true" { $$ = $1; }
378 | "false" { $$ = $1; }
379 ;
380
381 /* 11.1 Primary Expressions {{{ */
382 PrimaryExpression_
383 : "this" { $$ = $1; }
384 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
385 | Literal { $$ = $1; }
386 | ArrayLiteral { $$ = $1; }
387 | "(" Expression ")" { $$ = $2; }
388 ;
389
390 PrimaryExpression
391 : ObjectLiteral { $$ = $1; }
392 | PrimaryExpression_ { $$ = $1; }
393 ;
394
395 PrimaryExpressionNoBF
396 : PrimaryExpression_ { $$ = $1; }
397 ;
398 /* }}} */
399 /* 11.1.4 Array Initialiser {{{ */
400 ArrayLiteral
401 : "[" ElementList "]" { $$ = new(driver.pool_) CYArray($2); }
402 ;
403
404 Element
405 : AssignmentExpression { $$ = $1; }
406 ;
407
408 ElementOpt
409 : Element { $$ = $1; }
410 | { $$ = NULL; }
411 ;
412
413 ElementListOpt
414 : ElementList { $$ = $1; }
415 | { $$ = NULL; }
416 ;
417
418 ElementList
419 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
420 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
421 ;
422 /* }}} */
423 /* 11.1.5 Object Initialiser {{{ */
424 ObjectLiteral
425 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
426 ;
427
428 PropertyNameAndValueList_
429 : "," PropertyNameAndValueList { $$ = $2; }
430 | CommaOpt { $$ = NULL; }
431 ;
432
433 PropertyNameAndValueListOpt
434 : PropertyNameAndValueList { $$ = $1; }
435 | { $$ = NULL; }
436 ;
437
438 PropertyNameAndValueList
439 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
440 ;
441
442 PropertyName
443 : Identifier { $$ = $1; }
444 | StringLiteral { $$ = $1; }
445 | NumericLiteral { $$ = $1; }
446 ;
447 /* }}} */
448
449 MemberExpression_
450 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
451 ;
452
453 MemberExpression
454 : PrimaryExpression { $$ = $1; }
455 | FunctionExpression { $$ = $1; }
456 | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
457 | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
458 | MemberExpression_ { $$ = $1; }
459 ;
460
461 MemberExpressionNoBF
462 : PrimaryExpressionNoBF { $$ = $1; }
463 | MemberExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
464 | MemberExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
465 | MemberExpression_ { $$ = $1; }
466 ;
467
468 NewExpression_
469 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
470 ;
471
472 NewExpression
473 : MemberExpression { $$ = $1; }
474 | NewExpression_ { $$ = $1; }
475 ;
476
477 NewExpressionNoBF
478 : MemberExpressionNoBF { $$ = $1; }
479 | NewExpression_ { $$ = $1; }
480 ;
481
482 CallExpression
483 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
484 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
485 | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
486 | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
487 ;
488
489 CallExpressionNoBF
490 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
491 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
492 | CallExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
493 | CallExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
494 ;
495
496 ArgumentList_
497 : "," ArgumentList { $$ = $2; }
498 | { $$ = NULL; }
499 ;
500
501 ArgumentListOpt
502 : ArgumentList { $$ = $1; }
503 | { $$ = NULL; }
504 ;
505
506 ArgumentList
507 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
508 ;
509
510 Arguments
511 : "(" ArgumentListOpt ")" { $$ = $2; }
512 ;
513
514 LeftHandSideExpression
515 : NewExpression { $$ = $1; }
516 | CallExpression { $$ = $1; }
517 | LeftHandSideExpression_ { $$ = $1; }
518 ;
519
520 LeftHandSideExpressionNoBF
521 : NewExpressionNoBF { $$ = $1; }
522 | CallExpressionNoBF { $$ = $1; }
523 | LeftHandSideExpression_ { $$ = $1; }
524 ;
525
526 PostfixExpression
527 : LeftHandSideExpression { $$ = $1; }
528 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
529 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
530 ;
531
532 PostfixExpressionNoBF
533 : LeftHandSideExpressionNoBF { $$ = $1; }
534 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
535 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
536 ;
537
538 UnaryExpression_
539 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
540 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
541 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
542 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
543 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
544 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
545 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
546 | "+" UnaryExpression { $$ = $2; }
547 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
548 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
549 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
550 ;
551
552 UnaryExpression
553 : PostfixExpression { $$ = $1; }
554 | UnaryExpression_ { $$ = $1; }
555 ;
556
557 UnaryExpressionNoBF
558 : PostfixExpressionNoBF { $$ = $1; }
559 | UnaryExpression_ { $$ = $1; }
560 ;
561
562 MultiplicativeExpression
563 : UnaryExpression { $$ = $1; }
564 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
565 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
566 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
567 ;
568
569 MultiplicativeExpressionNoBF
570 : UnaryExpressionNoBF { $$ = $1; }
571 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
572 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
573 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
574 ;
575
576 AdditiveExpression
577 : MultiplicativeExpression { $$ = $1; }
578 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
579 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
580 ;
581
582 AdditiveExpressionNoBF
583 : MultiplicativeExpressionNoBF { $$ = $1; }
584 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
585 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
586 ;
587
588 ShiftExpression
589 : AdditiveExpression { $$ = $1; }
590 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
591 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
592 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
593 ;
594
595 ShiftExpressionNoBF
596 : AdditiveExpressionNoBF { $$ = $1; }
597 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
598 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
599 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
600 ;
601
602 RelationalExpression
603 : ShiftExpression { $$ = $1; }
604 | RelationalExpression "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
605 | RelationalExpression ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
606 | RelationalExpression "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
607 | RelationalExpression ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
608 | RelationalExpression "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
609 | RelationalExpression "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
610 ;
611
612 RelationalExpressionNoIn
613 : ShiftExpression { $$ = $1; }
614 | RelationalExpressionNoIn "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
615 | RelationalExpressionNoIn ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
616 | RelationalExpressionNoIn "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
617 | RelationalExpressionNoIn ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
618 | RelationalExpressionNoIn "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
619 ;
620
621 RelationalExpressionNoBF
622 : ShiftExpressionNoBF { $$ = $1; }
623 | RelationalExpressionNoBF "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
624 | RelationalExpressionNoBF ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
625 | RelationalExpressionNoBF "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
626 | RelationalExpressionNoBF ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
627 | RelationalExpressionNoBF "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
628 | RelationalExpressionNoBF "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
629 ;
630
631 EqualityExpression
632 : RelationalExpression { $$ = $1; }
633 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
634 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
635 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
636 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
637 ;
638
639 EqualityExpressionNoIn
640 : RelationalExpressionNoIn { $$ = $1; }
641 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
642 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
643 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
644 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
645 ;
646
647 EqualityExpressionNoBF
648 : RelationalExpressionNoBF { $$ = $1; }
649 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
650 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
651 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
652 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
653 ;
654
655 BitwiseANDExpression
656 : EqualityExpression { $$ = $1; }
657 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
658 ;
659
660 BitwiseANDExpressionNoIn
661 : EqualityExpressionNoIn { $$ = $1; }
662 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
663 ;
664
665 BitwiseANDExpressionNoBF
666 : EqualityExpressionNoBF { $$ = $1; }
667 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
668 ;
669
670 BitwiseXORExpression
671 : BitwiseANDExpression { $$ = $1; }
672 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
673 ;
674
675 BitwiseXORExpressionNoIn
676 : BitwiseANDExpressionNoIn { $$ = $1; }
677 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
678 ;
679
680 BitwiseXORExpressionNoBF
681 : BitwiseANDExpressionNoBF { $$ = $1; }
682 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
683 ;
684
685 BitwiseORExpression
686 : BitwiseXORExpression { $$ = $1; }
687 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
688 ;
689
690 BitwiseORExpressionNoIn
691 : BitwiseXORExpressionNoIn { $$ = $1; }
692 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
693 ;
694
695 BitwiseORExpressionNoBF
696 : BitwiseXORExpressionNoBF { $$ = $1; }
697 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
698 ;
699
700 LogicalANDExpression
701 : BitwiseORExpression { $$ = $1; }
702 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
703 ;
704
705 LogicalANDExpressionNoIn
706 : BitwiseORExpressionNoIn { $$ = $1; }
707 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
708 ;
709
710 LogicalANDExpressionNoBF
711 : BitwiseORExpressionNoBF { $$ = $1; }
712 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
713 ;
714
715 LogicalORExpression
716 : LogicalANDExpression { $$ = $1; }
717 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
718 ;
719
720 LogicalORExpressionNoIn
721 : LogicalANDExpressionNoIn { $$ = $1; }
722 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
723 ;
724
725 LogicalORExpressionNoBF
726 : LogicalANDExpressionNoBF { $$ = $1; }
727 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
728 ;
729
730 ConditionalExpression
731 : LogicalORExpression { $$ = $1; }
732 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
733 ;
734
735 ConditionalExpressionNoIn
736 : LogicalORExpressionNoIn { $$ = $1; }
737 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
738 ;
739
740 ConditionalExpressionNoBF
741 : LogicalORExpressionNoBF { $$ = $1; }
742 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
743 ;
744
745 AssignmentExpression
746 : ConditionalExpression { $$ = $1; }
747 | LeftHandSideExpression "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
748 | LeftHandSideExpression "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
749 | LeftHandSideExpression "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
750 | LeftHandSideExpression "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
751 | LeftHandSideExpression "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
752 | LeftHandSideExpression "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
753 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
754 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
755 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
756 | LeftHandSideExpression "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
757 | LeftHandSideExpression "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
758 | LeftHandSideExpression "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
759 ;
760
761 AssignmentExpressionNoIn
762 : ConditionalExpressionNoIn { $$ = $1; }
763 | LeftHandSideExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
764 | LeftHandSideExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
765 | LeftHandSideExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
766 | LeftHandSideExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
767 | LeftHandSideExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
768 | LeftHandSideExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
769 | LeftHandSideExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
770 | LeftHandSideExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
771 | LeftHandSideExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
772 | LeftHandSideExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
773 | LeftHandSideExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
774 | LeftHandSideExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
775 ;
776
777 AssignmentExpressionNoBF
778 : ConditionalExpressionNoBF { $$ = $1; }
779 | LeftHandSideExpressionNoBF "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
780 | LeftHandSideExpressionNoBF "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
781 | LeftHandSideExpressionNoBF "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
782 | LeftHandSideExpressionNoBF "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
783 | LeftHandSideExpressionNoBF "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
784 | LeftHandSideExpressionNoBF "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
785 | LeftHandSideExpressionNoBF "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
786 | LeftHandSideExpressionNoBF ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
787 | LeftHandSideExpressionNoBF ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
788 | LeftHandSideExpressionNoBF "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
789 | LeftHandSideExpressionNoBF "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
790 | LeftHandSideExpressionNoBF "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
791 ;
792
793 Expression_
794 : "," Expression { $$ = $2; }
795 | { $$ = NULL; }
796 ;
797
798 ExpressionNoIn_
799 : "," ExpressionNoIn { $$ = $2; }
800 | { $$ = NULL; }
801 ;
802
803 ExpressionOpt
804 : Expression { $$ = $1; }
805 | { $$ = NULL; }
806 ;
807
808 ExpressionNoInOpt
809 : ExpressionNoIn { $$ = $1; }
810 | { $$ = NULL; }
811 ;
812
813 Expression
814 : AssignmentExpression Expression_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; }
815 ;
816
817 ExpressionNoIn
818 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; }
819 ;
820
821 ExpressionNoBF
822 : AssignmentExpressionNoBF Expression_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; }
823 ;
824
825 Statement
826 : Block { $$ = $1; }
827 | VariableStatement { $$ = $1; }
828 | EmptyStatement { $$ = $1; }
829 | ExpressionStatement { $$ = $1; }
830 | IfStatement { $$ = $1; }
831 | IterationStatement { $$ = $1; }
832 | ContinueStatement { $$ = $1; }
833 | BreakStatement { $$ = $1; }
834 | ReturnStatement { $$ = $1; }
835 | WithStatement { $$ = $1; }
836 | LabelledStatement { $$ = $1; }
837 | SwitchStatement { $$ = $1; }
838 | ThrowStatement { $$ = $1; }
839 | TryStatement { $$ = $1; }
840 ;
841
842 Block
843 : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); }
844 ;
845
846 StatementList
847 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
848 ;
849
850 StatementListOpt
851 : StatementList { $$ = $1; }
852 | { $$ = NULL; }
853 ;
854
855 VariableStatement
856 : "var" VariableDeclarationList Terminator { $$ = $2; }
857 ;
858
859 VariableDeclarationList_
860 : "," VariableDeclarationList { $$ = $2; }
861 | { $$ = NULL; }
862 ;
863
864 VariableDeclarationListNoIn_
865 : "," VariableDeclarationListNoIn { $$ = $2; }
866 | { $$ = NULL; }
867 ;
868
869 VariableDeclarationList
870 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
871 ;
872
873 VariableDeclarationListNoIn
874 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
875 ;
876
877 VariableDeclaration
878 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
879 ;
880
881 VariableDeclarationNoIn
882 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
883 ;
884
885 InitialiserOpt
886 : Initialiser { $$ = $1; }
887 | { $$ = NULL; }
888 ;
889
890 InitialiserNoInOpt
891 : InitialiserNoIn { $$ = $1; }
892 | { $$ = NULL; }
893 ;
894
895 Initialiser
896 : "=" AssignmentExpression { $$ = $2; }
897 ;
898
899 InitialiserNoIn
900 : "=" AssignmentExpressionNoIn { $$ = $2; }
901 ;
902
903 EmptyStatement
904 : ";" { $$ = new(driver.pool_) CYEmpty(); }
905 ;
906
907 ExpressionStatement
908 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
909 ;
910
911 ElseStatementOpt
912 : "else" Statement { $$ = $2; }
913 | %prec "if" { $$ = NULL; }
914 ;
915
916 IfStatement
917 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
918 ;
919
920 IterationStatement
921 : DoWhileStatement { $$ = $1; }
922 | WhileStatement { $$ = $1; }
923 | ForStatement { $$ = $1; }
924 | ForInStatement { $$ = $1; }
925 ;
926
927 DoWhileStatement
928 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
929 ;
930
931 WhileStatement
932 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
933 ;
934
935 ForStatement
936 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
937 ;
938
939 ForStatementInitialiser
940 : ExpressionNoInOpt { $$ = $1; }
941 | "var" VariableDeclarationListNoIn { $$ = $2; }
942 ;
943
944 ForInStatement
945 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
946 ;
947
948 ForInStatementInitialiser
949 : LeftHandSideExpression { $$ = $1; }
950 | "var" VariableDeclarationNoIn { $$ = $2; }
951 ;
952
953 ContinueStatement
954 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
955 ;
956
957 BreakStatement
958 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
959 ;
960
961 ReturnStatement
962 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
963 ;
964
965 WithStatement
966 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
967 ;
968
969 SwitchStatement
970 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
971 ;
972
973 CaseBlock
974 : "{" CaseClausesOpt "}" { $$ = $2; }
975 ;
976
977 CaseClausesOpt
978 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
979 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
980 | { $$ = NULL; }
981 ;
982
983 CaseClause
984 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
985 ;
986
987 DefaultClause
988 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
989 ;
990
991 LabelledStatement
992 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
993 ;
994
995 ThrowStatement
996 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
997 ;
998
999 TryStatement
1000 : "try" Block CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1001 ;
1002
1003 CatchOpt
1004 : "catch" "(" Identifier ")" Block { $$ = new(driver.pool_) CYCatch($3, $5); }
1005 | { $$ = NULL; }
1006 ;
1007
1008 FinallyOpt
1009 : "finally" Block { $$ = $2; }
1010 | { $$ = NULL; }
1011 ;
1012
1013 FunctionDeclaration
1014 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1015 ;
1016
1017 FunctionExpression
1018 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1019 ;
1020
1021 FormalParameterList_
1022 : "," FormalParameterList { $$ = $2; }
1023 | { $$ = NULL; }
1024 ;
1025
1026 FormalParameterList
1027 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); }
1028 | { $$ = NULL; }
1029 ;
1030
1031 FunctionBody
1032 : SourceElements { $$ = $1; }
1033 ;
1034
1035 Program
1036 : SourceElements { driver.source_ = $1; }
1037 ;
1038
1039 SourceElements
1040 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1041 | { $$ = NULL; }
1042 ;
1043
1044 SourceElement
1045 : Statement { $$ = $1; }
1046 | FunctionDeclaration { $$ = $1; }
1047 ;
1048
1049 /* Objective-C Extensions {{{ */
1050 VariadicCall
1051 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1052 | { $$ = NULL; }
1053 ;
1054
1055 SelectorCall_
1056 : SelectorCall { $$ = $1; }
1057 | VariadicCall { $$ = $1; }
1058 ;
1059
1060 SelectorCall
1061 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1062 ;
1063
1064 SelectorList
1065 : SelectorCall { $$ = $1; }
1066 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1067 ;
1068
1069 MessageExpression
1070 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); }
1071 ;
1072
1073 SelectorExpressionOpt
1074 : SelectorExpression_ { $$ = $1; }
1075 | { $$ = NULL; }
1076 ;
1077
1078 SelectorExpression_
1079 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1080 ;
1081
1082 SelectorExpression
1083 : SelectorExpression_ { $$ = $1; }
1084 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1085 ;
1086
1087 PrimaryExpression_
1088 : MessageExpression { $$ = $1; }
1089 | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); }
1090 ;
1091 /* }}} */
1092
1093 LeftHandSideExpression_
1094 : "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); }
1095 ;
1096
1097 UnaryExpression_
1098 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1099 ;
1100
1101 %%