]>
Commit | Line | Data |
---|---|---|
1 | /* Cycript - Inlining/Optimizing JavaScript Compiler | |
2 | * Copyright (C) 2009 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
40 | %code top { | |
41 | #include "Cycript.tab.hh" | |
42 | #define scanner driver.scanner_ | |
43 | #define YYSTACKEXPANDABLE 1 | |
44 | } | |
45 | ||
46 | %code requires { | |
47 | #include "Parser.hpp" | |
48 | ||
49 | @begin ObjectiveC | |
50 | #include "ObjectiveC/Syntax.hpp" | |
51 | @end | |
52 | ||
53 | @begin E4X | |
54 | #include "E4X/Syntax.hpp" | |
55 | @end | |
56 | ||
57 | typedef struct { | |
58 | bool newline_; | |
59 | ||
60 | union { | |
61 | bool bool_; | |
62 | ||
63 | CYDriver::Condition condition_; | |
64 | ||
65 | CYArgument *argument_; | |
66 | CYAssignment *assignment_; | |
67 | CYBoolean *boolean_; | |
68 | CYClause *clause_; | |
69 | cy::Syntax::Catch *catch_; | |
70 | CYComprehension *comprehension_; | |
71 | CYCompound *compound_; | |
72 | CYDeclaration *declaration_; | |
73 | CYDeclarations *declarations_; | |
74 | CYElement *element_; | |
75 | CYExpression *expression_; | |
76 | CYFalse *false_; | |
77 | CYFinally *finally_; | |
78 | CYForInitialiser *for_; | |
79 | CYForInInitialiser *forin_; | |
80 | CYFunctionParameter *functionParameter_; | |
81 | CYIdentifier *identifier_; | |
82 | CYInfix *infix_; | |
83 | CYLiteral *literal_; | |
84 | CYMember *member_; | |
85 | CYNull *null_; | |
86 | CYNumber *number_; | |
87 | CYProgram *program_; | |
88 | CYProperty *property_; | |
89 | CYPropertyName *propertyName_; | |
90 | CYStatement *statement_; | |
91 | CYString *string_; | |
92 | CYThis *this_; | |
93 | CYTrue *true_; | |
94 | CYWord *word_; | |
95 | ||
96 | @begin ObjectiveC | |
97 | CYClassName *className_; | |
98 | CYField *field_; | |
99 | CYMessage *message_; | |
100 | CYMessageParameter *messageParameter_; | |
101 | CYSelectorPart *selector_; | |
102 | @end | |
103 | ||
104 | @begin E4X | |
105 | CYAttribute *attribute_; | |
106 | CYPropertyIdentifier *propertyIdentifier_; | |
107 | CYSelector *selector_; | |
108 | @end | |
109 | }; | |
110 | } YYSTYPE; | |
111 | ||
112 | } | |
113 | ||
114 | %code provides { | |
115 | int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); | |
116 | } | |
117 | ||
118 | %name-prefix "cy" | |
119 | ||
120 | %language "C++" | |
121 | %locations | |
122 | ||
123 | %initial-action { | |
124 | @$.begin.filename = @$.end.filename = &driver.filename_; | |
125 | }; | |
126 | ||
127 | %defines | |
128 | ||
129 | //%glr-parser | |
130 | //%expect 1 | |
131 | ||
132 | %error-verbose | |
133 | ||
134 | %parse-param { CYDriver &driver } | |
135 | %lex-param { void *scanner } | |
136 | ||
137 | @begin E4X | |
138 | %token XMLCDATA | |
139 | %token XMLComment | |
140 | %token XMLPI | |
141 | ||
142 | %token XMLAttributeValue | |
143 | %token XMLName | |
144 | %token XMLTagCharacters | |
145 | %token XMLText | |
146 | %token XMLWhitespace | |
147 | @end | |
148 | ||
149 | @begin E4X | |
150 | %token LeftRight "<>" | |
151 | %token LeftSlashRight "</>" | |
152 | ||
153 | %token SlashRight "/>" | |
154 | %token LeftSlash "</" | |
155 | ||
156 | %token ColonColon "::" | |
157 | %token PeriodPeriod ".." | |
158 | @end | |
159 | ||
160 | @begin E4X ObjectiveC | |
161 | %token At "@" | |
162 | @end | |
163 | ||
164 | %token Ampersand "&" | |
165 | %token AmpersandAmpersand "&&" | |
166 | %token AmpersandEqual "&=" | |
167 | %token Carrot "^" | |
168 | %token CarrotEqual "^=" | |
169 | %token Equal "=" | |
170 | %token EqualEqual "==" | |
171 | %token EqualEqualEqual "===" | |
172 | %token Exclamation "!" | |
173 | %token ExclamationEqual "!=" | |
174 | %token ExclamationEqualEqual "!==" | |
175 | %token Hyphen "-" | |
176 | %token HyphenEqual "-=" | |
177 | %token HyphenHyphen "--" | |
178 | %token HyphenHyphen_ "\n--" | |
179 | %token HyphenRight "->" | |
180 | %token Left "<" | |
181 | %token LeftEqual "<=" | |
182 | %token LeftLeft "<<" | |
183 | %token LeftLeftEqual "<<=" | |
184 | %token Percent "%" | |
185 | %token PercentEqual "%=" | |
186 | %token Period "." | |
187 | %token Pipe "|" | |
188 | %token PipeEqual "|=" | |
189 | %token PipePipe "||" | |
190 | %token Plus "+" | |
191 | %token PlusEqual "+=" | |
192 | %token PlusPlus "++" | |
193 | %token PlusPlus_ "\n++" | |
194 | %token Right ">" | |
195 | %token RightEqual ">=" | |
196 | %token RightRight ">>" | |
197 | %token RightRightEqual ">>=" | |
198 | %token RightRightRight ">>>" | |
199 | %token RightRightRightEqual ">>>=" | |
200 | %token Slash "/" | |
201 | %token SlashEqual "/=" | |
202 | %token Star "*" | |
203 | %token StarEqual "*=" | |
204 | %token Tilde "~" | |
205 | ||
206 | %token Colon ":" | |
207 | %token Comma "," | |
208 | %token Question "?" | |
209 | %token SemiColon ";" | |
210 | %token NewLine "\n" | |
211 | ||
212 | %token OpenParen "(" | |
213 | %token CloseParen ")" | |
214 | ||
215 | %token OpenBrace "{" | |
216 | %token CloseBrace "}" | |
217 | ||
218 | %token OpenBracket "[" | |
219 | %token CloseBracket "]" | |
220 | ||
221 | %token AtClass "@class" | |
222 | %token AtSelector "@selector" | |
223 | %token AtEnd "@end" | |
224 | ||
225 | %token <false_> False "false" | |
226 | %token <null_> Null "null" | |
227 | %token <true_> True "true" | |
228 | ||
229 | // ES3/ES5/WIE/JSC Reserved | |
230 | %token <word_> Break "break" | |
231 | %token <word_> Case "case" | |
232 | %token <word_> Catch "catch" | |
233 | %token <word_> Continue "continue" | |
234 | %token <word_> Default "default" | |
235 | %token <word_> Delete "delete" | |
236 | %token <word_> Do "do" | |
237 | %token <word_> Else "else" | |
238 | %token <word_> Finally "finally" | |
239 | %token <word_> For "for" | |
240 | %token <word_> Function "function" | |
241 | %token <word_> If "if" | |
242 | %token <word_> In "in" | |
243 | %token <word_> InstanceOf "instanceof" | |
244 | %token <word_> New "new" | |
245 | %token <word_> Return "return" | |
246 | %token <word_> Switch "switch" | |
247 | %token <this_> This "this" | |
248 | %token <word_> Throw "throw" | |
249 | %token <word_> Try "try" | |
250 | %token <word_> TypeOf "typeof" | |
251 | %token <word_> Var "var" | |
252 | %token <word_> Void "void" | |
253 | %token <word_> While "while" | |
254 | %token <word_> With "with" | |
255 | ||
256 | // ES3/IE6 Future, ES5/JSC Reserved | |
257 | %token <word_> Debugger "debugger" | |
258 | ||
259 | // ES3/ES5/IE6 Future, JSC Reserved | |
260 | %token <word_> Const "const" | |
261 | ||
262 | // ES3/ES5/IE6/JSC Future | |
263 | %token <word_> Class "class" | |
264 | %token <word_> Enum "enum" | |
265 | %token <word_> Export "export" | |
266 | %token <word_> Extends "extends" | |
267 | %token <word_> Import "import" | |
268 | %token <word_> Super "super" | |
269 | ||
270 | // ES3 Future, ES5 Strict Future | |
271 | %token <identifier_> Implements "implements" | |
272 | %token <identifier_> Interface "interface" | |
273 | %token <identifier_> Package "package" | |
274 | %token <identifier_> Private "private" | |
275 | %token <identifier_> Protected "protected" | |
276 | %token <identifier_> Public "public" | |
277 | %token <identifier_> Static "static" | |
278 | ||
279 | // ES3 Future | |
280 | %token <identifier_> Abstract "abstract" | |
281 | %token <identifier_> Boolean "boolean" | |
282 | %token <identifier_> Byte "byte" | |
283 | %token <identifier_> Char "char" | |
284 | %token <identifier_> Double "double" | |
285 | %token <identifier_> Final "final" | |
286 | %token <identifier_> Float "float" | |
287 | %token <identifier_> Goto "goto" | |
288 | %token <identifier_> Int "int" | |
289 | %token <identifier_> Long "long" | |
290 | %token <identifier_> Native "native" | |
291 | %token <identifier_> Short "short" | |
292 | %token <identifier_> Synchronized "synchronized" | |
293 | %token <identifier_> Throws "throws" | |
294 | %token <identifier_> Transient "transient" | |
295 | %token <identifier_> Volatile "volatile" | |
296 | ||
297 | // ES5 Strict | |
298 | %token <identifier_> Let "let" | |
299 | %token <identifier_> Yield "yield" | |
300 | ||
301 | // Woah?! | |
302 | %token <identifier_> Each "each" | |
303 | ||
304 | @begin E4X | |
305 | // E4X Conditional | |
306 | %token <identifier_> Namespace "namespace" | |
307 | %token <identifier_> XML "xml" | |
308 | @end | |
309 | ||
310 | %token <identifier_> Identifier_ | |
311 | %token <number_> NumericLiteral | |
312 | %token <string_> StringLiteral | |
313 | %token <literal_> RegularExpressionLiteral | |
314 | ||
315 | %type <expression_> AdditiveExpression | |
316 | %type <expression_> AdditiveExpressionNoBF | |
317 | %type <argument_> ArgumentList | |
318 | %type <argument_> ArgumentList_ | |
319 | %type <argument_> ArgumentListOpt | |
320 | %type <argument_> Arguments | |
321 | %type <literal_> ArrayLiteral | |
322 | %type <expression_> AssigneeExpression | |
323 | %type <expression_> AssigneeExpressionNoBF | |
324 | %type <expression_> AssigneeExpressionNoRE | |
325 | %type <expression_> AssignmentExpression | |
326 | %type <assignment_> AssignmentExpression_ | |
327 | %type <expression_> AssignmentExpressionNoBF | |
328 | %type <expression_> AssignmentExpressionNoIn | |
329 | %type <expression_> BitwiseANDExpression | |
330 | %type <expression_> BitwiseANDExpressionNoBF | |
331 | %type <expression_> BitwiseANDExpressionNoIn | |
332 | %type <statement_> Block | |
333 | %type <statement_> Block_ | |
334 | %type <boolean_> BooleanLiteral | |
335 | %type <expression_> BitwiseORExpression | |
336 | %type <expression_> BitwiseORExpressionNoBF | |
337 | %type <expression_> BitwiseORExpressionNoIn | |
338 | %type <expression_> BitwiseXORExpression | |
339 | %type <expression_> BitwiseXORExpressionNoBF | |
340 | %type <expression_> BitwiseXORExpressionNoIn | |
341 | %type <statement_> BreakStatement | |
342 | %type <expression_> CallExpression | |
343 | %type <expression_> CallExpressionNoBF | |
344 | %type <expression_> CallExpressionNoRE | |
345 | %type <clause_> CaseBlock | |
346 | %type <clause_> CaseClause | |
347 | %type <clause_> CaseClausesOpt | |
348 | %type <catch_> CatchOpt | |
349 | %type <comprehension_> ComprehensionList | |
350 | %type <comprehension_> ComprehensionListOpt | |
351 | %type <expression_> ConditionalExpression | |
352 | %type <expression_> ConditionalExpressionNoBF | |
353 | %type <expression_> ConditionalExpressionNoIn | |
354 | %type <statement_> ContinueStatement | |
355 | %type <clause_> DefaultClause | |
356 | %type <statement_> DoWhileStatement | |
357 | %type <expression_> Element | |
358 | %type <expression_> ElementOpt | |
359 | %type <element_> ElementList | |
360 | %type <element_> ElementListOpt | |
361 | %type <statement_> ElseStatementOpt | |
362 | %type <statement_> EmptyStatement | |
363 | %type <expression_> EqualityExpression | |
364 | %type <expression_> EqualityExpressionNoBF | |
365 | %type <expression_> EqualityExpressionNoIn | |
366 | %type <expression_> Expression | |
367 | %type <expression_> ExpressionOpt | |
368 | %type <compound_> Expression_ | |
369 | %type <expression_> ExpressionNoBF | |
370 | %type <expression_> ExpressionNoIn | |
371 | %type <compound_> ExpressionNoIn_ | |
372 | %type <expression_> ExpressionNoInOpt | |
373 | %type <statement_> ExpressionStatement | |
374 | %type <finally_> FinallyOpt | |
375 | %type <comprehension_> ForComprehension | |
376 | %type <statement_> ForStatement | |
377 | %type <for_> ForStatementInitialiser | |
378 | %type <statement_> ForInStatement | |
379 | %type <forin_> ForInStatementInitialiser | |
380 | %type <functionParameter_> FormalParameterList | |
381 | %type <functionParameter_> FormalParameterList_ | |
382 | %type <statement_> FunctionBody | |
383 | %type <statement_> FunctionDeclaration | |
384 | %type <expression_> FunctionExpression | |
385 | %type <identifier_> Identifier | |
386 | %type <identifier_> IdentifierOpt | |
387 | %type <comprehension_> IfComprehension | |
388 | %type <statement_> IfStatement | |
389 | %type <expression_> Initialiser | |
390 | %type <expression_> InitialiserOpt | |
391 | %type <expression_> InitialiserNoIn | |
392 | %type <expression_> InitialiserNoInOpt | |
393 | %type <statement_> IterationStatement | |
394 | %type <statement_> LabelledStatement | |
395 | %type <expression_> LeftHandSideExpression | |
396 | %type <expression_> LeftHandSideExpressionNoBF | |
397 | %type <expression_> LeftHandSideExpressionNoRE | |
398 | //%type <statement_> LetStatement | |
399 | %type <literal_> Literal | |
400 | %type <literal_> LiteralNoRE | |
401 | %type <literal_> LiteralRE | |
402 | %type <expression_> LogicalANDExpression | |
403 | %type <expression_> LogicalANDExpressionNoBF | |
404 | %type <expression_> LogicalANDExpressionNoIn | |
405 | %type <expression_> LogicalORExpression | |
406 | %type <expression_> LogicalORExpressionNoBF | |
407 | %type <expression_> LogicalORExpressionNoIn | |
408 | %type <member_> MemberAccess | |
409 | %type <expression_> MemberExpression | |
410 | %type <expression_> MemberExpression_ | |
411 | %type <expression_> MemberExpressionNoBF | |
412 | %type <expression_> MemberExpressionNoRE | |
413 | %type <expression_> MultiplicativeExpression | |
414 | %type <expression_> MultiplicativeExpressionNoBF | |
415 | %type <expression_> NewExpression | |
416 | %type <expression_> NewExpression_ | |
417 | %type <expression_> NewExpressionNoBF | |
418 | %type <expression_> NewExpressionNoRE | |
419 | %type <null_> NullLiteral | |
420 | %type <literal_> ObjectLiteral | |
421 | %type <expression_> PostfixExpression | |
422 | %type <expression_> PostfixExpressionNoBF | |
423 | %type <expression_> PostfixExpressionNoRE | |
424 | %type <expression_> PrimaryExpression | |
425 | %type <expression_> PrimaryExpressionNo | |
426 | %type <expression_> PrimaryExpressionNoBF | |
427 | %type <expression_> PrimaryExpressionNoRE | |
428 | %type <expression_> PrimaryExpressionBF | |
429 | %type <statement_> Program | |
430 | %type <propertyName_> PropertyName | |
431 | %type <propertyName_> PropertyName_ | |
432 | %type <property_> PropertyNameAndValueList | |
433 | %type <property_> PropertyNameAndValueList_ | |
434 | %type <property_> PropertyNameAndValueListOpt | |
435 | %type <expression_> RelationalExpression | |
436 | %type <infix_> RelationalExpression_ | |
437 | %type <expression_> RelationalExpressionNoBF | |
438 | %type <expression_> RelationalExpressionNoIn | |
439 | %type <infix_> RelationalExpressionNoIn_ | |
440 | %type <statement_> ReturnStatement | |
441 | %type <expression_> ShiftExpression | |
442 | %type <expression_> ShiftExpressionNoBF | |
443 | %type <statement_> SourceElement | |
444 | %type <statement_> SourceElement_ | |
445 | %type <statement_> SourceElements | |
446 | %type <statement_> Statement | |
447 | %type <statement_> Statement_ | |
448 | %type <statement_> StatementList | |
449 | %type <statement_> StatementListOpt | |
450 | %type <statement_> SwitchStatement | |
451 | %type <statement_> ThrowStatement | |
452 | %type <statement_> TryStatement | |
453 | %type <expression_> UnaryAssigneeExpression | |
454 | %type <expression_> UnaryExpression | |
455 | %type <expression_> UnaryExpression_ | |
456 | %type <expression_> UnaryExpressionNoBF | |
457 | %type <expression_> UnaryExpressionNoRE | |
458 | %type <declaration_> VariableDeclaration | |
459 | %type <declaration_> VariableDeclarationNoIn | |
460 | %type <declarations_> VariableDeclarationList | |
461 | %type <declarations_> VariableDeclarationList_ | |
462 | %type <declarations_> VariableDeclarationListNoIn | |
463 | %type <declarations_> VariableDeclarationListNoIn_ | |
464 | %type <statement_> VariableStatement | |
465 | %type <statement_> WhileStatement | |
466 | %type <statement_> WithStatement | |
467 | ||
468 | @begin ObjectiveC | |
469 | %type <statement_> CategoryStatement | |
470 | %type <expression_> ClassExpression | |
471 | %type <statement_> ClassStatement | |
472 | %type <expression_> ClassSuperOpt | |
473 | %type <field_> ClassFieldList | |
474 | %type <message_> ClassMessageDeclaration | |
475 | %type <message_> ClassMessageDeclarationListOpt | |
476 | %type <className_> ClassName | |
477 | %type <className_> ClassNameOpt | |
478 | %type <expression_> MessageExpression | |
479 | %type <messageParameter_> MessageParameter | |
480 | %type <messageParameter_> MessageParameters | |
481 | %type <messageParameter_> MessageParameterList | |
482 | %type <messageParameter_> MessageParameterListOpt | |
483 | %type <bool_> MessageScope | |
484 | %type <argument_> SelectorCall | |
485 | %type <argument_> SelectorCall_ | |
486 | %type <selector_> SelectorExpression | |
487 | %type <selector_> SelectorExpression_ | |
488 | %type <selector_> SelectorExpressionOpt | |
489 | %type <argument_> SelectorList | |
490 | %type <expression_> TypeOpt | |
491 | %type <argument_> VariadicCall | |
492 | %type <word_> Word | |
493 | %type <word_> WordOpt | |
494 | @end | |
495 | ||
496 | @begin E4X | |
497 | %type <propertyIdentifier_> PropertyIdentifier_ | |
498 | %type <selector_> PropertySelector | |
499 | %type <selector_> PropertySelector_ | |
500 | %type <identifier_> QualifiedIdentifier | |
501 | %type <identifier_> QualifiedIdentifier_ | |
502 | %type <identifier_> WildcardIdentifier | |
503 | %type <identifier_> XMLComment | |
504 | %type <identifier_> XMLCDATA | |
505 | %type <identifier_> XMLElement | |
506 | %type <identifier_> XMLElementContent | |
507 | %type <identifier_> XMLMarkup | |
508 | %type <identifier_> XMLPI | |
509 | ||
510 | %type <attribute_> AttributeIdentifier | |
511 | /* XXX: %type <statement_> DefaultXMLNamespaceStatement */ | |
512 | %type <expression_> PropertyIdentifier | |
513 | %type <expression_> XMLListInitialiser | |
514 | %type <expression_> XMLInitialiser | |
515 | @end | |
516 | ||
517 | %nonassoc Identifier_ "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "debugger" "default" "delete" "do" "double" "each" "enum" "export" "extends" "false" "final" "finally" "float" /*"for"*/ "function" "goto" "implements" "import" /*"in"*/ /*"instanceof"*/ "int" "interface" "let" "long" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return" "short" "super" "static" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "var" "void" "volatile" "while" "with" "xml" "yield" | |
518 | ||
519 | %nonassoc "if" | |
520 | %nonassoc "else" | |
521 | ||
522 | %nonassoc "++" "--" | |
523 | %nonassoc "(" "[" | |
524 | ||
525 | %left "*" "/" "%" | |
526 | %left "+" "-" | |
527 | %left "<<" ">>" ">>>" | |
528 | %left "<" ">" "<=" ">=" "instanceof" "in" | |
529 | %left "==" "!=" "===" "!==" | |
530 | %left "&" | |
531 | %left "^" | |
532 | %left "|" | |
533 | %left "&&" | |
534 | %left "||" | |
535 | ||
536 | %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" | |
537 | ||
538 | %start Program | |
539 | ||
540 | %% | |
541 | ||
542 | /* Lexer State {{{ */ | |
543 | LexSetRegExp | |
544 | : { driver.SetCondition(CYDriver::RegExpCondition); } | |
545 | ; | |
546 | /* }}} */ | |
547 | ||
548 | StrictSemi | |
549 | : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } | |
550 | ; | |
551 | ||
552 | Terminator_ | |
553 | : ";" | |
554 | | "\n" StrictSemi | |
555 | ; | |
556 | ||
557 | TerminatorOpt | |
558 | : Terminator_ | |
559 | | error { yyerrok; driver.errors_.pop_back(); } StrictSemi | |
560 | ; | |
561 | ||
562 | Terminator | |
563 | : Terminator_ | |
564 | | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi | |
565 | ; | |
566 | ||
567 | /*CommaOpt | |
568 | : "," | |
569 | | | |
570 | ;*/ | |
571 | ||
572 | @begin ObjectiveC | |
573 | NewLineOpt | |
574 | : "\n" | |
575 | | | |
576 | ; | |
577 | ||
578 | WordOpt | |
579 | : Word { $$ = $1; } | |
580 | | { $$ = NULL; } | |
581 | ; | |
582 | ||
583 | Word | |
584 | : Identifier { $$ = $1; } | |
585 | | "break" NewLineOpt { $$ = $1; } | |
586 | | "case" { $$ = $1; } | |
587 | | "catch" { $$ = $1; } | |
588 | | "class" { $$ = $1; } | |
589 | | "const" { $$ = $1; } | |
590 | | "continue" NewLineOpt { $$ = $1; } | |
591 | | "debugger" { $$ = $1; } | |
592 | | "default" { $$ = $1; } | |
593 | | "delete" { $$ = $1; } | |
594 | | "do" { $$ = $1; } | |
595 | | "else" { $$ = $1; } | |
596 | | "enum" { $$ = $1; } | |
597 | | "export" { $$ = $1; } | |
598 | | "extends" { $$ = $1; } | |
599 | | "false" { $$ = $1; } | |
600 | | "finally" { $$ = $1; } | |
601 | /* XXX: | "for" { $$ = $1; } */ | |
602 | | "function" { $$ = $1; } | |
603 | | "if" { $$ = $1; } | |
604 | | "import" { $$ = $1; } | |
605 | /* XXX: | "in" { $$ = $1; } */ | |
606 | /* XXX: | "instanceof" { $$ = $1; } */ | |
607 | | "new" { $$ = $1; } | |
608 | | "null" { $$ = $1; } | |
609 | | "return" NewLineOpt { $$ = $1; } | |
610 | | "super" { $$ = $1; } | |
611 | | "switch" { $$ = $1; } | |
612 | | "this" { $$ = $1; } | |
613 | | "throw" NewLineOpt { $$ = $1; } | |
614 | | "true" { $$ = $1; } | |
615 | | "try" { $$ = $1; } | |
616 | | "typeof" { $$ = $1; } | |
617 | | "var" { $$ = $1; } | |
618 | | "void" { $$ = $1; } | |
619 | | "while" { $$ = $1; } | |
620 | | "with" { $$ = $1; } | |
621 | ; | |
622 | @end | |
623 | ||
624 | Identifier | |
625 | : Identifier_ { $$ = $1; } | |
626 | ||
627 | | "implements" { $$ = $1; } | |
628 | | "interface" { $$ = $1; } | |
629 | | "package" { $$ = $1; } | |
630 | | "private" { $$ = $1; } | |
631 | | "protected" { $$ = $1; } | |
632 | | "public" { $$ = $1; } | |
633 | | "static" { $$ = $1; } | |
634 | ||
635 | | "abstract" { $$ = $1; } | |
636 | | "boolean" { $$ = $1; } | |
637 | | "byte" { $$ = $1; } | |
638 | | "char" { $$ = $1; } | |
639 | | "double" { $$ = $1; } | |
640 | | "final" { $$ = $1; } | |
641 | | "float" { $$ = $1; } | |
642 | | "goto" { $$ = $1; } | |
643 | | "int" { $$ = $1; } | |
644 | | "long" { $$ = $1; } | |
645 | | "native" { $$ = $1; } | |
646 | | "short" { $$ = $1; } | |
647 | | "synchronized" { $$ = $1; } | |
648 | | "throws" { $$ = $1; } | |
649 | | "transient" { $$ = $1; } | |
650 | | "volatile" { $$ = $1; } | |
651 | ||
652 | | "let" { $$ = $1; } | |
653 | | "yield" { $$ = $1; } | |
654 | ||
655 | | "each" { $$ = $1; } | |
656 | ; | |
657 | ||
658 | IdentifierOpt | |
659 | : Identifier { $$ = $1; } | |
660 | | { $$ = NULL; } | |
661 | ; | |
662 | ||
663 | LiteralNoRE | |
664 | : NullLiteral { $$ = $1; } | |
665 | | BooleanLiteral { $$ = $1; } | |
666 | | NumericLiteral { $$ = $1; } | |
667 | | StringLiteral { $$ = $1; } | |
668 | | "@" StringLiteral { $$ = $2; } | |
669 | ; | |
670 | ||
671 | LiteralRE | |
672 | : RegularExpressionLiteral { $$ = $1; } | |
673 | ; | |
674 | ||
675 | Literal | |
676 | : LiteralNoRE { $$ = $1; } | |
677 | | LiteralRE { $$ = $1; } | |
678 | ; | |
679 | ||
680 | NullLiteral | |
681 | : "null" { $$ = $1; } | |
682 | ; | |
683 | ||
684 | BooleanLiteral | |
685 | : "true" { $$ = $1; } | |
686 | | "false" { $$ = $1; } | |
687 | ; | |
688 | ||
689 | /* 11.1 Primary Expressions {{{ */ | |
690 | PrimaryExpression | |
691 | : LexSetRegExp PrimaryExpressionNoRE { $$ = $2; } | |
692 | ; | |
693 | ||
694 | PrimaryExpressionNoBF | |
695 | : PrimaryExpressionNo { $$ = $1; } | |
696 | ; | |
697 | ||
698 | PrimaryExpressionNoRE | |
699 | : PrimaryExpressionBF { $$ = $1; } | |
700 | | PrimaryExpressionNo { $$ = $1; } | |
701 | ; | |
702 | ||
703 | PrimaryExpressionNo | |
704 | : "this" { $$ = $1; } | |
705 | | Identifier { $$ = new(driver.pool_) CYVariable($1); } | |
706 | | Literal { $$ = $1; } | |
707 | | ArrayLiteral { $$ = $1; } | |
708 | | "(" Expression ")" { $$ = $2; } | |
709 | ; | |
710 | ||
711 | PrimaryExpressionBF | |
712 | : ObjectLiteral { $$ = $1; } | |
713 | ; | |
714 | /* }}} */ | |
715 | /* 11.1.4 Array Initialiser {{{ */ | |
716 | ArrayLiteral | |
717 | : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); } | |
718 | ; | |
719 | ||
720 | Element | |
721 | : AssignmentExpression { $$ = $1; } | |
722 | ; | |
723 | ||
724 | ElementOpt | |
725 | : Element { $$ = $1; } | |
726 | | LexSetRegExp { $$ = NULL; } | |
727 | ; | |
728 | ||
729 | ElementListOpt | |
730 | : ElementList { $$ = $1; } | |
731 | | LexSetRegExp { $$ = NULL; } | |
732 | ; | |
733 | ||
734 | ElementList | |
735 | : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); } | |
736 | | Element { $$ = new(driver.pool_) CYElement($1, NULL); } | |
737 | ; | |
738 | /* }}} */ | |
739 | /* 11.1.5 Object Initialiser {{{ */ | |
740 | ObjectLiteral | |
741 | : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); } | |
742 | ; | |
743 | ||
744 | PropertyNameAndValueList_ | |
745 | : "," PropertyNameAndValueList { $$ = $2; } | |
746 | | { $$ = NULL; } | |
747 | ; | |
748 | ||
749 | PropertyNameAndValueListOpt | |
750 | : PropertyNameAndValueList { $$ = $1; } | |
751 | | { $$ = NULL; } | |
752 | ; | |
753 | ||
754 | PropertyNameAndValueList | |
755 | : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); } | |
756 | ; | |
757 | ||
758 | PropertyName_ | |
759 | : Identifier { $$ = $1; } | |
760 | | StringLiteral { $$ = $1; } | |
761 | | NumericLiteral { $$ = $1; } | |
762 | ; | |
763 | ||
764 | PropertyName | |
765 | : LexSetRegExp PropertyName_ { $$ = $2; } | |
766 | ; | |
767 | /* }}} */ | |
768 | ||
769 | /* 11.2 Left-Hand-Side Expressions {{{ */ | |
770 | MemberExpression_ | |
771 | : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); } | |
772 | ; | |
773 | ||
774 | MemberAccess | |
775 | : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); } | |
776 | | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); } | |
777 | ; | |
778 | ||
779 | MemberExpression | |
780 | : PrimaryExpression { $$ = $1; } | |
781 | | LexSetRegExp FunctionExpression { $$ = $2; } | |
782 | | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | |
783 | | LexSetRegExp MemberExpression_ { $$ = $2; } | |
784 | ; | |
785 | ||
786 | MemberExpressionNoBF | |
787 | : PrimaryExpressionNoBF { $$ = $1; } | |
788 | | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } | |
789 | | MemberExpression_ { $$ = $1; } | |
790 | ; | |
791 | ||
792 | MemberExpressionNoRE | |
793 | : PrimaryExpressionNoRE { $$ = $1; } | |
794 | | FunctionExpression { $$ = $1; } | |
795 | | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } | |
796 | | MemberExpression_ { $$ = $1; } | |
797 | ; | |
798 | ||
799 | NewExpression_ | |
800 | : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); } | |
801 | ; | |
802 | ||
803 | NewExpression | |
804 | : MemberExpression { $$ = $1; } | |
805 | | LexSetRegExp NewExpression_ { $$ = $2; } | |
806 | ; | |
807 | ||
808 | NewExpressionNoBF | |
809 | : MemberExpressionNoBF { $$ = $1; } | |
810 | | NewExpression_ { $$ = $1; } | |
811 | ; | |
812 | ||
813 | NewExpressionNoRE | |
814 | : MemberExpressionNoRE { $$ = $1; } | |
815 | | NewExpression_ { $$ = $1; } | |
816 | ; | |
817 | ||
818 | CallExpression | |
819 | : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
820 | | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
821 | | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | |
822 | ; | |
823 | ||
824 | CallExpressionNoBF | |
825 | : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
826 | | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
827 | | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } | |
828 | ; | |
829 | ||
830 | CallExpressionNoRE | |
831 | : MemberExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
832 | | CallExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | |
833 | | CallExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } | |
834 | ; | |
835 | ||
836 | ArgumentList_ | |
837 | : "," ArgumentList { $$ = $2; } | |
838 | | { $$ = NULL; } | |
839 | ; | |
840 | ||
841 | ArgumentListOpt | |
842 | : ArgumentList { $$ = $1; } | |
843 | | LexSetRegExp { $$ = NULL; } | |
844 | ; | |
845 | ||
846 | ArgumentList | |
847 | : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); } | |
848 | ; | |
849 | ||
850 | Arguments | |
851 | : "(" ArgumentListOpt ")" { $$ = $2; } | |
852 | ; | |
853 | ||
854 | LeftHandSideExpression | |
855 | : NewExpression { $$ = $1; } | |
856 | | CallExpression { $$ = $1; } | |
857 | ; | |
858 | ||
859 | LeftHandSideExpressionNoBF | |
860 | : NewExpressionNoBF { $$ = $1; } | |
861 | | CallExpressionNoBF { $$ = $1; } | |
862 | ; | |
863 | ||
864 | LeftHandSideExpressionNoRE | |
865 | : NewExpressionNoRE { $$ = $1; } | |
866 | | CallExpressionNoRE { $$ = $1; } | |
867 | ; | |
868 | /* }}} */ | |
869 | /* 11.3 Postfix Expressions {{{ */ | |
870 | PostfixExpression | |
871 | : AssigneeExpression { $$ = $1; } | |
872 | | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | |
873 | | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); } | |
874 | ; | |
875 | ||
876 | PostfixExpressionNoBF | |
877 | : AssigneeExpressionNoBF { $$ = $1; } | |
878 | | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | |
879 | | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); } | |
880 | ; | |
881 | ||
882 | PostfixExpressionNoRE | |
883 | : AssigneeExpressionNoRE { $$ = $1; } | |
884 | | LeftHandSideExpressionNoRE "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | |
885 | | LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); } | |
886 | ; | |
887 | /* }}} */ | |
888 | /* 11.4 Unary Operators {{{ */ | |
889 | UnaryExpression_ | |
890 | : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); } | |
891 | | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); } | |
892 | | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); } | |
893 | | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); } | |
894 | | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); } | |
895 | | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } | |
896 | | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } | |
897 | | "+" UnaryExpression { $$ = new(driver.pool_) CYAffirm($2); } | |
898 | | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); } | |
899 | | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); } | |
900 | | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); } | |
901 | ; | |
902 | ||
903 | UnaryExpression | |
904 | : PostfixExpression { $$ = $1; } | |
905 | | LexSetRegExp UnaryExpression_ { $$ = $2; } | |
906 | ; | |
907 | ||
908 | UnaryExpressionNoBF | |
909 | : PostfixExpressionNoBF { $$ = $1; } | |
910 | | UnaryExpression_ { $$ = $1; } | |
911 | ; | |
912 | ||
913 | UnaryExpressionNoRE | |
914 | : PostfixExpressionNoRE { $$ = $1; } | |
915 | | UnaryExpression_ { $$ = $1; } | |
916 | ; | |
917 | /* }}} */ | |
918 | /* 11.5 Multiplicative Operators {{{ */ | |
919 | MultiplicativeExpression | |
920 | : UnaryExpression { $$ = $1; } | |
921 | | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); } | |
922 | | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); } | |
923 | | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); } | |
924 | ; | |
925 | ||
926 | MultiplicativeExpressionNoBF | |
927 | : UnaryExpressionNoBF { $$ = $1; } | |
928 | | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); } | |
929 | | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); } | |
930 | | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); } | |
931 | ; | |
932 | /* }}} */ | |
933 | /* 11.6 Additive Operators {{{ */ | |
934 | AdditiveExpression | |
935 | : MultiplicativeExpression { $$ = $1; } | |
936 | | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } | |
937 | | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } | |
938 | ; | |
939 | ||
940 | AdditiveExpressionNoBF | |
941 | : MultiplicativeExpressionNoBF { $$ = $1; } | |
942 | | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } | |
943 | | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } | |
944 | ; | |
945 | /* }}} */ | |
946 | /* 11.7 Bitwise Shift Operators {{{ */ | |
947 | ShiftExpression | |
948 | : AdditiveExpression { $$ = $1; } | |
949 | | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); } | |
950 | | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); } | |
951 | | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); } | |
952 | ; | |
953 | ||
954 | ShiftExpressionNoBF | |
955 | : AdditiveExpressionNoBF { $$ = $1; } | |
956 | | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); } | |
957 | | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); } | |
958 | | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); } | |
959 | ; | |
960 | /* }}} */ | |
961 | /* 11.8 Relational Operators {{{ */ | |
962 | RelationalExpressionNoIn_ | |
963 | : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); } | |
964 | | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); } | |
965 | | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); } | |
966 | | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); } | |
967 | | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); } | |
968 | ; | |
969 | ||
970 | RelationalExpression_ | |
971 | : RelationalExpressionNoIn_ { $$ = $1; } | |
972 | | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); } | |
973 | ; | |
974 | ||
975 | RelationalExpression | |
976 | : ShiftExpression { $$ = $1; } | |
977 | | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } | |
978 | ; | |
979 | ||
980 | RelationalExpressionNoIn | |
981 | : ShiftExpression { $$ = $1; } | |
982 | | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; } | |
983 | ; | |
984 | ||
985 | RelationalExpressionNoBF | |
986 | : ShiftExpressionNoBF { $$ = $1; } | |
987 | | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; } | |
988 | ; | |
989 | /* }}} */ | |
990 | /* 11.9 Equality Operators {{{ */ | |
991 | EqualityExpression | |
992 | : RelationalExpression { $$ = $1; } | |
993 | | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); } | |
994 | | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); } | |
995 | | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } | |
996 | | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } | |
997 | ; | |
998 | ||
999 | EqualityExpressionNoIn | |
1000 | : RelationalExpressionNoIn { $$ = $1; } | |
1001 | | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); } | |
1002 | | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); } | |
1003 | | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); } | |
1004 | | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); } | |
1005 | ; | |
1006 | ||
1007 | EqualityExpressionNoBF | |
1008 | : RelationalExpressionNoBF { $$ = $1; } | |
1009 | | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); } | |
1010 | | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); } | |
1011 | | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } | |
1012 | | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } | |
1013 | ; | |
1014 | /* }}} */ | |
1015 | /* 11.10 Binary Bitwise Operators {{{ */ | |
1016 | BitwiseANDExpression | |
1017 | : EqualityExpression { $$ = $1; } | |
1018 | | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } | |
1019 | ; | |
1020 | ||
1021 | BitwiseANDExpressionNoIn | |
1022 | : EqualityExpressionNoIn { $$ = $1; } | |
1023 | | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } | |
1024 | ; | |
1025 | ||
1026 | BitwiseANDExpressionNoBF | |
1027 | : EqualityExpressionNoBF { $$ = $1; } | |
1028 | | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } | |
1029 | ; | |
1030 | ||
1031 | BitwiseXORExpression | |
1032 | : BitwiseANDExpression { $$ = $1; } | |
1033 | | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } | |
1034 | ; | |
1035 | ||
1036 | BitwiseXORExpressionNoIn | |
1037 | : BitwiseANDExpressionNoIn { $$ = $1; } | |
1038 | | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } | |
1039 | ; | |
1040 | ||
1041 | BitwiseXORExpressionNoBF | |
1042 | : BitwiseANDExpressionNoBF { $$ = $1; } | |
1043 | | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } | |
1044 | ; | |
1045 | ||
1046 | BitwiseORExpression | |
1047 | : BitwiseXORExpression { $$ = $1; } | |
1048 | | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } | |
1049 | ; | |
1050 | ||
1051 | BitwiseORExpressionNoIn | |
1052 | : BitwiseXORExpressionNoIn { $$ = $1; } | |
1053 | | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } | |
1054 | ; | |
1055 | ||
1056 | BitwiseORExpressionNoBF | |
1057 | : BitwiseXORExpressionNoBF { $$ = $1; } | |
1058 | | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } | |
1059 | ; | |
1060 | /* }}} */ | |
1061 | /* 11.11 Binary Logical Operators {{{ */ | |
1062 | LogicalANDExpression | |
1063 | : BitwiseORExpression { $$ = $1; } | |
1064 | | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } | |
1065 | ; | |
1066 | ||
1067 | LogicalANDExpressionNoIn | |
1068 | : BitwiseORExpressionNoIn { $$ = $1; } | |
1069 | | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } | |
1070 | ; | |
1071 | ||
1072 | LogicalANDExpressionNoBF | |
1073 | : BitwiseORExpressionNoBF { $$ = $1; } | |
1074 | | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } | |
1075 | ; | |
1076 | ||
1077 | LogicalORExpression | |
1078 | : LogicalANDExpression { $$ = $1; } | |
1079 | | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } | |
1080 | ; | |
1081 | ||
1082 | LogicalORExpressionNoIn | |
1083 | : LogicalANDExpressionNoIn { $$ = $1; } | |
1084 | | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); } | |
1085 | ; | |
1086 | ||
1087 | LogicalORExpressionNoBF | |
1088 | : LogicalANDExpressionNoBF { $$ = $1; } | |
1089 | | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } | |
1090 | ; | |
1091 | /* }}} */ | |
1092 | /* 11.12 Conditional Operator ( ? : ) {{{ */ | |
1093 | ConditionalExpression | |
1094 | : LogicalORExpression { $$ = $1; } | |
1095 | | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); } | |
1096 | ; | |
1097 | ||
1098 | ConditionalExpressionNoIn | |
1099 | : LogicalORExpressionNoIn { $$ = $1; } | |
1100 | | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); } | |
1101 | ; | |
1102 | ||
1103 | ConditionalExpressionNoBF | |
1104 | : LogicalORExpressionNoBF { $$ = $1; } | |
1105 | | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); } | |
1106 | ; | |
1107 | /* }}} */ | |
1108 | /* 11.13 Assignment Operators {{{ */ | |
1109 | AssignmentExpression_ | |
1110 | : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); } | |
1111 | | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); } | |
1112 | | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); } | |
1113 | | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); } | |
1114 | | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); } | |
1115 | | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); } | |
1116 | | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); } | |
1117 | | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); } | |
1118 | | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); } | |
1119 | | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); } | |
1120 | | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); } | |
1121 | | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); } | |
1122 | ; | |
1123 | ||
1124 | AssigneeExpression | |
1125 | : LeftHandSideExpression { $$ = $1; } | |
1126 | | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } | |
1127 | ; | |
1128 | ||
1129 | AssigneeExpressionNoBF | |
1130 | : LeftHandSideExpressionNoBF { $$ = $1; } | |
1131 | | UnaryAssigneeExpression { $$ = $1; } | |
1132 | ; | |
1133 | ||
1134 | AssigneeExpressionNoRE | |
1135 | : LeftHandSideExpressionNoRE { $$ = $1; } | |
1136 | | UnaryAssigneeExpression { $$ = $1; } | |
1137 | ; | |
1138 | ||
1139 | AssignmentExpression | |
1140 | : ConditionalExpression { $$ = $1; } | |
1141 | | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } | |
1142 | ; | |
1143 | ||
1144 | AssignmentExpressionNoIn | |
1145 | : ConditionalExpressionNoIn { $$ = $1; } | |
1146 | | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); } | |
1147 | | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); } | |
1148 | | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); } | |
1149 | | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); } | |
1150 | | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); } | |
1151 | | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); } | |
1152 | | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); } | |
1153 | | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); } | |
1154 | | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); } | |
1155 | | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); } | |
1156 | | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); } | |
1157 | | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); } | |
1158 | ; | |
1159 | ||
1160 | AssignmentExpressionNoBF | |
1161 | : ConditionalExpressionNoBF { $$ = $1; } | |
1162 | | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } | |
1163 | ; | |
1164 | /* }}} */ | |
1165 | /* 11.14 Comma Operator {{{ */ | |
1166 | Expression_ | |
1167 | : "," Expression { $$ = new(driver.pool_) CYCompound($2); } | |
1168 | | { $$ = NULL; } | |
1169 | ; | |
1170 | ||
1171 | ExpressionNoIn_ | |
1172 | : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); } | |
1173 | | { $$ = NULL; } | |
1174 | ; | |
1175 | ||
1176 | ExpressionOpt | |
1177 | : Expression { $$ = $1; } | |
1178 | | LexSetRegExp { $$ = NULL; } | |
1179 | ; | |
1180 | ||
1181 | ExpressionNoInOpt | |
1182 | : ExpressionNoIn { $$ = $1; } | |
1183 | | LexSetRegExp { $$ = NULL; } | |
1184 | ; | |
1185 | ||
1186 | Expression | |
1187 | : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } | |
1188 | ; | |
1189 | ||
1190 | ExpressionNoIn | |
1191 | : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } | |
1192 | ; | |
1193 | ||
1194 | ExpressionNoBF | |
1195 | : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } | |
1196 | ; | |
1197 | /* }}} */ | |
1198 | ||
1199 | /* 12 Statements {{{ */ | |
1200 | Statement_ | |
1201 | : Block { $$ = $1; } | |
1202 | | VariableStatement { $$ = $1; } | |
1203 | | EmptyStatement { $$ = $1; } | |
1204 | | ExpressionStatement { $$ = $1; } | |
1205 | | IfStatement { $$ = $1; } | |
1206 | | IterationStatement { $$ = $1; } | |
1207 | | ContinueStatement { $$ = $1; } | |
1208 | | BreakStatement { $$ = $1; } | |
1209 | | ReturnStatement { $$ = $1; } | |
1210 | | WithStatement { $$ = $1; } | |
1211 | | LabelledStatement { $$ = $1; } | |
1212 | | SwitchStatement { $$ = $1; } | |
1213 | | ThrowStatement { $$ = $1; } | |
1214 | | TryStatement { $$ = $1; } | |
1215 | ; | |
1216 | ||
1217 | Statement | |
1218 | : LexSetRegExp Statement_ { $$ = $2; } | |
1219 | ; | |
1220 | /* }}} */ | |
1221 | /* 12.1 Block {{{ */ | |
1222 | Block_ | |
1223 | : "{" StatementListOpt "}" { $$ = $2; } | |
1224 | ; | |
1225 | ||
1226 | Block | |
1227 | : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); } | |
1228 | ; | |
1229 | ||
1230 | StatementList | |
1231 | : Statement StatementListOpt { $1->SetNext($2); $$ = $1; } | |
1232 | ; | |
1233 | ||
1234 | StatementListOpt | |
1235 | : StatementList { $$ = $1; } | |
1236 | | LexSetRegExp { $$ = NULL; } | |
1237 | ; | |
1238 | /* }}} */ | |
1239 | /* 12.2 Variable Statement {{{ */ | |
1240 | VariableStatement | |
1241 | : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); } | |
1242 | ; | |
1243 | ||
1244 | VariableDeclarationList_ | |
1245 | : "," VariableDeclarationList { $$ = $2; } | |
1246 | | { $$ = NULL; } | |
1247 | ; | |
1248 | ||
1249 | VariableDeclarationListNoIn_ | |
1250 | : "," VariableDeclarationListNoIn { $$ = $2; } | |
1251 | | { $$ = NULL; } | |
1252 | ; | |
1253 | ||
1254 | VariableDeclarationList | |
1255 | : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); } | |
1256 | ; | |
1257 | ||
1258 | VariableDeclarationListNoIn | |
1259 | : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); } | |
1260 | ; | |
1261 | ||
1262 | VariableDeclaration | |
1263 | : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); } | |
1264 | ; | |
1265 | ||
1266 | VariableDeclarationNoIn | |
1267 | : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); } | |
1268 | ; | |
1269 | ||
1270 | InitialiserOpt | |
1271 | : Initialiser { $$ = $1; } | |
1272 | | { $$ = NULL; } | |
1273 | ; | |
1274 | ||
1275 | InitialiserNoInOpt | |
1276 | : InitialiserNoIn { $$ = $1; } | |
1277 | | { $$ = NULL; } | |
1278 | ; | |
1279 | ||
1280 | Initialiser | |
1281 | : "=" AssignmentExpression { $$ = $2; } | |
1282 | ; | |
1283 | ||
1284 | InitialiserNoIn | |
1285 | : "=" AssignmentExpressionNoIn { $$ = $2; } | |
1286 | ; | |
1287 | /* }}} */ | |
1288 | /* 12.3 Empty Statement {{{ */ | |
1289 | EmptyStatement | |
1290 | : ";" { $$ = new(driver.pool_) CYEmpty(); } | |
1291 | ; | |
1292 | /* }}} */ | |
1293 | /* 12.4 Expression Statement {{{ */ | |
1294 | ExpressionStatement | |
1295 | : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); } | |
1296 | ; | |
1297 | /* }}} */ | |
1298 | /* 12.5 The if Statement {{{ */ | |
1299 | ElseStatementOpt | |
1300 | : "else" Statement { $$ = $2; } | |
1301 | | %prec "if" { $$ = NULL; } | |
1302 | ; | |
1303 | ||
1304 | IfStatement | |
1305 | : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); } | |
1306 | ; | |
1307 | /* }}} */ | |
1308 | ||
1309 | /* 12.6 Iteration Statements {{{ */ | |
1310 | IterationStatement | |
1311 | : DoWhileStatement { $$ = $1; } | |
1312 | | WhileStatement { $$ = $1; } | |
1313 | | ForStatement { $$ = $1; } | |
1314 | | ForInStatement { $$ = $1; } | |
1315 | ; | |
1316 | /* }}} */ | |
1317 | /* 12.6.1 The do-while Statement {{{ */ | |
1318 | DoWhileStatement | |
1319 | : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); } | |
1320 | ; | |
1321 | /* }}} */ | |
1322 | /* 12.6.2 The while Statement {{{ */ | |
1323 | WhileStatement | |
1324 | : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); } | |
1325 | ; | |
1326 | /* }}} */ | |
1327 | /* 12.6.3 The for Statement {{{ */ | |
1328 | ForStatement | |
1329 | : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); } | |
1330 | ; | |
1331 | ||
1332 | ForStatementInitialiser | |
1333 | : ExpressionNoInOpt { $$ = $1; } | |
1334 | | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = $3; } | |
1335 | ; | |
1336 | /* }}} */ | |
1337 | /* 12.6.4 The for-in Statement {{{ */ | |
1338 | ForInStatement | |
1339 | : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); } | |
1340 | ; | |
1341 | ||
1342 | ForInStatementInitialiser | |
1343 | : LeftHandSideExpression { $$ = $1; } | |
1344 | | LexSetRegExp "var" VariableDeclarationNoIn { $$ = $3; } | |
1345 | ; | |
1346 | /* }}} */ | |
1347 | ||
1348 | /* 12.7 The continue Statement {{{ */ | |
1349 | ContinueStatement | |
1350 | : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); } | |
1351 | ; | |
1352 | /* }}} */ | |
1353 | /* 12.8 The break Statement {{{ */ | |
1354 | BreakStatement | |
1355 | : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); } | |
1356 | ; | |
1357 | /* }}} */ | |
1358 | /* 12.9 The return Statement {{{ */ | |
1359 | ReturnStatement | |
1360 | : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); } | |
1361 | ; | |
1362 | /* }}} */ | |
1363 | /* 12.10 The with Statement {{{ */ | |
1364 | WithStatement | |
1365 | : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); } | |
1366 | ; | |
1367 | /* }}} */ | |
1368 | ||
1369 | /* 12.11 The switch Statement {{{ */ | |
1370 | SwitchStatement | |
1371 | : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); } | |
1372 | ; | |
1373 | ||
1374 | CaseBlock | |
1375 | : "{" CaseClausesOpt "}" { $$ = $2; } | |
1376 | ; | |
1377 | ||
1378 | CaseClausesOpt | |
1379 | : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | |
1380 | | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | |
1381 | | { $$ = NULL; } | |
1382 | ; | |
1383 | ||
1384 | CaseClause | |
1385 | : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); } | |
1386 | ; | |
1387 | ||
1388 | DefaultClause | |
1389 | : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); } | |
1390 | ; | |
1391 | /* }}} */ | |
1392 | /* 12.12 Labelled Statements {{{ */ | |
1393 | LabelledStatement | |
1394 | : Identifier ":" Statement { $$ = new(driver.pool_) CYLabel($1, $3); } | |
1395 | ; | |
1396 | /* }}} */ | |
1397 | /* 12.13 The throw Statement {{{ */ | |
1398 | ThrowStatement | |
1399 | : "throw" Expression Terminator { $$ = new(driver.pool_) cy::Syntax::Throw($2); } | |
1400 | ; | |
1401 | /* }}} */ | |
1402 | /* 12.14 The try Statement {{{ */ | |
1403 | TryStatement | |
1404 | : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) cy::Syntax::Try($2, $3, $4); } | |
1405 | ; | |
1406 | ||
1407 | CatchOpt | |
1408 | : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) cy::Syntax::Catch($3, $5); } | |
1409 | | { $$ = NULL; } | |
1410 | ; | |
1411 | ||
1412 | FinallyOpt | |
1413 | : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); } | |
1414 | | { $$ = NULL; } | |
1415 | ; | |
1416 | /* }}} */ | |
1417 | ||
1418 | /* 13 Function Definition {{{ */ | |
1419 | FunctionDeclaration | |
1420 | : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); } | |
1421 | ; | |
1422 | ||
1423 | FunctionExpression | |
1424 | : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } | |
1425 | ; | |
1426 | ||
1427 | FormalParameterList_ | |
1428 | : "," FormalParameterList { $$ = $2; } | |
1429 | | { $$ = NULL; } | |
1430 | ; | |
1431 | ||
1432 | FormalParameterList | |
1433 | : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); } | |
1434 | | { $$ = NULL; } | |
1435 | ; | |
1436 | ||
1437 | FunctionBody | |
1438 | : SourceElements { $$ = $1; } | |
1439 | ; | |
1440 | /* }}} */ | |
1441 | /* 14 Program {{{ */ | |
1442 | Program | |
1443 | : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); } | |
1444 | ; | |
1445 | ||
1446 | SourceElements | |
1447 | : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } | |
1448 | | LexSetRegExp { $$ = NULL; } | |
1449 | ; | |
1450 | ||
1451 | SourceElement_ | |
1452 | : Statement_ { $$ = $1; } | |
1453 | | FunctionDeclaration { $$ = $1; } | |
1454 | ; | |
1455 | ||
1456 | SourceElement | |
1457 | : LexSetRegExp SourceElement_ { $$ = $2; } | |
1458 | ; | |
1459 | /* }}} */ | |
1460 | ||
1461 | @begin ObjectiveC | |
1462 | /* Cycript (Objective-C): @class Declaration {{{ */ | |
1463 | ClassSuperOpt | |
1464 | /* XXX: why the hell did I choose MemberExpressionNoBF? */ | |
1465 | : ":" LexSetRegExp MemberExpressionNoBF { $$ = $3; } | |
1466 | | { $$ = NULL; } | |
1467 | ; | |
1468 | ||
1469 | ClassFieldList | |
1470 | : "{" "}" { $$ = NULL; } | |
1471 | ; | |
1472 | ||
1473 | MessageScope | |
1474 | : "+" { $$ = false; } | |
1475 | | "-" { $$ = true; } | |
1476 | ; | |
1477 | ||
1478 | TypeOpt | |
1479 | : "(" Expression ")" { $$ = $2; } | |
1480 | | { $$ = NULL; } | |
1481 | ; | |
1482 | ||
1483 | MessageParameter | |
1484 | : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); } | |
1485 | ; | |
1486 | ||
1487 | MessageParameterListOpt | |
1488 | : MessageParameterList { $$ = $1; } | |
1489 | | { $$ = NULL; } | |
1490 | ; | |
1491 | ||
1492 | MessageParameterList | |
1493 | : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; } | |
1494 | ; | |
1495 | ||
1496 | MessageParameters | |
1497 | : MessageParameterList { $$ = $1; } | |
1498 | | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); } | |
1499 | ; | |
1500 | ||
1501 | ClassMessageDeclaration | |
1502 | : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); } | |
1503 | ; | |
1504 | ||
1505 | ClassMessageDeclarationListOpt | |
1506 | : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; } | |
1507 | | { $$ = NULL; } | |
1508 | ; | |
1509 | ||
1510 | ClassName | |
1511 | : Identifier { $$ = $1; } | |
1512 | | "(" AssignmentExpression ")" { $$ = $2; } | |
1513 | ; | |
1514 | ||
1515 | ClassNameOpt | |
1516 | : ClassName { $$ = $1; } | |
1517 | | { $$ = NULL; } | |
1518 | ; | |
1519 | ||
1520 | ClassExpression | |
1521 | : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); } | |
1522 | ; | |
1523 | ||
1524 | ClassStatement | |
1525 | : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); } | |
1526 | ; | |
1527 | ||
1528 | CategoryStatement | |
1529 | : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); } | |
1530 | ; | |
1531 | ||
1532 | PrimaryExpressionBF | |
1533 | : ClassExpression { $$ = $1; } | |
1534 | ; | |
1535 | ||
1536 | Statement_ | |
1537 | : ClassStatement { $$ = $1; } | |
1538 | | CategoryStatement { $$ = $1; } | |
1539 | ; | |
1540 | /* }}} */ | |
1541 | /* Cycript (Objective-C): Send Message {{{ */ | |
1542 | VariadicCall | |
1543 | : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); } | |
1544 | | { $$ = NULL; } | |
1545 | ; | |
1546 | ||
1547 | SelectorCall_ | |
1548 | : SelectorCall { $$ = $1; } | |
1549 | | VariadicCall { $$ = $1; } | |
1550 | ; | |
1551 | ||
1552 | SelectorCall | |
1553 | : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); } | |
1554 | ; | |
1555 | ||
1556 | SelectorList | |
1557 | : SelectorCall { $$ = $1; } | |
1558 | | Word { $$ = new(driver.pool_) CYArgument($1, NULL); } | |
1559 | ; | |
1560 | ||
1561 | MessageExpression | |
1562 | : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); } | |
1563 | | "[" LexSetRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); } | |
1564 | ; | |
1565 | ||
1566 | SelectorExpressionOpt | |
1567 | : SelectorExpression_ { $$ = $1; } | |
1568 | | { $$ = NULL; } | |
1569 | ; | |
1570 | ||
1571 | SelectorExpression_ | |
1572 | : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); } | |
1573 | ; | |
1574 | ||
1575 | SelectorExpression | |
1576 | : SelectorExpression_ { $$ = $1; } | |
1577 | | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } | |
1578 | ; | |
1579 | ||
1580 | PrimaryExpressionNo | |
1581 | : MessageExpression { $$ = $1; } | |
1582 | | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); } | |
1583 | ; | |
1584 | /* }}} */ | |
1585 | @end | |
1586 | ||
1587 | @begin C | |
1588 | /* Cycript (C): Pointer Indirection/Addressing {{{ */ | |
1589 | UnaryAssigneeExpression | |
1590 | : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); } | |
1591 | ; | |
1592 | ||
1593 | UnaryExpression_ | |
1594 | : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); } | |
1595 | ; | |
1596 | ||
1597 | MemberAccess | |
1598 | : "->" "[" Expression "]" { $$ = new(driver.pool_) CYIndirectMember(NULL, $3); } | |
1599 | | "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); } | |
1600 | ; | |
1601 | /* }}} */ | |
1602 | @end | |
1603 | ||
1604 | @begin E4X | |
1605 | /* Lexer State {{{ */ | |
1606 | LexPushRegExp | |
1607 | : { driver.PushCondition(CYDriver::RegExpCondition); } | |
1608 | ; | |
1609 | ||
1610 | LexPushXMLContent | |
1611 | : { driver.PushCondition(CYDriver::XMLContentCondition); } | |
1612 | ; | |
1613 | ||
1614 | LexPushXMLTag | |
1615 | : { driver.PushCondition(CYDriver::XMLTagCondition); } | |
1616 | ; | |
1617 | ||
1618 | LexPop | |
1619 | : { driver.PopCondition(); } | |
1620 | ; | |
1621 | ||
1622 | LexSetXMLContent | |
1623 | : { driver.SetCondition(CYDriver::XMLContentCondition); } | |
1624 | ; | |
1625 | ||
1626 | LexSetXMLTag | |
1627 | : { driver.SetCondition(CYDriver::XMLTagCondition); } | |
1628 | ; | |
1629 | /* }}} */ | |
1630 | ||
1631 | XMLWhitespaceOpt | |
1632 | : XMLWhitespace | |
1633 | | | |
1634 | ; | |
1635 | ||
1636 | /* 8.1 Context Keywords {{{ */ | |
1637 | Identifier | |
1638 | : "namespace" { $$ = $1; } | |
1639 | | "xml" { $$ = $1; } | |
1640 | ; | |
1641 | /* }}} */ | |
1642 | /* 8.3 XML Initialiser Input Elements {{{ */ | |
1643 | XMLMarkup | |
1644 | : XMLComment { $$ = $1; } | |
1645 | | XMLCDATA { $$ = $1; } | |
1646 | | XMLPI { $$ = $1; } | |
1647 | ; | |
1648 | /* }}} */ | |
1649 | /* 11.1 Primary Expressions {{{ */ | |
1650 | PrimaryExpressionNo | |
1651 | : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); } | |
1652 | | XMLInitialiser { $$ = $1; } | |
1653 | | XMLListInitialiser { $$ = $1; } | |
1654 | ; | |
1655 | ||
1656 | PropertyIdentifier | |
1657 | : AttributeIdentifier { $$ = $1; } | |
1658 | | QualifiedIdentifier { $$ = $1; } | |
1659 | | WildcardIdentifier { $$ = $1; } | |
1660 | ; | |
1661 | /* }}} */ | |
1662 | /* 11.1.1 Attribute Identifiers {{{ */ | |
1663 | AttributeIdentifier | |
1664 | : "@" QualifiedIdentifier_ { $$ = new(driver.pool_) CYAttribute($2); } | |
1665 | ; | |
1666 | ||
1667 | PropertySelector_ | |
1668 | : PropertySelector { $$ = $1; } | |
1669 | | "[" Expression "]" { $$ = new(driver.pool_) CYSelector($2); } | |
1670 | ; | |
1671 | ||
1672 | PropertySelector | |
1673 | : Identifier { $$ = new(driver.pool_) CYSelector($1); } | |
1674 | | WildcardIdentifier { $$ = $1; } | |
1675 | ; | |
1676 | /* }}} */ | |
1677 | /* 11.1.2 Qualified Identifiers {{{ */ | |
1678 | QualifiedIdentifier_ | |
1679 | : PropertySelector_ { $$ = new(driver.pool_) CYQualified(NULL, $1); } | |
1680 | | QualifiedIdentifier { $$ = $1; } | |
1681 | ; | |
1682 | ||
1683 | QualifiedIdentifier | |
1684 | : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQualified($1, $3); } | |
1685 | ; | |
1686 | /* }}} */ | |
1687 | /* 11.1.3 Wildcard Identifiers {{{ */ | |
1688 | WildcardIdentifier | |
1689 | : "*" { $$ = new(driver.pool_) CYWildcard(); } | |
1690 | ; | |
1691 | /* }}} */ | |
1692 | /* 11.1.4 XML Initialiser {{{ */ | |
1693 | XMLInitialiser | |
1694 | : XMLMarkup { $$ = $1; } | |
1695 | | XMLElement { $$ = $1; } | |
1696 | ; | |
1697 | ||
1698 | XMLElement | |
1699 | : "<" XMLTagContent "/>" LexPop | |
1700 | | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt ">" LexPop | |
1701 | ; | |
1702 | ||
1703 | XMLTagContent | |
1704 | : LexPushXMLTag XMLTagName XMLAttributes | |
1705 | ; | |
1706 | ||
1707 | XMLExpression | |
1708 | : "{" LexPushRegExp Expression "}" LexPop | |
1709 | ; | |
1710 | ||
1711 | XMLTagName | |
1712 | : XMLExpression | |
1713 | | XMLName | |
1714 | ; | |
1715 | ||
1716 | XMLAttributes_ | |
1717 | : XMLAttributes_ XMLAttribute | |
1718 | | | |
1719 | ; | |
1720 | ||
1721 | XMLAttributes | |
1722 | : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt | |
1723 | | XMLAttributes_ XMLWhitespaceOpt | |
1724 | ; | |
1725 | ||
1726 | XMLAttributeValue_ | |
1727 | : XMLExpression | |
1728 | | XMLAttributeValue | |
1729 | ; | |
1730 | ||
1731 | XMLAttribute | |
1732 | : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_ | |
1733 | ; | |
1734 | ||
1735 | XMLElementContent | |
1736 | : XMLExpression XMLElementContentOpt | |
1737 | | XMLMarkup XMLElementContentOpt | |
1738 | | XMLText XMLElementContentOpt | |
1739 | | XMLElement XMLElementContentOpt | |
1740 | ; | |
1741 | ||
1742 | XMLElementContentOpt | |
1743 | : XMLElementContent | |
1744 | | | |
1745 | ; | |
1746 | /* }}} */ | |
1747 | /* 11.1.5 XMLList Initialiser {{{ */ | |
1748 | XMLListInitialiser | |
1749 | : "<>" LexPushXMLContent XMLElementContent "</>" LexPop { $$ = new(driver.pool_) CYXMLList($3); } | |
1750 | ; | |
1751 | /* }}} */ | |
1752 | /* 11.2 Left-Hand-Side Expressions {{{ */ | |
1753 | PropertyIdentifier_ | |
1754 | : Identifier { $$ = $1; } | |
1755 | | PropertyIdentifier { $$ = $1; } | |
1756 | ; | |
1757 | ||
1758 | MemberAccess | |
1759 | : "." PropertyIdentifier { $$ = new(driver.pool_) CYPropertyMember(NULL, $2); } | |
1760 | | ".." PropertyIdentifier_ { $$ = new(driver.pool_) CYDescendantMember(NULL, $2); } | |
1761 | | "." "(" Expression ")" { $$ = new(driver.pool_) CYFilteringPredicate(NULL, $3); } | |
1762 | ; | |
1763 | /* }}} */ | |
1764 | /* 12.1 The default xml namespace Statement {{{ */ | |
1765 | /* XXX: DefaultXMLNamespaceStatement | |
1766 | : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); } | |
1767 | ; | |
1768 | ||
1769 | Statement_ | |
1770 | : DefaultXMLNamespaceStatement { $$ = $1; } | |
1771 | ; */ | |
1772 | /* }}} */ | |
1773 | @end | |
1774 | ||
1775 | /* ECMAScript5: Object Literal Trailing Comma {{{ */ | |
1776 | PropertyNameAndValueList_ | |
1777 | : "," { $$ = NULL; } | |
1778 | ; | |
1779 | /* }}} */ | |
1780 | /* JavaScript 1.7: Array Comprehensions {{{ */ | |
1781 | IfComprehension | |
1782 | : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); } | |
1783 | ; | |
1784 | ||
1785 | ForComprehension | |
1786 | : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); } | |
1787 | | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); } | |
1788 | ; | |
1789 | ||
1790 | ComprehensionListOpt | |
1791 | : ComprehensionList { $$ = $1; } | |
1792 | | IfComprehension { $$ = $1; } | |
1793 | | { $$ = NULL; } | |
1794 | ; | |
1795 | ||
1796 | ComprehensionList | |
1797 | : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } | |
1798 | ; | |
1799 | ||
1800 | PrimaryExpressionNo | |
1801 | : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); } | |
1802 | ; | |
1803 | /* }}} */ | |
1804 | /* JavaScript 1.7: for each {{{ */ | |
1805 | ForInStatement | |
1806 | : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); } | |
1807 | ; | |
1808 | /* }}} */ | |
1809 | /* JavaScript 1.7: let Statements {{{ *//* | |
1810 | LetStatement | |
1811 | : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); } | |
1812 | ; | |
1813 | ||
1814 | Statement_ | |
1815 | : LetStatement | |
1816 | ; | |
1817 | *//* }}} */ | |
1818 | /* JavaScript FTW: Function Statements {{{ */ | |
1819 | Statement | |
1820 | : LexSetRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; } | |
1821 | ; | |
1822 | /* }}} */ | |
1823 | ||
1824 | %% |