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