]>
Commit | Line | Data |
---|---|---|
1dbba6cc | 1 | %code top { |
63b4c5a8 | 2 | #include "Cycript.tab.hh" |
e5332278 | 3 | int 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 | |
119 | IdentifierOpt | |
120 | : Identifier | |
121 | | | |
122 | ; | |
123 | ||
1dbba6cc JF |
124 | Literal |
125 | : NullLiteral | |
126 | | BooleanLiteral | |
127 | | NumericLiteral | |
128 | | StringLiteral | |
129 | ; | |
130 | ||
131 | NullLiteral | |
132 | : "null" | |
133 | ; | |
134 | ||
135 | BooleanLiteral | |
136 | : "true" | |
137 | | "false" | |
138 | ; | |
139 | ||
1dbba6cc JF |
140 | /* Objective-C Extensions {{{ */ |
141 | VariadicCall | |
142 | : "," AssignmentExpression VariadicCall | |
143 | | | |
144 | ; | |
145 | ||
146 | SelectorCall_ | |
147 | : SelectorCall | |
148 | | VariadicCall | |
149 | ; | |
150 | ||
151 | SelectorCall | |
152 | : IdentifierOpt ":" AssignmentExpression SelectorCall_ | |
153 | ; | |
154 | ||
155 | SelectorList | |
156 | : SelectorCall | |
157 | | Identifier | |
158 | ; | |
159 | ||
160 | ObjectiveCall | |
161 | : "[" AssignmentExpression SelectorList "]" | |
162 | ; | |
163 | /* }}} */ | |
164 | ||
165 | /* 11.1 Primary Expressions {{{ */ | |
166 | PrimaryExpression | |
167 | : "this" | |
168 | | Identifier | |
169 | | Literal | |
170 | | ArrayLiteral | |
171 | | ObjectLiteral | |
172 | | "(" Expression ")" | |
173 | | ObjectiveCall | |
174 | ; | |
175 | /* }}} */ | |
176 | /* 11.1.4 Array Initialiser {{{ */ | |
177 | ArrayLiteral | |
178 | : "[" ElementList "]" | |
179 | ; | |
180 | ||
181 | Element | |
182 | : AssignmentExpression | |
183 | | | |
184 | ; | |
185 | ||
186 | ElementList_ | |
187 | : "," ElementList | |
188 | | | |
189 | ; | |
190 | ||
191 | ElementList | |
192 | : Element ElementList_ | |
193 | ; | |
194 | /* }}} */ | |
195 | /* 11.1.5 Object Initialiser {{{ */ | |
196 | ObjectLiteral | |
197 | : "{" PropertyNameAndValueListOpt "}" | |
198 | ; | |
199 | ||
200 | PropertyNameAndValueList_ | |
201 | : "," PropertyNameAndValueList | |
202 | | | |
203 | ; | |
204 | ||
205 | PropertyNameAndValueListOpt | |
206 | : PropertyNameAndValueList | |
207 | | | |
208 | ; | |
209 | ||
210 | PropertyNameAndValueList | |
211 | : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ | |
212 | ; | |
213 | ||
214 | PropertyName | |
215 | : Identifier | |
216 | | StringLiteral | |
217 | | NumericLiteral | |
218 | ; | |
219 | /* }}} */ | |
220 | ||
221 | MemberExpression | |
222 | : PrimaryExpression | |
223 | | FunctionExpression | |
224 | | MemberExpression "[" Expression "]" | |
225 | | MemberExpression "." Identifier | |
226 | | "new" MemberExpression Arguments | |
227 | ; | |
228 | ||
229 | NewExpression | |
230 | : MemberExpression | |
231 | | "new" NewExpression | |
232 | ; | |
233 | ||
234 | CallExpression | |
235 | : MemberExpression Arguments | |
236 | | CallExpression Arguments | |
237 | | CallExpression "[" Expression "]" | |
238 | | CallExpression "." Identifier | |
239 | ; | |
240 | ||
241 | ArgumentList_ | |
242 | : "," ArgumentList | |
243 | | | |
244 | ; | |
245 | ||
246 | ArgumentListOpt | |
247 | : ArgumentList | |
248 | | | |
249 | ; | |
250 | ||
251 | ArgumentList | |
252 | : AssignmentExpression ArgumentList_ | |
253 | ; | |
254 | ||
255 | Arguments | |
256 | : "(" ArgumentListOpt ")" | |
257 | ; | |
258 | ||
259 | LeftHandSideExpression | |
260 | : NewExpression | |
261 | | CallExpression | |
262 | ; | |
263 | ||
264 | PostfixExpression | |
265 | : LeftHandSideExpression | |
266 | | LeftHandSideExpression "++" | |
267 | | LeftHandSideExpression "--" | |
268 | ; | |
269 | ||
270 | UnaryExpression | |
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 | ||
285 | MultiplicativeExpression | |
286 | : UnaryExpression | |
287 | | MultiplicativeExpression "*" UnaryExpression | |
288 | | MultiplicativeExpression "/" UnaryExpression | |
289 | | MultiplicativeExpression "%" UnaryExpression | |
290 | ; | |
291 | ||
292 | AdditiveExpression | |
293 | : MultiplicativeExpression | |
294 | | AdditiveExpression "+" MultiplicativeExpression | |
295 | | AdditiveExpression "-" MultiplicativeExpression | |
296 | ; | |
297 | ||
298 | ShiftExpression | |
299 | : AdditiveExpression | |
300 | | ShiftExpression "<<" AdditiveExpression | |
301 | | ShiftExpression ">>" AdditiveExpression | |
302 | | ShiftExpression ">>>" AdditiveExpression | |
303 | ; | |
304 | ||
305 | RelationalExpression | |
306 | : ShiftExpression | |
307 | | RelationalExpression "<" ShiftExpression | |
308 | | RelationalExpression ">" ShiftExpression | |
309 | | RelationalExpression "<=" ShiftExpression | |
310 | | RelationalExpression ">=" ShiftExpression | |
311 | | RelationalExpression "instanceof" ShiftExpression | |
312 | | RelationalExpression "in" ShiftExpression | |
313 | ; | |
314 | ||
315 | EqualityExpression | |
316 | : RelationalExpression | |
317 | | EqualityExpression "==" RelationalExpression | |
318 | | EqualityExpression "!=" RelationalExpression | |
319 | | EqualityExpression "===" RelationalExpression | |
320 | | EqualityExpression "!==" RelationalExpression | |
321 | ; | |
322 | ||
323 | BitwiseANDExpression | |
324 | : EqualityExpression | |
325 | | BitwiseANDExpression "&" EqualityExpression | |
326 | ; | |
327 | ||
328 | BitwiseXORExpression | |
329 | : BitwiseANDExpression | |
330 | | BitwiseXORExpression "^" BitwiseANDExpression | |
331 | ; | |
332 | ||
333 | BitwiseORExpression | |
334 | : BitwiseXORExpression | |
335 | | BitwiseORExpression "|" BitwiseXORExpression | |
336 | ; | |
337 | ||
338 | LogicalANDExpression | |
339 | : BitwiseORExpression | |
340 | | LogicalANDExpression "&&" BitwiseORExpression | |
341 | ; | |
342 | ||
343 | LogicalORExpression | |
344 | : LogicalANDExpression | |
345 | | LogicalORExpression "||" LogicalANDExpression | |
346 | ; | |
347 | ||
348 | ConditionalExpression | |
349 | : LogicalORExpression | |
350 | | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression | |
351 | ; | |
352 | ||
353 | AssignmentExpression | |
354 | : ConditionalExpression | |
355 | | LeftHandSideExpression AssignmentOperator AssignmentExpression | |
356 | ; | |
357 | ||
358 | AssignmentOperator | |
359 | : "=" | |
360 | | "*=" | |
361 | | "/=" | |
362 | | "%=" | |
363 | | "+=" | |
364 | | "-=" | |
365 | | "<<=" | |
366 | | ">>=" | |
367 | | ">>>=" | |
368 | | "&=" | |
369 | | "^=" | |
370 | | "|=" | |
371 | ; | |
372 | ||
373 | Expression_ | |
374 | : "," Expression | |
375 | | | |
376 | ; | |
377 | ||
378 | ExpressionOpt | |
379 | : Expression | |
380 | | | |
381 | ; | |
382 | ||
383 | Expression | |
384 | : AssignmentExpression Expression_ | |
385 | ; | |
386 | ||
387 | Statement | |
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 | ||
404 | Block | |
405 | : "{" StatementListOpt "}" | |
406 | ; | |
407 | ||
408 | StatementListOpt | |
409 | : Statement StatementListOpt | |
410 | | | |
411 | ; | |
412 | ||
413 | VariableStatement | |
414 | : "var" VariableDeclarationList ";" | |
415 | ; | |
416 | ||
417 | VariableDeclarationList_ | |
418 | : "," VariableDeclarationList | |
419 | | | |
420 | ; | |
421 | ||
422 | VariableDeclarationList | |
423 | : VariableDeclaration VariableDeclarationList_ | |
424 | ; | |
425 | ||
426 | VariableDeclaration | |
427 | : Identifier InitialiserOpt | |
428 | ; | |
429 | ||
430 | InitialiserOpt | |
431 | : Initialiser | |
432 | | | |
433 | ; | |
434 | ||
435 | Initialiser | |
436 | : "=" AssignmentExpression | |
437 | ; | |
438 | ||
439 | EmptyStatement | |
440 | : ";" | |
441 | ; | |
442 | ||
443 | ExpressionStatement | |
444 | : Expression ";" | |
445 | ; | |
446 | ||
447 | ElseStatementOpt | |
448 | : "else" Statement | |
449 | | | |
450 | ; | |
451 | ||
452 | IfStatement | |
453 | : "if" "(" Expression ")" Statement ElseStatementOpt | |
454 | ; | |
455 | ||
456 | IterationStatement | |
457 | : DoWhileStatement | |
458 | | WhileStatement | |
459 | | ForStatement | |
460 | | ForInStatement | |
461 | ; | |
462 | ||
463 | DoWhileStatement | |
464 | : "do" Statement "while" "(" Expression ")" ";" | |
465 | ; | |
466 | ||
467 | WhileStatement | |
468 | : "while" "(" Expression ")" Statement | |
469 | ; | |
470 | ||
471 | ForStatement | |
472 | : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement | |
473 | ; | |
474 | ||
475 | ForStatementInitialiser | |
476 | : ExpressionOpt | |
477 | | "var" VariableDeclarationList | |
478 | ; | |
479 | ||
480 | ForInStatement | |
481 | : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement | |
482 | ; | |
483 | ||
484 | ForInStatementInitialiser | |
485 | : LeftHandSideExpression | |
486 | | "var" VariableDeclaration | |
487 | ; | |
488 | ||
489 | ContinueStatement | |
490 | : "continue" IdentifierOpt ";" | |
491 | ; | |
492 | ||
493 | BreakStatement | |
494 | : "break" IdentifierOpt ";" | |
495 | ; | |
496 | ||
497 | ReturnStatement | |
498 | : "return" ExpressionOpt ";" | |
499 | ; | |
500 | ||
501 | WithStatement | |
502 | : "with" "(" Expression ")" Statement | |
503 | ; | |
504 | ||
505 | SwitchStatement | |
506 | : "switch" "(" Expression ")" CaseBlock | |
507 | ; | |
508 | ||
509 | CaseBlock | |
510 | : "{" CaseClausesOpt "}" | |
511 | ; | |
512 | ||
513 | CaseClausesOpt | |
514 | : CaseClause CaseClausesOpt | |
515 | | DefaultClause CaseClausesOpt | |
516 | | | |
517 | ; | |
518 | ||
519 | CaseClause | |
520 | : "case" Expression ":" StatementListOpt | |
521 | ; | |
522 | ||
523 | DefaultClause | |
524 | : "default" ":" StatementListOpt | |
525 | ; | |
526 | ||
527 | LabelledStatement | |
528 | : Identifier ":" Statement | |
529 | ; | |
530 | ||
531 | ThrowStatement | |
532 | : "throw" Expression ";" | |
533 | ; | |
534 | ||
535 | TryStatement | |
536 | : "try" Block CatchOpt FinallyOpt | |
537 | ; | |
538 | ||
539 | CatchOpt | |
540 | : "catch" "(" Identifier ")" Block | |
541 | | | |
542 | ; | |
543 | ||
544 | FinallyOpt | |
545 | : "finally" Block | |
546 | | | |
547 | ; | |
548 | ||
549 | FunctionDeclaration | |
550 | : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" | |
551 | ; | |
552 | ||
553 | FunctionExpression | |
554 | : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" | |
555 | ; | |
556 | ||
557 | FormalParameterList_ | |
558 | : "," FormalParameterList | |
559 | | | |
560 | ; | |
561 | ||
562 | FormalParameterList | |
563 | : Identifier FormalParameterList_ | |
564 | | | |
565 | ; | |
566 | ||
567 | FunctionBody | |
568 | : SourceElements | |
569 | ; | |
570 | ||
571 | Program | |
572 | : SourceElements | |
573 | ; | |
574 | ||
575 | SourceElements | |
576 | : SourceElement SourceElements | |
577 | | | |
578 | ; | |
579 | ||
580 | SourceElement | |
581 | : Statement | |
582 | | FunctionDeclaration | |
583 | ; | |
e5332278 JF |
584 | |
585 | %% |