]> git.saurik.com Git - cycript.git/blob - Cycript.y
0cfbe6e062f0922e0e083e2b59eddb7e71b1672f
[cycript.git] / Cycript.y
1 %code top {
2 #include "Cycript.tab.hh"
3 int cylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
4 #define scanner driver->scanner_
5 }
6
7 %code requires {
8 #include "Parser.hpp"
9 }
10
11 %union {
12 CYExpression *expression_;
13 CYTokenIdentifier *identifier_;
14 CYTokenNumber *number_;
15 CYTokenString *string_;
16 }
17
18 %name-prefix "cy"
19
20 %language "C++"
21 %locations
22 %glr-parser
23
24 %defines
25
26 %debug
27 %error-verbose
28
29 %parse-param { CYParser *driver }
30 %lex-param { void *scanner }
31
32 %token Ampersand "&"
33 %token AmpersandAmpersand "&&"
34 %token AmpersandEqual "&="
35 %token Carrot "^"
36 %token CarrotEqual "^="
37 %token Equal "="
38 %token EqualEqual "=="
39 %token EqualEqualEqual "==="
40 %token Exclamation "!"
41 %token ExclamationEqual "!="
42 %token ExclamationEqualEqual "!=="
43 %token Hyphen "-"
44 %token HyphenEqual "-="
45 %token HyphenHyphen "--"
46 %token HyphenRight "->"
47 %token Left "<"
48 %token LeftEqual "<="
49 %token LeftLeft "<<"
50 %token LeftLeftEqual "<<="
51 %token Percent "%"
52 %token PercentEqual "%="
53 %token Period "."
54 %token Pipe "|"
55 %token PipeEqual "|="
56 %token PipePipe "||"
57 %token Plus "+"
58 %token PlusEqual "+="
59 %token PlusPlus "++"
60 %token Right ">"
61 %token RightEqual ">="
62 %token RightRight ">>"
63 %token RightRightEqual ">>="
64 %token RightRightRight ">>>"
65 %token RightRightRightEqual ">>>="
66 %token Slash "/"
67 %token SlashEqual "/="
68 %token Star "*"
69 %token StarEqual "*="
70 %token Tilde "~"
71
72 %token Colon ":"
73 %token Comma ","
74 %token Question "?"
75 %token SemiColon ";"
76
77 %token OpenParen "("
78 %token CloseParen ")"
79
80 %token OpenBrace "{"
81 %token CloseBrace "}"
82
83 %token OpenBracket "["
84 %token CloseBracket "]"
85
86 %token Break "break"
87 %token Case "case"
88 %token Catch "catch"
89 %token Continue "continue"
90 %token Default "default"
91 %token Delete "delete"
92 %token Do "do"
93 %token Else "else"
94 %token False "false"
95 %token Finally "finally"
96 %token For "for"
97 %token Function "function"
98 %token If "if"
99 %token In "in"
100 %token InstanceOf "instanceof"
101 %token New "new"
102 %token Null "null"
103 %token Return "return"
104 %token Switch "switch"
105 %token This "this"
106 %token Throw "throw"
107 %token True "true"
108 %token Try "try"
109 %token TypeOf "typeof"
110 %token Var "var"
111 %token Void "void"
112 %token While "while"
113 %token With "with"
114
115 %token <identifier_> Identifier
116 %token <number_> NumericLiteral
117 %token <string_> StringLiteral
118
119 %%
120
121 %start Program;
122
123 WordOpt
124 : Word
125 |
126 ;
127
128 Word
129 : Identifier
130 | "break"
131 | "case"
132 | "catch"
133 | "continue"
134 | "default"
135 | "delete"
136 | "do"
137 | "else"
138 | "false"
139 | "finally"
140 | "for"
141 | "function"
142 | "if"
143 | "in"
144 | "instanceof"
145 | "new"
146 | "null"
147 | "return"
148 | "switch"
149 | "this"
150 | "throw"
151 | "true"
152 | "try"
153 | "typeof"
154 | "var"
155 | "void"
156 | "while"
157 | "with"
158 ;
159
160 IdentifierOpt
161 : Identifier
162 |
163 ;
164
165 Literal
166 : NullLiteral
167 | BooleanLiteral
168 | NumericLiteral
169 | StringLiteral
170 ;
171
172 NullLiteral
173 : "null"
174 ;
175
176 BooleanLiteral
177 : "true"
178 | "false"
179 ;
180
181 /* Objective-C Extensions {{{ */
182 VariadicCall
183 : "," AssignmentExpression VariadicCall
184 |
185 ;
186
187 SelectorCall_
188 : SelectorCall
189 | VariadicCall
190 ;
191
192 SelectorCall
193 : WordOpt ":" AssignmentExpression SelectorCall_
194 ;
195
196 SelectorList
197 : SelectorCall
198 | Word
199 ;
200
201 ObjectiveCall
202 : "[" AssignmentExpression SelectorList "]"
203 ;
204 /* }}} */
205
206 /* 11.1 Primary Expressions {{{ */
207 PrimaryExpression
208 : "this"
209 | Identifier
210 | Literal
211 | ArrayLiteral
212 | ObjectLiteral
213 | "(" Expression ")"
214 | ObjectiveCall
215 ;
216 /* }}} */
217 /* 11.1.4 Array Initialiser {{{ */
218 ArrayLiteral
219 : "[" ElementList "]"
220 ;
221
222 Element
223 : AssignmentExpression
224 |
225 ;
226
227 ElementList_
228 : "," ElementList
229 |
230 ;
231
232 ElementList
233 : Element ElementList_
234 ;
235 /* }}} */
236 /* 11.1.5 Object Initialiser {{{ */
237 ObjectLiteral
238 : "{" PropertyNameAndValueListOpt "}"
239 ;
240
241 PropertyNameAndValueList_
242 : "," PropertyNameAndValueList
243 |
244 ;
245
246 PropertyNameAndValueListOpt
247 : PropertyNameAndValueList
248 |
249 ;
250
251 PropertyNameAndValueList
252 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_
253 ;
254
255 PropertyName
256 : Identifier
257 | StringLiteral
258 | NumericLiteral
259 ;
260 /* }}} */
261
262 MemberExpression
263 : PrimaryExpression
264 | FunctionExpression
265 | MemberExpression "[" Expression "]"
266 | MemberExpression "." Identifier
267 | "new" MemberExpression Arguments
268 ;
269
270 NewExpression
271 : MemberExpression
272 | "new" NewExpression
273 ;
274
275 CallExpression
276 : MemberExpression Arguments
277 | CallExpression Arguments
278 | CallExpression "[" Expression "]"
279 | CallExpression "." Identifier
280 ;
281
282 ArgumentList_
283 : "," ArgumentList
284 |
285 ;
286
287 ArgumentListOpt
288 : ArgumentList
289 |
290 ;
291
292 ArgumentList
293 : AssignmentExpression ArgumentList_
294 ;
295
296 Arguments
297 : "(" ArgumentListOpt ")"
298 ;
299
300 LeftHandSideExpression
301 : NewExpression
302 | CallExpression
303 ;
304
305 PostfixExpression
306 : LeftHandSideExpression
307 | LeftHandSideExpression "++"
308 | LeftHandSideExpression "--"
309 ;
310
311 UnaryExpression
312 : PostfixExpression
313 | "delete" UnaryExpression
314 | "void" UnaryExpression
315 | "typeof" UnaryExpression
316 | "++" UnaryExpression
317 | "--" UnaryExpression
318 | "+" UnaryExpression
319 | "-" UnaryExpression
320 | "~" UnaryExpression
321 | "!" UnaryExpression
322 | "*" UnaryExpression
323 | "&" UnaryExpression
324 ;
325
326 MultiplicativeExpression
327 : UnaryExpression
328 | MultiplicativeExpression "*" UnaryExpression
329 | MultiplicativeExpression "/" UnaryExpression
330 | MultiplicativeExpression "%" UnaryExpression
331 ;
332
333 AdditiveExpression
334 : MultiplicativeExpression
335 | AdditiveExpression "+" MultiplicativeExpression
336 | AdditiveExpression "-" MultiplicativeExpression
337 ;
338
339 ShiftExpression
340 : AdditiveExpression
341 | ShiftExpression "<<" AdditiveExpression
342 | ShiftExpression ">>" AdditiveExpression
343 | ShiftExpression ">>>" AdditiveExpression
344 ;
345
346 RelationalExpression
347 : ShiftExpression
348 | RelationalExpression "<" ShiftExpression
349 | RelationalExpression ">" ShiftExpression
350 | RelationalExpression "<=" ShiftExpression
351 | RelationalExpression ">=" ShiftExpression
352 | RelationalExpression "instanceof" ShiftExpression
353 | RelationalExpression "in" ShiftExpression
354 ;
355
356 EqualityExpression
357 : RelationalExpression
358 | EqualityExpression "==" RelationalExpression
359 | EqualityExpression "!=" RelationalExpression
360 | EqualityExpression "===" RelationalExpression
361 | EqualityExpression "!==" RelationalExpression
362 ;
363
364 BitwiseANDExpression
365 : EqualityExpression
366 | BitwiseANDExpression "&" EqualityExpression
367 ;
368
369 BitwiseXORExpression
370 : BitwiseANDExpression
371 | BitwiseXORExpression "^" BitwiseANDExpression
372 ;
373
374 BitwiseORExpression
375 : BitwiseXORExpression
376 | BitwiseORExpression "|" BitwiseXORExpression
377 ;
378
379 LogicalANDExpression
380 : BitwiseORExpression
381 | LogicalANDExpression "&&" BitwiseORExpression
382 ;
383
384 LogicalORExpression
385 : LogicalANDExpression
386 | LogicalORExpression "||" LogicalANDExpression
387 ;
388
389 ConditionalExpression
390 : LogicalORExpression
391 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression
392 ;
393
394 AssignmentExpression
395 : ConditionalExpression
396 | LeftHandSideExpression AssignmentOperator AssignmentExpression
397 ;
398
399 AssignmentOperator
400 : "="
401 | "*="
402 | "/="
403 | "%="
404 | "+="
405 | "-="
406 | "<<="
407 | ">>="
408 | ">>>="
409 | "&="
410 | "^="
411 | "|="
412 ;
413
414 Expression_
415 : "," Expression
416 |
417 ;
418
419 ExpressionOpt
420 : Expression
421 |
422 ;
423
424 Expression
425 : AssignmentExpression Expression_
426 ;
427
428 Statement
429 : Block
430 | VariableStatement
431 | EmptyStatement
432 | ExpressionStatement
433 | IfStatement
434 | IterationStatement
435 | ContinueStatement
436 | BreakStatement
437 | ReturnStatement
438 | WithStatement
439 | LabelledStatement
440 | SwitchStatement
441 | ThrowStatement
442 | TryStatement
443 ;
444
445 Block
446 : "{" StatementListOpt "}"
447 ;
448
449 StatementListOpt
450 : Statement StatementListOpt
451 |
452 ;
453
454 VariableStatement
455 : "var" VariableDeclarationList ";"
456 ;
457
458 VariableDeclarationList_
459 : "," VariableDeclarationList
460 |
461 ;
462
463 VariableDeclarationList
464 : VariableDeclaration VariableDeclarationList_
465 ;
466
467 VariableDeclaration
468 : Identifier InitialiserOpt
469 ;
470
471 InitialiserOpt
472 : Initialiser
473 |
474 ;
475
476 Initialiser
477 : "=" AssignmentExpression
478 ;
479
480 EmptyStatement
481 : ";"
482 ;
483
484 ExpressionStatement
485 : Expression ";"
486 ;
487
488 ElseStatementOpt
489 : "else" Statement
490 |
491 ;
492
493 IfStatement
494 : "if" "(" Expression ")" Statement ElseStatementOpt
495 ;
496
497 IterationStatement
498 : DoWhileStatement
499 | WhileStatement
500 | ForStatement
501 | ForInStatement
502 ;
503
504 DoWhileStatement
505 : "do" Statement "while" "(" Expression ")" ";"
506 ;
507
508 WhileStatement
509 : "while" "(" Expression ")" Statement
510 ;
511
512 ForStatement
513 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement
514 ;
515
516 ForStatementInitialiser
517 : ExpressionOpt
518 | "var" VariableDeclarationList
519 ;
520
521 ForInStatement
522 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement
523 ;
524
525 ForInStatementInitialiser
526 : LeftHandSideExpression
527 | "var" VariableDeclaration
528 ;
529
530 ContinueStatement
531 : "continue" IdentifierOpt ";"
532 ;
533
534 BreakStatement
535 : "break" IdentifierOpt ";"
536 ;
537
538 ReturnStatement
539 : "return" ExpressionOpt ";"
540 ;
541
542 WithStatement
543 : "with" "(" Expression ")" Statement
544 ;
545
546 SwitchStatement
547 : "switch" "(" Expression ")" CaseBlock
548 ;
549
550 CaseBlock
551 : "{" CaseClausesOpt "}"
552 ;
553
554 CaseClausesOpt
555 : CaseClause CaseClausesOpt
556 | DefaultClause CaseClausesOpt
557 |
558 ;
559
560 CaseClause
561 : "case" Expression ":" StatementListOpt
562 ;
563
564 DefaultClause
565 : "default" ":" StatementListOpt
566 ;
567
568 LabelledStatement
569 : Identifier ":" Statement
570 ;
571
572 ThrowStatement
573 : "throw" Expression ";"
574 ;
575
576 TryStatement
577 : "try" Block CatchOpt FinallyOpt
578 ;
579
580 CatchOpt
581 : "catch" "(" Identifier ")" Block
582 |
583 ;
584
585 FinallyOpt
586 : "finally" Block
587 |
588 ;
589
590 FunctionDeclaration
591 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}"
592 ;
593
594 FunctionExpression
595 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}"
596 ;
597
598 FormalParameterList_
599 : "," FormalParameterList
600 |
601 ;
602
603 FormalParameterList
604 : Identifier FormalParameterList_
605 |
606 ;
607
608 FunctionBody
609 : SourceElements
610 ;
611
612 Program
613 : SourceElements
614 ;
615
616 SourceElements
617 : SourceElement SourceElements
618 |
619 ;
620
621 SourceElement
622 : Statement
623 | FunctionDeclaration
624 ;
625
626 %%