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