]>
Commit | Line | Data |
---|---|---|
1dbba6cc | 1 | %code top { |
63b4c5a8 | 2 | #include "Cycript.tab.hh" |
924f67b2 | 3 | int cylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); |
5999c315 | 4 | #define scanner driver.scanner_ |
1dbba6cc JF |
5 | } |
6 | ||
63b4c5a8 JF |
7 | %code requires { |
8 | #include "Parser.hpp" | |
63b4c5a8 | 9 | |
c3c20102 JF |
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 | ||
63b4c5a8 JF |
41 | } |
42 | ||
1dbba6cc | 43 | %name-prefix "cy" |
e5332278 | 44 | |
63b4c5a8 | 45 | %language "C++" |
e5332278 | 46 | %locations |
1dbba6cc JF |
47 | %glr-parser |
48 | ||
5999c315 JF |
49 | %initial-action { |
50 | @$.begin.filename = @$.end.filename = &driver.filename_; | |
51 | }; | |
52 | ||
e5332278 | 53 | %defines |
1dbba6cc JF |
54 | |
55 | %debug | |
e5332278 JF |
56 | %error-verbose |
57 | ||
5999c315 | 58 | %parse-param { CYDriver &driver } |
924f67b2 | 59 | %lex-param { void *scanner } |
e5332278 | 60 | |
63b4c5a8 JF |
61 | %token Ampersand "&" |
62 | %token AmpersandAmpersand "&&" | |
63 | %token AmpersandEqual "&=" | |
64 | %token Carrot "^" | |
65 | %token CarrotEqual "^=" | |
66 | %token Equal "=" | |
67 | %token EqualEqual "==" | |
68 | %token EqualEqualEqual "===" | |
69 | %token Exclamation "!" | |
70 | %token ExclamationEqual "!=" | |
71 | %token ExclamationEqualEqual "!==" | |
72 | %token Hyphen "-" | |
73 | %token HyphenEqual "-=" | |
74 | %token HyphenHyphen "--" | |
c3c20102 | 75 | %token HyphenHyphen_ "\n--" |
63b4c5a8 JF |
76 | %token HyphenRight "->" |
77 | %token Left "<" | |
78 | %token LeftEqual "<=" | |
79 | %token LeftLeft "<<" | |
80 | %token LeftLeftEqual "<<=" | |
81 | %token Percent "%" | |
82 | %token PercentEqual "%=" | |
83 | %token Period "." | |
84 | %token Pipe "|" | |
85 | %token PipeEqual "|=" | |
86 | %token PipePipe "||" | |
87 | %token Plus "+" | |
88 | %token PlusEqual "+=" | |
89 | %token PlusPlus "++" | |
c3c20102 | 90 | %token PlusPlus_ "\n++" |
63b4c5a8 JF |
91 | %token Right ">" |
92 | %token RightEqual ">=" | |
93 | %token RightRight ">>" | |
94 | %token RightRightEqual ">>=" | |
95 | %token RightRightRight ">>>" | |
96 | %token RightRightRightEqual ">>>=" | |
97 | %token Slash "/" | |
98 | %token SlashEqual "/=" | |
99 | %token Star "*" | |
100 | %token StarEqual "*=" | |
101 | %token Tilde "~" | |
102 | ||
103 | %token Colon ":" | |
104 | %token Comma "," | |
105 | %token Question "?" | |
106 | %token SemiColon ";" | |
c3c20102 | 107 | %token NewLine "\n" |
63b4c5a8 JF |
108 | |
109 | %token OpenParen "(" | |
110 | %token CloseParen ")" | |
924f67b2 | 111 | |
63b4c5a8 JF |
112 | %token OpenBrace "{" |
113 | %token CloseBrace "}" | |
924f67b2 | 114 | |
63b4c5a8 JF |
115 | %token OpenBracket "[" |
116 | %token CloseBracket "]" | |
117 | ||
cf7d4c69 JF |
118 | %token <word_> Break "break" |
119 | %token <word_> Case "case" | |
120 | %token <word_> Catch "catch" | |
121 | %token <word_> Continue "continue" | |
122 | %token <word_> Default "default" | |
123 | %token <word_> Delete "delete" | |
124 | %token <word_> Do "do" | |
125 | %token <word_> Else "else" | |
126 | %token <false_> False "false" | |
127 | %token <word_> Finally "finally" | |
128 | %token <word_> For "for" | |
129 | %token <word_> Function "function" | |
130 | %token <word_> If "if" | |
131 | %token <word_> In "in" | |
132 | %token <word_> InstanceOf "instanceof" | |
133 | %token <word_> New "new" | |
134 | %token <null_> Null "null" | |
135 | %token <word_> Return "return" | |
136 | %token <word_> Switch "switch" | |
137 | %token <this_> This "this" | |
138 | %token <word_> Throw "throw" | |
139 | %token <true_> True "true" | |
140 | %token <word_> Try "try" | |
141 | %token <word_> TypeOf "typeof" | |
142 | %token <word_> Var "var" | |
143 | %token <word_> Void "void" | |
144 | %token <word_> While "while" | |
145 | %token <word_> With "with" | |
63b4c5a8 JF |
146 | |
147 | %token <identifier_> Identifier | |
148 | %token <number_> NumericLiteral | |
149 | %token <string_> StringLiteral | |
1dbba6cc | 150 | |
cf7d4c69 JF |
151 | %type <expression_> AdditiveExpression |
152 | %type <argument_> ArgumentList | |
153 | %type <argument_> ArgumentList_ | |
154 | %type <argument_> ArgumentListOpt | |
155 | %type <argument_> Arguments | |
156 | %type <literal_> ArrayLiteral | |
157 | %type <expression_> AssignmentExpression | |
158 | %type <expression_> BitwiseANDExpression | |
159 | %type <statement_> Block | |
160 | %type <boolean_> BooleanLiteral | |
161 | %type <expression_> BitwiseORExpression | |
162 | %type <expression_> BitwiseXORExpression | |
163 | %type <statement_> BreakStatement | |
164 | %type <expression_> CallExpression | |
165 | %type <clause_> CaseBlock | |
166 | %type <clause_> CaseClause | |
167 | %type <clause_> CaseClausesOpt | |
168 | %type <catch_> CatchOpt | |
169 | %type <expression_> ConditionalExpression | |
170 | %type <statement_> ContinueStatement | |
171 | %type <clause_> DefaultClause | |
172 | %type <statement_> DoWhileStatement | |
173 | %type <expression_> Element | |
174 | %type <element_> ElementList | |
175 | %type <element_> ElementList_ | |
176 | %type <statement_> ElseStatementOpt | |
177 | %type <statement_> EmptyStatement | |
178 | %type <expression_> EqualityExpression | |
179 | %type <expression_> Expression | |
180 | %type <expression_> Expression_ | |
181 | %type <expression_> ExpressionOpt | |
182 | %type <statement_> ExpressionStatement | |
183 | %type <statement_> FinallyOpt | |
184 | %type <statement_> ForStatement | |
185 | %type <for_> ForStatementInitialiser | |
186 | %type <statement_> ForInStatement | |
187 | %type <forin_> ForInStatementInitialiser | |
188 | %type <parameter_> FormalParameterList | |
189 | %type <parameter_> FormalParameterList_ | |
190 | %type <source_> FunctionBody | |
191 | %type <source_> FunctionDeclaration | |
192 | %type <expression_> FunctionExpression | |
193 | %type <identifier_> IdentifierOpt | |
194 | %type <statement_> IfStatement | |
195 | %type <expression_> Initialiser | |
196 | %type <expression_> InitialiserOpt | |
197 | %type <statement_> IterationStatement | |
198 | %type <statement_> LabelledStatement | |
199 | %type <expression_> LeftHandSideExpression | |
200 | %type <literal_> Literal | |
201 | %type <expression_> LogicalANDExpression | |
202 | %type <expression_> LogicalORExpression | |
203 | %type <expression_> MemberExpression | |
204 | %type <expression_> MultiplicativeExpression | |
205 | %type <expression_> NewExpression | |
206 | %type <null_> NullLiteral | |
207 | %type <literal_> ObjectLiteral | |
208 | %type <expression_> MessageExpression | |
209 | %type <expression_> PostfixExpression | |
210 | %type <expression_> PrimaryExpression | |
211 | %type <source_> Program | |
212 | %type <name_> PropertyName | |
213 | %type <property_> PropertyNameAndValueList | |
214 | %type <property_> PropertyNameAndValueList_ | |
215 | %type <property_> PropertyNameAndValueListOpt | |
216 | %type <expression_> RelationalExpression | |
217 | %type <statement_> ReturnStatement | |
218 | %type <argument_> SelectorCall | |
219 | %type <argument_> SelectorCall_ | |
220 | %type <argument_> SelectorList | |
221 | %type <expression_> ShiftExpression | |
222 | %type <source_> SourceElement | |
223 | %type <source_> SourceElements | |
224 | %type <statement_> Statement | |
225 | %type <statement_> StatementListOpt | |
226 | %type <statement_> SwitchStatement | |
227 | %type <statement_> ThrowStatement | |
228 | %type <statement_> TryStatement | |
229 | %type <expression_> UnaryExpression | |
230 | %type <declaration_> VariableDeclaration | |
231 | %type <declarations_> VariableDeclarationList | |
232 | %type <declarations_> VariableDeclarationList_ | |
233 | %type <statement_> VariableStatement | |
234 | %type <argument_> VariadicCall | |
235 | %type <statement_> WhileStatement | |
236 | %type <statement_> WithStatement | |
237 | %type <word_> Word | |
238 | %type <word_> WordOpt | |
239 | ||
c3c20102 JF |
240 | %nonassoc "if" |
241 | %nonassoc "else" | |
242 | ||
e5332278 JF |
243 | %% |
244 | ||
c3c20102 JF |
245 | %start Program; |
246 | ||
c3c20102 JF |
247 | TerminatorOpt |
248 | : ";" | |
249 | | NewLine | |
250 | | | |
251 | ; | |
252 | ||
253 | Terminator | |
254 | : ";" | |
255 | | NewLine | |
55c229fd | 256 | | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else yyerrok; } |
c3c20102 JF |
257 | ; |
258 | ||
259 | NewLineOpt | |
260 | : NewLine | |
261 | | | |
262 | ; | |
1dbba6cc | 263 | |
36cd3cb9 | 264 | WordOpt |
cf7d4c69 JF |
265 | : Word { $$ = $1; } |
266 | | { $$ = NULL; } | |
2bf24581 JF |
267 | ; |
268 | ||
36cd3cb9 | 269 | Word |
cf7d4c69 | 270 | : Identifier { $$ = $1; } |
c3c20102 | 271 | | "break" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
272 | | "case" { $$ = $1; } |
273 | | "catch" { $$ = $1; } | |
c3c20102 | 274 | | "continue" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
275 | | "default" { $$ = $1; } |
276 | | "delete" { $$ = $1; } | |
277 | | "do" { $$ = $1; } | |
278 | | "else" { $$ = $1; } | |
279 | | "false" { $$ = $1; } | |
280 | | "finally" { $$ = $1; } | |
281 | | "for" { $$ = $1; } | |
282 | | "function" { $$ = $1; } | |
283 | | "if" { $$ = $1; } | |
284 | | "in" { $$ = $1; } | |
285 | | "instanceof" { $$ = $1; } | |
286 | | "new" { $$ = $1; } | |
287 | | "null" { $$ = $1; } | |
c3c20102 | 288 | | "return" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
289 | | "switch" { $$ = $1; } |
290 | | "this" { $$ = $1; } | |
c3c20102 | 291 | | "throw" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
292 | | "true" { $$ = $1; } |
293 | | "try" { $$ = $1; } | |
294 | | "typeof" { $$ = $1; } | |
295 | | "var" { $$ = $1; } | |
296 | | "void" { $$ = $1; } | |
297 | | "while" { $$ = $1; } | |
298 | | "with" { $$ = $1; } | |
2bf24581 JF |
299 | ; |
300 | ||
36cd3cb9 | 301 | IdentifierOpt |
cf7d4c69 JF |
302 | : Identifier { $$ = $1; } |
303 | | { $$ = NULL; } | |
1dbba6cc JF |
304 | ; |
305 | ||
36cd3cb9 | 306 | Literal |
cf7d4c69 JF |
307 | : NullLiteral { $$ = $1; } |
308 | | BooleanLiteral { $$ = $1; } | |
309 | | NumericLiteral { $$ = $1; } | |
310 | | StringLiteral { $$ = $1; } | |
1dbba6cc JF |
311 | ; |
312 | ||
36cd3cb9 | 313 | NullLiteral |
cf7d4c69 | 314 | : "null" { $$ = $1; } |
1dbba6cc JF |
315 | ; |
316 | ||
36cd3cb9 | 317 | BooleanLiteral |
cf7d4c69 JF |
318 | : "true" { $$ = $1; } |
319 | | "false" { $$ = $1; } | |
1dbba6cc JF |
320 | ; |
321 | ||
1dbba6cc | 322 | /* Objective-C Extensions {{{ */ |
36cd3cb9 JF |
323 | VariadicCall |
324 | : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); } | |
cf7d4c69 | 325 | | { $$ = NULL; } |
1dbba6cc JF |
326 | ; |
327 | ||
36cd3cb9 | 328 | SelectorCall_ |
cf7d4c69 JF |
329 | : SelectorCall { $$ = $1; } |
330 | | VariadicCall { $$ = $1; } | |
1dbba6cc JF |
331 | ; |
332 | ||
36cd3cb9 JF |
333 | SelectorCall |
334 | : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); } | |
1dbba6cc JF |
335 | ; |
336 | ||
36cd3cb9 | 337 | SelectorList |
cf7d4c69 | 338 | : SelectorCall { $$ = $1; } |
36cd3cb9 | 339 | | Word { $$ = new(driver.pool_) CYArgument($1, NULL); } |
1dbba6cc JF |
340 | ; |
341 | ||
36cd3cb9 JF |
342 | MessageExpression |
343 | : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); } | |
1dbba6cc JF |
344 | ; |
345 | /* }}} */ | |
346 | ||
347 | /* 11.1 Primary Expressions {{{ */ | |
36cd3cb9 | 348 | PrimaryExpression |
cf7d4c69 | 349 | : "this" { $$ = $1; } |
b1ff2d78 | 350 | | Identifier { $$ = new(driver.pool_) CYVariable($1); } |
cf7d4c69 JF |
351 | | Literal { $$ = $1; } |
352 | | ArrayLiteral { $$ = $1; } | |
353 | | ObjectLiteral { $$ = $1; } | |
36cd3cb9 | 354 | | "(" Expression ")" { $$ = $2; } |
cf7d4c69 | 355 | | MessageExpression { $$ = $1; } |
1dbba6cc JF |
356 | ; |
357 | /* }}} */ | |
358 | /* 11.1.4 Array Initialiser {{{ */ | |
36cd3cb9 JF |
359 | ArrayLiteral |
360 | : "[" ElementList "]" { $$ = $2; } | |
1dbba6cc JF |
361 | ; |
362 | ||
36cd3cb9 | 363 | Element |
cf7d4c69 JF |
364 | : AssignmentExpression { $$ = $1; } |
365 | | { $$ = NULL; } | |
1dbba6cc JF |
366 | ; |
367 | ||
36cd3cb9 JF |
368 | ElementList_ |
369 | : "," ElementList { $$ = $2; } | |
cf7d4c69 | 370 | | { $$ = NULL; } |
1dbba6cc JF |
371 | ; |
372 | ||
36cd3cb9 | 373 | ElementList |
b1ff2d78 | 374 | : Element ElementList_ { $$ = new(driver.pool_) CYElement($1, $2); } |
1dbba6cc JF |
375 | ; |
376 | /* }}} */ | |
377 | /* 11.1.5 Object Initialiser {{{ */ | |
36cd3cb9 | 378 | ObjectLiteral |
cf7d4c69 | 379 | : "{" PropertyNameAndValueListOpt "}" { $$ = $2; } |
1dbba6cc JF |
380 | ; |
381 | ||
36cd3cb9 | 382 | PropertyNameAndValueList_ |
cf7d4c69 JF |
383 | : "," PropertyNameAndValueList { $$ = $2; } |
384 | | { $$ = NULL; } | |
1dbba6cc JF |
385 | ; |
386 | ||
36cd3cb9 | 387 | PropertyNameAndValueListOpt |
cf7d4c69 | 388 | : PropertyNameAndValueList { $$ = $1; } |
36cd3cb9 | 389 | | { $$ = NULL; } |
1dbba6cc JF |
390 | ; |
391 | ||
36cd3cb9 JF |
392 | PropertyNameAndValueList |
393 | : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); } | |
1dbba6cc JF |
394 | ; |
395 | ||
396 | PropertyName | |
36cd3cb9 JF |
397 | : Identifier { $$ = $1; } |
398 | | StringLiteral { $$ = $1; } | |
399 | | NumericLiteral { $$ = $1; } | |
1dbba6cc JF |
400 | ; |
401 | /* }}} */ | |
402 | ||
36cd3cb9 | 403 | MemberExpression |
cf7d4c69 JF |
404 | : PrimaryExpression { $$ = $1; } |
405 | | FunctionExpression { $$ = $1; } | |
36cd3cb9 JF |
406 | | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } |
407 | | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } | |
408 | | "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); } | |
1dbba6cc JF |
409 | ; |
410 | ||
36cd3cb9 | 411 | NewExpression |
cf7d4c69 | 412 | : MemberExpression { $$ = $1; } |
36cd3cb9 | 413 | | "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); } |
1dbba6cc JF |
414 | ; |
415 | ||
36cd3cb9 | 416 | CallExpression |
b1ff2d78 JF |
417 | : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } |
418 | | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
36cd3cb9 JF |
419 | | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); } |
420 | | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); } | |
1dbba6cc JF |
421 | ; |
422 | ||
36cd3cb9 | 423 | ArgumentList_ |
cf7d4c69 JF |
424 | : "," ArgumentList { $$ = $2; } |
425 | | { $$ = NULL; } | |
1dbba6cc JF |
426 | ; |
427 | ||
36cd3cb9 | 428 | ArgumentListOpt |
cf7d4c69 | 429 | : ArgumentList { $$ = $1; } |
36cd3cb9 | 430 | | { $$ = NULL; } |
1dbba6cc JF |
431 | ; |
432 | ||
36cd3cb9 JF |
433 | ArgumentList |
434 | : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); } | |
1dbba6cc JF |
435 | ; |
436 | ||
437 | Arguments | |
36cd3cb9 | 438 | : "(" ArgumentListOpt ")" { $$ = $2; } |
1dbba6cc JF |
439 | ; |
440 | ||
36cd3cb9 | 441 | LeftHandSideExpression |
cf7d4c69 JF |
442 | : NewExpression { $$ = $1; } |
443 | | CallExpression { $$ = $1; } | |
36cd3cb9 | 444 | | "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); } |
1dbba6cc JF |
445 | ; |
446 | ||
36cd3cb9 | 447 | PostfixExpression |
cf7d4c69 | 448 | : LeftHandSideExpression { $$ = $1; } |
b1ff2d78 JF |
449 | | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); } |
450 | | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); } | |
1dbba6cc JF |
451 | ; |
452 | ||
36cd3cb9 JF |
453 | UnaryExpression |
454 | : PostfixExpression { $$ = $1; } | |
455 | | "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); } | |
456 | | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); } | |
457 | | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); } | |
458 | | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); } | |
459 | | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); } | |
460 | | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } | |
461 | | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } | |
462 | | "+" UnaryExpression { $$ = $2; } | |
463 | | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); } | |
464 | | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); } | |
465 | | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); } | |
466 | | "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); } | |
1dbba6cc JF |
467 | ; |
468 | ||
36cd3cb9 | 469 | MultiplicativeExpression |
cf7d4c69 | 470 | : UnaryExpression { $$ = $1; } |
36cd3cb9 JF |
471 | | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); } |
472 | | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); } | |
473 | | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); } | |
1dbba6cc JF |
474 | ; |
475 | ||
36cd3cb9 | 476 | AdditiveExpression |
cf7d4c69 | 477 | : MultiplicativeExpression { $$ = $1; } |
36cd3cb9 JF |
478 | | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } |
479 | | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } | |
1dbba6cc JF |
480 | ; |
481 | ||
36cd3cb9 | 482 | ShiftExpression |
cf7d4c69 | 483 | : AdditiveExpression { $$ = $1; } |
36cd3cb9 JF |
484 | | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); } |
485 | | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); } | |
486 | | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); } | |
1dbba6cc JF |
487 | ; |
488 | ||
36cd3cb9 | 489 | RelationalExpression |
cf7d4c69 | 490 | : ShiftExpression { $$ = $1; } |
36cd3cb9 JF |
491 | | RelationalExpression "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); } |
492 | | RelationalExpression ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); } | |
493 | | RelationalExpression "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); } | |
494 | | RelationalExpression ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); } | |
495 | | RelationalExpression "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); } | |
496 | | RelationalExpression "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); } | |
1dbba6cc JF |
497 | ; |
498 | ||
36cd3cb9 | 499 | EqualityExpression |
cf7d4c69 | 500 | : RelationalExpression { $$ = $1; } |
36cd3cb9 JF |
501 | | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); } |
502 | | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); } | |
503 | | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } | |
504 | | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } | |
1dbba6cc JF |
505 | ; |
506 | ||
36cd3cb9 | 507 | BitwiseANDExpression |
cf7d4c69 | 508 | : EqualityExpression { $$ = $1; } |
36cd3cb9 | 509 | | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } |
1dbba6cc JF |
510 | ; |
511 | ||
36cd3cb9 | 512 | BitwiseXORExpression |
cf7d4c69 | 513 | : BitwiseANDExpression { $$ = $1; } |
36cd3cb9 | 514 | | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } |
1dbba6cc JF |
515 | ; |
516 | ||
36cd3cb9 | 517 | BitwiseORExpression |
cf7d4c69 | 518 | : BitwiseXORExpression { $$ = $1; } |
36cd3cb9 | 519 | | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } |
1dbba6cc JF |
520 | ; |
521 | ||
36cd3cb9 | 522 | LogicalANDExpression |
cf7d4c69 | 523 | : BitwiseORExpression { $$ = $1; } |
36cd3cb9 | 524 | | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } |
1dbba6cc JF |
525 | ; |
526 | ||
36cd3cb9 | 527 | LogicalORExpression |
cf7d4c69 | 528 | : LogicalANDExpression { $$ = $1; } |
36cd3cb9 | 529 | | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } |
1dbba6cc JF |
530 | ; |
531 | ||
36cd3cb9 | 532 | ConditionalExpression |
cf7d4c69 | 533 | : LogicalORExpression { $$ = $1; } |
36cd3cb9 | 534 | | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); } |
1dbba6cc JF |
535 | ; |
536 | ||
36cd3cb9 | 537 | AssignmentExpression |
cf7d4c69 | 538 | : ConditionalExpression { $$ = $1; } |
36cd3cb9 JF |
539 | | LeftHandSideExpression "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); } |
540 | | LeftHandSideExpression "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); } | |
541 | | LeftHandSideExpression "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); } | |
542 | | LeftHandSideExpression "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); } | |
543 | | LeftHandSideExpression "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); } | |
544 | | LeftHandSideExpression "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); } | |
545 | | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); } | |
546 | | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); } | |
547 | | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); } | |
548 | | LeftHandSideExpression "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); } | |
549 | | LeftHandSideExpression "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); } | |
550 | | LeftHandSideExpression "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); } | |
551 | ; | |
552 | ||
553 | Expression_ | |
554 | : "," Expression { $$ = $2; } | |
cf7d4c69 | 555 | | { $$ = NULL; } |
1dbba6cc JF |
556 | ; |
557 | ||
36cd3cb9 | 558 | ExpressionOpt |
cf7d4c69 | 559 | : Expression { $$ = $1; } |
36cd3cb9 | 560 | | { $$ = NULL; } |
1dbba6cc JF |
561 | ; |
562 | ||
36cd3cb9 | 563 | Expression |
c3c20102 | 564 | : AssignmentExpression Expression_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; } |
1dbba6cc JF |
565 | ; |
566 | ||
36cd3cb9 JF |
567 | Statement |
568 | : Block { $$ = $1; } | |
569 | | VariableStatement { $$ = $1; } | |
570 | | EmptyStatement { $$ = $1; } | |
571 | | ExpressionStatement { $$ = $1; } | |
cf7d4c69 JF |
572 | | IfStatement { $$ = $1; } |
573 | | IterationStatement { $$ = $1; } | |
36cd3cb9 JF |
574 | | ContinueStatement { $$ = $1; } |
575 | | BreakStatement { $$ = $1; } | |
576 | | ReturnStatement { $$ = $1; } | |
cf7d4c69 JF |
577 | | WithStatement { $$ = $1; } |
578 | | LabelledStatement { $$ = $1; } | |
36cd3cb9 JF |
579 | | SwitchStatement { $$ = $1; } |
580 | | ThrowStatement { $$ = $1; } | |
581 | | TryStatement { $$ = $1; } | |
1dbba6cc JF |
582 | ; |
583 | ||
36cd3cb9 | 584 | Block |
b1ff2d78 | 585 | : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); } |
1dbba6cc JF |
586 | ; |
587 | ||
36cd3cb9 | 588 | StatementListOpt |
cf7d4c69 JF |
589 | : Statement StatementListOpt { $1->SetNext($2); $$ = $1; } |
590 | | { $$ = NULL; } | |
1dbba6cc JF |
591 | ; |
592 | ||
36cd3cb9 | 593 | VariableStatement |
c3c20102 | 594 | : "var" VariableDeclarationList Terminator { $$ = $2; } |
1dbba6cc JF |
595 | ; |
596 | ||
36cd3cb9 | 597 | VariableDeclarationList_ |
cf7d4c69 JF |
598 | : "," VariableDeclarationList { $$ = $2; } |
599 | | { $$ = NULL; } | |
1dbba6cc JF |
600 | ; |
601 | ||
36cd3cb9 | 602 | VariableDeclarationList |
b1ff2d78 | 603 | : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); } |
1dbba6cc JF |
604 | ; |
605 | ||
36cd3cb9 JF |
606 | VariableDeclaration |
607 | : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); } | |
1dbba6cc JF |
608 | ; |
609 | ||
36cd3cb9 | 610 | InitialiserOpt |
cf7d4c69 | 611 | : Initialiser { $$ = $1; } |
36cd3cb9 | 612 | | { $$ = NULL; } |
1dbba6cc JF |
613 | ; |
614 | ||
36cd3cb9 JF |
615 | Initialiser |
616 | : "=" AssignmentExpression { $$ = $2; } | |
1dbba6cc JF |
617 | ; |
618 | ||
36cd3cb9 | 619 | EmptyStatement |
b1ff2d78 | 620 | : ";" { $$ = new(driver.pool_) CYEmpty(); } |
1dbba6cc JF |
621 | ; |
622 | ||
36cd3cb9 | 623 | ExpressionStatement |
c3c20102 | 624 | : Expression Terminator { $$ = new(driver.pool_) CYExpress($1); } |
1dbba6cc JF |
625 | ; |
626 | ||
36cd3cb9 JF |
627 | ElseStatementOpt |
628 | : "else" Statement { $$ = $2; } | |
c3c20102 | 629 | | %prec "if" { $$ = NULL; } |
1dbba6cc JF |
630 | ; |
631 | ||
36cd3cb9 JF |
632 | IfStatement |
633 | : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); } | |
1dbba6cc JF |
634 | ; |
635 | ||
36cd3cb9 JF |
636 | IterationStatement |
637 | : DoWhileStatement { $$ = $1; } | |
cf7d4c69 JF |
638 | | WhileStatement { $$ = $1; } |
639 | | ForStatement { $$ = $1; } | |
640 | | ForInStatement { $$ = $1; } | |
1dbba6cc JF |
641 | ; |
642 | ||
36cd3cb9 JF |
643 | DoWhileStatement |
644 | : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); } | |
1dbba6cc JF |
645 | ; |
646 | ||
36cd3cb9 JF |
647 | WhileStatement |
648 | : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); } | |
1dbba6cc JF |
649 | ; |
650 | ||
36cd3cb9 JF |
651 | ForStatement |
652 | : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); } | |
1dbba6cc JF |
653 | ; |
654 | ||
36cd3cb9 | 655 | ForStatementInitialiser |
cf7d4c69 JF |
656 | : ExpressionOpt { $$ = $1; } |
657 | | "var" VariableDeclarationList { $$ = $2; } | |
1dbba6cc JF |
658 | ; |
659 | ||
36cd3cb9 JF |
660 | ForInStatement |
661 | : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); } | |
1dbba6cc JF |
662 | ; |
663 | ||
36cd3cb9 JF |
664 | ForInStatementInitialiser |
665 | : LeftHandSideExpression { $$ = $1; } | |
cf7d4c69 | 666 | | "var" VariableDeclaration { $$ = $2; } |
1dbba6cc JF |
667 | ; |
668 | ||
36cd3cb9 JF |
669 | ContinueStatement |
670 | : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); } | |
1dbba6cc JF |
671 | ; |
672 | ||
36cd3cb9 JF |
673 | BreakStatement |
674 | : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); } | |
1dbba6cc JF |
675 | ; |
676 | ||
36cd3cb9 | 677 | ReturnStatement |
c3c20102 | 678 | : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); } |
1dbba6cc JF |
679 | ; |
680 | ||
36cd3cb9 JF |
681 | WithStatement |
682 | : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); } | |
1dbba6cc JF |
683 | ; |
684 | ||
36cd3cb9 JF |
685 | SwitchStatement |
686 | : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); } | |
1dbba6cc JF |
687 | ; |
688 | ||
689 | CaseBlock | |
36cd3cb9 | 690 | : "{" CaseClausesOpt "}" { $$ = $2; } |
1dbba6cc JF |
691 | ; |
692 | ||
36cd3cb9 | 693 | CaseClausesOpt |
cf7d4c69 JF |
694 | : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } |
695 | | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | |
696 | | { $$ = NULL; } | |
1dbba6cc JF |
697 | ; |
698 | ||
36cd3cb9 JF |
699 | CaseClause |
700 | : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); } | |
1dbba6cc JF |
701 | ; |
702 | ||
36cd3cb9 JF |
703 | DefaultClause |
704 | : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); } | |
1dbba6cc JF |
705 | ; |
706 | ||
36cd3cb9 JF |
707 | LabelledStatement |
708 | : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; } | |
1dbba6cc JF |
709 | ; |
710 | ||
36cd3cb9 | 711 | ThrowStatement |
c3c20102 | 712 | : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); } |
1dbba6cc JF |
713 | ; |
714 | ||
36cd3cb9 | 715 | TryStatement |
b1ff2d78 | 716 | : "try" Block CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); } |
1dbba6cc JF |
717 | ; |
718 | ||
719 | CatchOpt | |
36cd3cb9 | 720 | : "catch" "(" Identifier ")" Block { $$ = new(driver.pool_) CYCatch($3, $5); } |
cf7d4c69 | 721 | | { $$ = NULL; } |
1dbba6cc JF |
722 | ; |
723 | ||
724 | FinallyOpt | |
36cd3cb9 | 725 | : "finally" Block { $$ = $2; } |
cf7d4c69 | 726 | | { $$ = NULL; } |
1dbba6cc JF |
727 | ; |
728 | ||
36cd3cb9 JF |
729 | FunctionDeclaration |
730 | : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); } | |
1dbba6cc JF |
731 | ; |
732 | ||
36cd3cb9 JF |
733 | FunctionExpression |
734 | : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); } | |
1dbba6cc JF |
735 | ; |
736 | ||
737 | FormalParameterList_ | |
36cd3cb9 | 738 | : "," FormalParameterList { $$ = $2; } |
cf7d4c69 | 739 | | { $$ = NULL; } |
1dbba6cc JF |
740 | ; |
741 | ||
742 | FormalParameterList | |
36cd3cb9 | 743 | : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); } |
cf7d4c69 | 744 | | { $$ = NULL; } |
1dbba6cc JF |
745 | ; |
746 | ||
36cd3cb9 JF |
747 | FunctionBody |
748 | : SourceElements { $$ = $1; } | |
1dbba6cc JF |
749 | ; |
750 | ||
751 | Program | |
36cd3cb9 | 752 | : SourceElements { driver.source_.push_back($1); $$ = $1; } |
1dbba6cc JF |
753 | ; |
754 | ||
36cd3cb9 JF |
755 | SourceElements |
756 | : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } | |
cf7d4c69 | 757 | | { $$ = NULL; } |
1dbba6cc JF |
758 | ; |
759 | ||
c3c20102 | 760 | /*Command |
36cd3cb9 | 761 | : SourceElement { driver.source_.push_back($2); if (driver.filename_.empty() && false) YYACCEPT; $2->Show(std::cout); } |
c3c20102 | 762 | ;*/ |
b1ff2d78 | 763 | |
36cd3cb9 | 764 | SourceElement |
cf7d4c69 | 765 | : Statement { $$ = $1; } |
36cd3cb9 | 766 | | FunctionDeclaration { $$ = $1; } |
1dbba6cc | 767 | ; |
e5332278 JF |
768 | |
769 | %% |