]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
b4aa79af JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
b4aa79af | 6 | /* |
f95d2598 JF |
7 | * This program is free software: you can redistribute it and/or modify |
8 | * it under the terms of the GNU Affero General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | ||
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c15969fd | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
15 | * GNU Affero General Public License for more details. |
16 | ||
17 | * You should have received a copy of the GNU Affero General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
b3378a02 | 19 | **/ |
b4aa79af JF |
20 | /* }}} */ |
21 | ||
6ce9ac92 | 22 | %code top { |
4e869640 | 23 | #define cyscanner driver.scanner_ |
693d501b | 24 | #define YYSTACKEXPANDABLE 1 |
6ce9ac92 | 25 | } |
1dbba6cc | 26 | |
6ce9ac92 | 27 | %code requires { |
b12a9965 | 28 | #include "Driver.hpp" |
63b4c5a8 | 29 | #include "Parser.hpp" |
ddeb1876 | 30 | #include "Stack.hpp" |
2c1d569a | 31 | #define CYNew new(driver.pool_) |
63b4c5a8 | 32 | |
cbaa5f0f | 33 | @begin ObjectiveC |
3c1c3635 | 34 | #include "ObjectiveC/Syntax.hpp" |
4de0686f JF |
35 | @end |
36 | ||
691e4717 | 37 | @begin E4X |
b92ceddb | 38 | #include "E4X/Syntax.hpp" |
691e4717 JF |
39 | @end |
40 | ||
82a02ede JF |
41 | #include "Highlight.hpp" |
42 | ||
c3c20102 JF |
43 | typedef struct { |
44 | bool newline_; | |
82a02ede | 45 | hi::Value highlight_; |
c3c20102 JF |
46 | |
47 | union { | |
b09da87b JF |
48 | bool bool_; |
49 | ||
63cd45c9 JF |
50 | CYDriver::Condition condition_; |
51 | ||
c3c20102 | 52 | CYArgument *argument_; |
0ff9f149 | 53 | CYAssignment *assignment_; |
c3c20102 JF |
54 | CYBoolean *boolean_; |
55 | CYClause *clause_; | |
37954781 | 56 | cy::Syntax::Catch *catch_; |
320ce753 | 57 | CYComment *comment_; |
75b0a457 | 58 | CYComprehension *comprehension_; |
c3c20102 JF |
59 | CYDeclaration *declaration_; |
60 | CYDeclarations *declarations_; | |
61 | CYElement *element_; | |
62 | CYExpression *expression_; | |
63 | CYFalse *false_; | |
b10bd496 | 64 | CYFinally *finally_; |
c3c20102 JF |
65 | CYForInitialiser *for_; |
66 | CYForInInitialiser *forin_; | |
b09da87b | 67 | CYFunctionParameter *functionParameter_; |
c3c20102 | 68 | CYIdentifier *identifier_; |
0ff9f149 | 69 | CYInfix *infix_; |
c3c20102 | 70 | CYLiteral *literal_; |
9b5527f0 | 71 | CYMember *member_; |
417dcc12 | 72 | CYModule *module_; |
c3c20102 JF |
73 | CYNull *null_; |
74 | CYNumber *number_; | |
b0385401 | 75 | CYParenthetical *parenthetical_; |
3b52fd1a | 76 | CYProgram *program_; |
c3c20102 | 77 | CYProperty *property_; |
e5bc40db | 78 | CYPropertyName *propertyName_; |
6c093cce | 79 | CYRubyProc *rubyProc_; |
c3c20102 JF |
80 | CYStatement *statement_; |
81 | CYString *string_; | |
82 | CYThis *this_; | |
83 | CYTrue *true_; | |
84 | CYWord *word_; | |
4de0686f | 85 | |
7b750785 JF |
86 | @begin C |
87 | CYTypeModifier *modifier_; | |
88 | CYTypeSpecifier *specifier_; | |
89 | CYTypedIdentifier *typedIdentifier_; | |
90 | CYTypedParameter *typedParameter_; | |
91 | @end | |
92 | ||
cbaa5f0f | 93 | @begin ObjectiveC |
328ad766 | 94 | CYClassName *className_; |
b6a67580 | 95 | CYClassField *classField_; |
4de0686f JF |
96 | CYMessage *message_; |
97 | CYMessageParameter *messageParameter_; | |
cee5e1fd | 98 | CYProtocol *protocol_; |
4de0686f JF |
99 | CYSelectorPart *selector_; |
100 | @end | |
691e4717 JF |
101 | |
102 | @begin E4X | |
103 | CYAttribute *attribute_; | |
b92ceddb JF |
104 | CYPropertyIdentifier *propertyIdentifier_; |
105 | CYSelector *selector_; | |
691e4717 | 106 | @end |
c3c20102 JF |
107 | }; |
108 | } YYSTYPE; | |
109 | ||
4e869640 | 110 | #define YYSTYPE YYSTYPE |
6ce9ac92 | 111 | } |
63b4c5a8 | 112 | |
6ce9ac92 | 113 | %code provides { |
58afc6aa | 114 | int cylex(YYSTYPE *, CYLocation *, void *); |
6ce9ac92 | 115 | } |
c5aeb567 | 116 | |
6ce9ac92 | 117 | %name-prefix "cy" |
e5332278 | 118 | |
6ce9ac92 | 119 | %language "C++" |
1dbba6cc | 120 | |
5999c315 JF |
121 | %initial-action { |
122 | @$.begin.filename = @$.end.filename = &driver.filename_; | |
123 | }; | |
124 | ||
be36c292 | 125 | %locations |
e5332278 | 126 | %defines |
1dbba6cc | 127 | |
58afc6aa JF |
128 | %define api.location.type { CYLocation } |
129 | ||
534fb6da JF |
130 | //%glr-parser |
131 | //%expect 1 | |
cac61857 | 132 | |
e5332278 JF |
133 | %error-verbose |
134 | ||
5999c315 | 135 | %parse-param { CYDriver &driver } |
4e869640 | 136 | %lex-param { void *cyscanner } |
e5332278 | 137 | |
c3b144b8 | 138 | /* Token Declarations {{{ */ |
cb02f8ae | 139 | @begin E4X |
cb02f8ae JF |
140 | %token XMLCDATA |
141 | %token XMLComment | |
142 | %token XMLPI | |
691e4717 JF |
143 | |
144 | %token XMLAttributeValue | |
145 | %token XMLName | |
146 | %token XMLTagCharacters | |
147 | %token XMLText | |
148 | %token XMLWhitespace | |
149 | @end | |
150 | ||
151 | @begin E4X | |
152 | %token LeftRight "<>" | |
153 | %token LeftSlashRight "</>" | |
154 | ||
155 | %token SlashRight "/>" | |
156 | %token LeftSlash "</" | |
157 | ||
691e4717 JF |
158 | %token ColonColon "::" |
159 | %token PeriodPeriod ".." | |
cb02f8ae | 160 | @end |
ac9a5ce1 | 161 | |
b1589845 JF |
162 | @begin E4X ObjectiveC |
163 | %token At "@" | |
ac9d4181 | 164 | %token Pound "#" |
b1589845 JF |
165 | @end |
166 | ||
63b4c5a8 JF |
167 | %token Ampersand "&" |
168 | %token AmpersandAmpersand "&&" | |
169 | %token AmpersandEqual "&=" | |
170 | %token Carrot "^" | |
171 | %token CarrotEqual "^=" | |
172 | %token Equal "=" | |
173 | %token EqualEqual "==" | |
174 | %token EqualEqualEqual "===" | |
4b2fd91c | 175 | %token EqualRight "=>" |
6265f0de | 176 | %token EqualRight_ "\n=>" |
63b4c5a8 JF |
177 | %token Exclamation "!" |
178 | %token ExclamationEqual "!=" | |
179 | %token ExclamationEqualEqual "!==" | |
180 | %token Hyphen "-" | |
181 | %token HyphenEqual "-=" | |
182 | %token HyphenHyphen "--" | |
c3c20102 | 183 | %token HyphenHyphen_ "\n--" |
63b4c5a8 JF |
184 | %token HyphenRight "->" |
185 | %token Left "<" | |
186 | %token LeftEqual "<=" | |
187 | %token LeftLeft "<<" | |
188 | %token LeftLeftEqual "<<=" | |
189 | %token Percent "%" | |
190 | %token PercentEqual "%=" | |
191 | %token Period "." | |
c8a0500b | 192 | %token PeriodPeriodPeriod "..." |
63b4c5a8 JF |
193 | %token Pipe "|" |
194 | %token PipeEqual "|=" | |
195 | %token PipePipe "||" | |
196 | %token Plus "+" | |
197 | %token PlusEqual "+=" | |
198 | %token PlusPlus "++" | |
c3c20102 | 199 | %token PlusPlus_ "\n++" |
63b4c5a8 JF |
200 | %token Right ">" |
201 | %token RightEqual ">=" | |
202 | %token RightRight ">>" | |
203 | %token RightRightEqual ">>=" | |
204 | %token RightRightRight ">>>" | |
205 | %token RightRightRightEqual ">>>=" | |
206 | %token Slash "/" | |
207 | %token SlashEqual "/=" | |
208 | %token Star "*" | |
209 | %token StarEqual "*=" | |
210 | %token Tilde "~" | |
211 | ||
212 | %token Colon ":" | |
213 | %token Comma "," | |
214 | %token Question "?" | |
215 | %token SemiColon ";" | |
c3c20102 | 216 | %token NewLine "\n" |
63b4c5a8 | 217 | |
320ce753 JF |
218 | %token <comment_> Comment |
219 | ||
63b4c5a8 JF |
220 | %token OpenParen "(" |
221 | %token CloseParen ")" | |
924f67b2 | 222 | |
63b4c5a8 | 223 | %token OpenBrace "{" |
6c093cce | 224 | %token OpenBrace_ "\n{" |
3ea7eed0 | 225 | %token OpenBrace__ ";{" |
63b4c5a8 | 226 | %token CloseBrace "}" |
924f67b2 | 227 | |
63b4c5a8 JF |
228 | %token OpenBracket "[" |
229 | %token CloseBracket "]" | |
230 | ||
dc5d7cf4 JF |
231 | %token AtError "@error" |
232 | ||
1ba6903e | 233 | @begin Java |
b09da87b | 234 | %token AtClass "@class" |
1ba6903e JF |
235 | @end |
236 | ||
60097023 JF |
237 | @begin C |
238 | %token <identifier_> Typedef "typedef" | |
3fe283c5 JF |
239 | %token <identifier_> Unsigned "unsigned" |
240 | %token <identifier_> Signed "signed" | |
c5587ed7 | 241 | %token <identifier_> Extern "extern" |
60097023 JF |
242 | @end |
243 | ||
8a2eb1be JF |
244 | @begin C |
245 | %token AtEncode "@encode" | |
246 | @end | |
247 | ||
1ba6903e JF |
248 | @begin ObjectiveC |
249 | %token AtImplementation "@implementation" | |
3ea7eed0 | 250 | %token AtImplementation_ ";@implementation" |
1ba6903e | 251 | %token AtImport "@import" |
d35a3b07 | 252 | %token AtEnd "@end" |
1ba6903e | 253 | %token AtSelector "@selector" |
4ea461c0 JF |
254 | %token AtNull "@null" |
255 | %token AtYes "@YES" | |
256 | %token AtNo "@NO" | |
257 | %token AtTrue "@true" | |
258 | %token AtFalse "@false" | |
60496dd5 JF |
259 | %token <identifier_> Yes "YES" |
260 | %token <identifier_> No "NO" | |
1ba6903e | 261 | @end |
e7ed5354 | 262 | |
534fb6da JF |
263 | %token <false_> False "false" |
264 | %token <null_> Null "null" | |
265 | %token <true_> True "true" | |
266 | ||
267 | // ES3/ES5/WIE/JSC Reserved | |
a87d7060 | 268 | %token <word_> Auto "auto" |
cf7d4c69 JF |
269 | %token <word_> Break "break" |
270 | %token <word_> Case "case" | |
271 | %token <word_> Catch "catch" | |
272 | %token <word_> Continue "continue" | |
273 | %token <word_> Default "default" | |
274 | %token <word_> Delete "delete" | |
275 | %token <word_> Do "do" | |
276 | %token <word_> Else "else" | |
cf7d4c69 JF |
277 | %token <word_> Finally "finally" |
278 | %token <word_> For "for" | |
279 | %token <word_> Function "function" | |
3ea7eed0 | 280 | %token <word_> Function_ ";function" |
cf7d4c69 JF |
281 | %token <word_> If "if" |
282 | %token <word_> In "in" | |
3ea7eed0 | 283 | %token <word_> In_ "!in" |
cf7d4c69 JF |
284 | %token <word_> InstanceOf "instanceof" |
285 | %token <word_> New "new" | |
cf7d4c69 JF |
286 | %token <word_> Return "return" |
287 | %token <word_> Switch "switch" | |
288 | %token <this_> This "this" | |
289 | %token <word_> Throw "throw" | |
cf7d4c69 JF |
290 | %token <word_> Try "try" |
291 | %token <word_> TypeOf "typeof" | |
292 | %token <word_> Var "var" | |
293 | %token <word_> Void "void" | |
294 | %token <word_> While "while" | |
295 | %token <word_> With "with" | |
63b4c5a8 | 296 | |
534fb6da | 297 | // ES3/IE6 Future, ES5/JSC Reserved |
d35a3b07 | 298 | %token <word_> Debugger "debugger" |
534fb6da JF |
299 | |
300 | // ES3/ES5/IE6 Future, JSC Reserved | |
301 | %token <word_> Const "const" | |
302 | ||
303 | // ES3/ES5/IE6/JSC Future | |
304 | %token <word_> Class "class" | |
d35a3b07 JF |
305 | %token <word_> Enum "enum" |
306 | %token <word_> Export "export" | |
307 | %token <word_> Extends "extends" | |
d35a3b07 | 308 | %token <word_> Import "import" |
d35a3b07 | 309 | %token <word_> Super "super" |
d35a3b07 | 310 | |
534fb6da JF |
311 | // ES3 Future, ES5 Strict Future |
312 | %token <identifier_> Implements "implements" | |
313 | %token <identifier_> Interface "interface" | |
314 | %token <identifier_> Package "package" | |
315 | %token <identifier_> Private "private" | |
316 | %token <identifier_> Protected "protected" | |
317 | %token <identifier_> Public "public" | |
318 | %token <identifier_> Static "static" | |
319 | ||
320 | // ES3 Future | |
321 | %token <identifier_> Abstract "abstract" | |
322 | %token <identifier_> Boolean "boolean" | |
323 | %token <identifier_> Byte "byte" | |
324 | %token <identifier_> Char "char" | |
325 | %token <identifier_> Double "double" | |
326 | %token <identifier_> Final "final" | |
327 | %token <identifier_> Float "float" | |
328 | %token <identifier_> Goto "goto" | |
329 | %token <identifier_> Int "int" | |
330 | %token <identifier_> Long "long" | |
331 | %token <identifier_> Native "native" | |
332 | %token <identifier_> Short "short" | |
333 | %token <identifier_> Synchronized "synchronized" | |
334 | %token <identifier_> Throws "throws" | |
335 | %token <identifier_> Transient "transient" | |
336 | %token <identifier_> Volatile "volatile" | |
337 | ||
338 | // ES5 Strict | |
cac61857 | 339 | %token <identifier_> Let "let" |
534fb6da JF |
340 | %token <identifier_> Yield "yield" |
341 | ||
342 | // Woah?! | |
343 | %token <identifier_> Each "each" | |
480c8834 | 344 | %token <identifier_> Of "of" |
75b0a457 | 345 | |
691e4717 JF |
346 | @begin E4X |
347 | // E4X Conditional | |
348 | %token <identifier_> Namespace "namespace" | |
349 | %token <identifier_> XML "xml" | |
350 | @end | |
351 | ||
7e5391fd JF |
352 | %token AutoComplete |
353 | ||
75b0a457 | 354 | %token <identifier_> Identifier_ |
63b4c5a8 JF |
355 | %token <number_> NumericLiteral |
356 | %token <string_> StringLiteral | |
63cd45c9 | 357 | %token <literal_> RegularExpressionLiteral |
1dbba6cc | 358 | |
cf7d4c69 | 359 | %type <expression_> AdditiveExpression |
cf7d4c69 | 360 | %type <argument_> ArgumentList_ |
55fc1817 | 361 | %type <argument_> ArgumentList |
cf7d4c69 JF |
362 | %type <argument_> ArgumentListOpt |
363 | %type <argument_> Arguments | |
b3aa25d8 JF |
364 | %type <expression_> ArrayComprehension |
365 | %type <expression_> ArrayInitialiser | |
cf7d4c69 | 366 | %type <literal_> ArrayLiteral |
4b2fd91c JF |
367 | %type <expression_> ArrowFunction |
368 | %type <functionParameter_> ArrowParameters | |
55fc1817 | 369 | %type <expression_> AssignmentExpression |
c2529502 | 370 | %type <identifier_> Binding |
c8a0500b | 371 | %type <identifier_> BindingIdentifier |
cf7d4c69 | 372 | %type <expression_> BitwiseANDExpression |
cac61857 | 373 | %type <statement_> Block_ |
55fc1817 | 374 | %type <statement_> Block |
cf7d4c69 | 375 | %type <boolean_> BooleanLiteral |
c8a0500b | 376 | %type <declaration_> BindingElement |
cf7d4c69 JF |
377 | %type <expression_> BitwiseORExpression |
378 | %type <expression_> BitwiseXORExpression | |
379 | %type <statement_> BreakStatement | |
c8a0500b | 380 | %type <statement_> BreakableStatement |
3ea7eed0 | 381 | %type <expression_> CallExpression_ |
cf7d4c69 JF |
382 | %type <expression_> CallExpression |
383 | %type <clause_> CaseBlock | |
384 | %type <clause_> CaseClause | |
385 | %type <clause_> CaseClausesOpt | |
386 | %type <catch_> CatchOpt | |
b3aa25d8 JF |
387 | %type <expression_> Comprehension |
388 | %type <comprehension_> ComprehensionFor | |
389 | %type <comprehension_> ComprehensionIf | |
390 | %type <comprehension_> ComprehensionTail | |
cf7d4c69 JF |
391 | %type <expression_> ConditionalExpression |
392 | %type <statement_> ContinueStatement | |
4b2fd91c | 393 | %type <statement_> ConciseBody |
c8a0500b | 394 | %type <statement_> DebuggerStatement |
3ea7eed0 JF |
395 | %type <statement_> Declaration__ |
396 | %type <statement_> Declaration_ | |
c8a0500b | 397 | %type <statement_> Declaration |
cf7d4c69 | 398 | %type <clause_> DefaultClause |
cf7d4c69 | 399 | %type <expression_> Element |
5befe15e | 400 | %type <expression_> ElementOpt |
cf7d4c69 | 401 | %type <element_> ElementList |
5befe15e | 402 | %type <element_> ElementListOpt |
cf7d4c69 JF |
403 | %type <statement_> ElseStatementOpt |
404 | %type <statement_> EmptyStatement | |
405 | %type <expression_> EqualityExpression | |
b0385401 | 406 | %type <expression_> Expression |
cf7d4c69 JF |
407 | %type <expression_> ExpressionOpt |
408 | %type <statement_> ExpressionStatement | |
b10bd496 | 409 | %type <finally_> FinallyOpt |
cf7d4c69 | 410 | %type <for_> ForStatementInitialiser |
cf7d4c69 | 411 | %type <forin_> ForInStatementInitialiser |
c8a0500b | 412 | %type <declaration_> FormalParameter |
b09da87b | 413 | %type <functionParameter_> FormalParameterList_ |
55fc1817 | 414 | %type <functionParameter_> FormalParameterList |
c8a0500b | 415 | %type <functionParameter_> FormalParameterListOpt |
b10bd496 JF |
416 | %type <statement_> FunctionBody |
417 | %type <statement_> FunctionDeclaration | |
cf7d4c69 | 418 | %type <expression_> FunctionExpression |
75b0a457 | 419 | %type <identifier_> Identifier |
cf7d4c69 | 420 | %type <identifier_> IdentifierOpt |
3fe283c5 | 421 | %type <identifier_> IdentifierType |
4492c19c | 422 | %type <word_> IdentifierName |
cf7d4c69 JF |
423 | %type <statement_> IfStatement |
424 | %type <expression_> Initialiser | |
425 | %type <expression_> InitialiserOpt | |
426 | %type <statement_> IterationStatement | |
427 | %type <statement_> LabelledStatement | |
428 | %type <expression_> LeftHandSideExpression | |
15b88a33 | 429 | %type <statement_> LetStatement |
c8a0500b | 430 | %type <statement_> LexicalDeclaration |
cf7d4c69 | 431 | %type <literal_> Literal |
c3b144b8 | 432 | %type <literal_> ValueLiteral |
cf7d4c69 JF |
433 | %type <expression_> LogicalANDExpression |
434 | %type <expression_> LogicalORExpression | |
9b5527f0 | 435 | %type <member_> MemberAccess |
693d501b | 436 | %type <expression_> MemberExpression_ |
55fc1817 | 437 | %type <expression_> MemberExpression |
7b750785 | 438 | %type <module_> Module |
cf7d4c69 | 439 | %type <expression_> MultiplicativeExpression |
55fc1817 | 440 | %type <expression_> NewExpression |
cf7d4c69 JF |
441 | %type <null_> NullLiteral |
442 | %type <literal_> ObjectLiteral | |
b0385401 | 443 | %type <parenthetical_> Parenthetical |
cf7d4c69 JF |
444 | %type <expression_> PostfixExpression |
445 | %type <expression_> PrimaryExpression | |
b10bd496 | 446 | %type <statement_> Program |
c8a0500b JF |
447 | %type <statement_> ProgramBody |
448 | %type <statement_> ProgramBodyOpt | |
b92ceddb | 449 | %type <propertyName_> PropertyName_ |
55fc1817 | 450 | %type <propertyName_> PropertyName |
aea76473 JF |
451 | %type <property_> PropertyDefinition |
452 | %type <property_> PropertyDefinitionList_ | |
453 | %type <property_> PropertyDefinitionList | |
454 | %type <property_> PropertyDefinitionListOpt | |
55fc1817 | 455 | %type <expression_> RelationalExpression |
cf7d4c69 | 456 | %type <statement_> ReturnStatement |
6c093cce | 457 | %type <rubyProc_> RubyProcExpression |
6c093cce | 458 | %type <functionParameter_> RubyProcParameterList_ |
55fc1817 | 459 | %type <functionParameter_> RubyProcParameterList |
d7205a63 | 460 | %type <functionParameter_> RubyProcParameters |
6c093cce | 461 | %type <functionParameter_> RubyProcParametersOpt |
cf7d4c69 | 462 | %type <expression_> ShiftExpression |
c8a0500b | 463 | %type <declaration_> SingleNameBinding |
3ea7eed0 | 464 | %type <statement_> Statement__ |
b10bd496 | 465 | %type <statement_> Statement_ |
55fc1817 | 466 | %type <statement_> Statement |
693d501b | 467 | %type <statement_> StatementList |
cf7d4c69 | 468 | %type <statement_> StatementListOpt |
c8a0500b | 469 | %type <statement_> StatementListItem |
cf7d4c69 JF |
470 | %type <statement_> SwitchStatement |
471 | %type <statement_> ThrowStatement | |
472 | %type <statement_> TryStatement | |
693d501b | 473 | %type <expression_> UnaryExpression_ |
55fc1817 | 474 | %type <expression_> UnaryExpression |
cf7d4c69 | 475 | %type <declaration_> VariableDeclaration |
cf7d4c69 | 476 | %type <declarations_> VariableDeclarationList_ |
55fc1817 | 477 | %type <declarations_> VariableDeclarationList |
cf7d4c69 | 478 | %type <statement_> VariableStatement |
cf7d4c69 | 479 | %type <statement_> WithStatement |
4492c19c | 480 | %type <word_> Word |
73f04979 | 481 | @begin ObjectiveC |
4492c19c | 482 | %type <word_> WordOpt |
73f04979 | 483 | @end |
46f4f308 | 484 | %type <expression_> Variable |
cf7d4c69 | 485 | |
7b750785 | 486 | @begin C |
7b750785 JF |
487 | %type <specifier_> IntegerType |
488 | %type <specifier_> IntegerTypeOpt | |
489 | %type <typedIdentifier_> PrefixedType | |
490 | %type <specifier_> PrimitiveType | |
7b750785 | 491 | %type <typedIdentifier_> SuffixedType |
00b4cb83 | 492 | %type <typedIdentifier_> TypeSignifier |
7b750785 JF |
493 | %type <modifier_> TypeQualifierLeft |
494 | %type <typedIdentifier_> TypeQualifierRight | |
495 | %type <typedIdentifier_> TypedIdentifier | |
496 | %type <typedParameter_> TypedParameterList_ | |
497 | %type <typedParameter_> TypedParameterList | |
498 | %type <typedParameter_> TypedParameterListOpt | |
499 | @end | |
500 | ||
501 | @begin ObjectiveC | |
c3b144b8 | 502 | %type <expression_> BoxableExpression |
328ad766 JF |
503 | %type <statement_> CategoryStatement |
504 | %type <expression_> ClassExpression | |
b6a67580 JF |
505 | %type <classField_> ClassFieldListOpt |
506 | %type <classField_> ClassFields | |
328ad766 JF |
507 | %type <statement_> ClassStatement |
508 | %type <expression_> ClassSuperOpt | |
328ad766 JF |
509 | %type <message_> ClassMessageDeclaration |
510 | %type <message_> ClassMessageDeclarationListOpt | |
511 | %type <className_> ClassName | |
512 | %type <className_> ClassNameOpt | |
64b8d29f JF |
513 | %type <protocol_> ClassProtocolListOpt |
514 | %type <protocol_> ClassProtocols | |
515 | %type <protocol_> ClassProtocolsOpt | |
693d501b | 516 | %type <expression_> MessageExpression |
328ad766 JF |
517 | %type <messageParameter_> MessageParameter |
518 | %type <messageParameter_> MessageParameters | |
519 | %type <messageParameter_> MessageParameterList | |
520 | %type <messageParameter_> MessageParameterListOpt | |
521 | %type <bool_> MessageScope | |
693d501b | 522 | %type <argument_> SelectorCall_ |
55fc1817 | 523 | %type <argument_> SelectorCall |
328ad766 | 524 | %type <selector_> SelectorExpression_ |
55fc1817 | 525 | %type <selector_> SelectorExpression |
328ad766 | 526 | %type <selector_> SelectorExpressionOpt |
693d501b | 527 | %type <argument_> SelectorList |
7e5391fd | 528 | %type <word_> SelectorWordOpt |
57d55714 | 529 | %type <typedIdentifier_> TypeOpt |
693d501b | 530 | %type <argument_> VariadicCall |
328ad766 | 531 | @end |
693d501b | 532 | |
691e4717 | 533 | @begin E4X |
b92ceddb | 534 | %type <propertyIdentifier_> PropertyIdentifier_ |
b92ceddb | 535 | %type <selector_> PropertySelector_ |
55fc1817 | 536 | %type <selector_> PropertySelector |
691e4717 | 537 | %type <identifier_> QualifiedIdentifier_ |
55fc1817 | 538 | %type <identifier_> QualifiedIdentifier |
691e4717 JF |
539 | %type <identifier_> WildcardIdentifier |
540 | %type <identifier_> XMLComment | |
541 | %type <identifier_> XMLCDATA | |
542 | %type <identifier_> XMLElement | |
543 | %type <identifier_> XMLElementContent | |
544 | %type <identifier_> XMLMarkup | |
545 | %type <identifier_> XMLPI | |
546 | ||
547 | %type <attribute_> AttributeIdentifier | |
b92ceddb | 548 | /* XXX: %type <statement_> DefaultXMLNamespaceStatement */ |
691e4717 JF |
549 | %type <expression_> PropertyIdentifier |
550 | %type <expression_> XMLListInitialiser | |
551 | %type <expression_> XMLInitialiser | |
552 | @end | |
c3b144b8 JF |
553 | /* }}} */ |
554 | /* Token Priorities {{{ */ | |
3ea7eed0 JF |
555 | %nonassoc "" |
556 | %left "++" "--" | |
b92ceddb JF |
557 | |
558 | %nonassoc "if" | |
559 | %nonassoc "else" | |
c3b144b8 | 560 | /* }}} */ |
b92ceddb | 561 | |
693d501b | 562 | %start Program |
e5332278 | 563 | |
693d501b | 564 | %% |
c3c20102 | 565 | |
691e4717 | 566 | /* Lexer State {{{ */ |
3ea7eed0 JF |
567 | LexPushInOn |
568 | : { driver.in_.push(true); } | |
569 | ; | |
570 | ||
571 | LexPushInOff | |
572 | : { driver.in_.push(false); } | |
573 | ; | |
574 | ||
575 | LexPopIn | |
576 | : { driver.in_.pop(); } | |
577 | ; | |
578 | ||
691e4717 JF |
579 | LexSetRegExp |
580 | : { driver.SetCondition(CYDriver::RegExpCondition); } | |
581 | ; | |
3ea7eed0 | 582 | |
4b2fd91c | 583 | LexNoBrace |
6ce9ac92 | 584 | : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); } |
4b2fd91c | 585 | ; |
066da9f6 | 586 | |
4b2fd91c | 587 | LexNoFunction |
6ce9ac92 | 588 | : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); } |
4b2fd91c JF |
589 | ; |
590 | ||
39ed6a51 JF |
591 | LexNoAtImplementation : |
592 | @begin ObjectiveC | |
6ce9ac92 | 593 | { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); } |
39ed6a51 | 594 | @end |
507848cd JF |
595 | ; |
596 | ||
4b2fd91c | 597 | LexSetStatement |
507848cd | 598 | : LexNoBrace LexNoFunction LexNoAtImplementation |
3ea7eed0 | 599 | ; |
691e4717 | 600 | /* }}} */ |
c3b144b8 | 601 | /* Virtual Tokens {{{ */ |
3ea7eed0 | 602 | BRACE |
6c093cce JF |
603 | : "{" |
604 | | "\n{" | |
605 | ; | |
a87d7060 JF |
606 | |
607 | Var_ | |
608 | : "var" | |
609 | ; | |
c3b144b8 | 610 | /* }}} */ |
6c093cce | 611 | |
c3b144b8 JF |
612 | /* 7.6 Identifier Names and Identifiers {{{ */ |
613 | IdentifierName | |
614 | : Word { $$ = $1; } | |
c3c20102 JF |
615 | ; |
616 | ||
617 | NewLineOpt | |
693d501b | 618 | : "\n" |
c3c20102 JF |
619 | | |
620 | ; | |
1dbba6cc | 621 | |
36cd3cb9 | 622 | Word |
cf7d4c69 | 623 | : Identifier { $$ = $1; } |
a87d7060 | 624 | | "auto" { $$ = $1; } |
c3c20102 | 625 | | "break" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
626 | | "case" { $$ = $1; } |
627 | | "catch" { $$ = $1; } | |
d35a3b07 JF |
628 | | "class" { $$ = $1; } |
629 | | "const" { $$ = $1; } | |
c3c20102 | 630 | | "continue" NewLineOpt { $$ = $1; } |
d35a3b07 | 631 | | "debugger" { $$ = $1; } |
cf7d4c69 | 632 | | "default" { $$ = $1; } |
ed493ddd | 633 | | "delete" LexSetRegExp { $$ = $1; } |
cf7d4c69 JF |
634 | | "do" { $$ = $1; } |
635 | | "else" { $$ = $1; } | |
d35a3b07 JF |
636 | | "enum" { $$ = $1; } |
637 | | "export" { $$ = $1; } | |
638 | | "extends" { $$ = $1; } | |
cf7d4c69 JF |
639 | | "false" { $$ = $1; } |
640 | | "finally" { $$ = $1; } | |
561ac418 | 641 | /* XXX: | "for" { $$ = $1; } */ |
cf7d4c69 JF |
642 | | "function" { $$ = $1; } |
643 | | "if" { $$ = $1; } | |
d35a3b07 | 644 | | "import" { $$ = $1; } |
693d501b | 645 | /* XXX: | "in" { $$ = $1; } */ |
4492c19c | 646 | | "!in" { $$ = $1; } |
693d501b | 647 | /* XXX: | "instanceof" { $$ = $1; } */ |
dd983804 JF |
648 | |
649 | // XXX: as it currently is not an Identifier | |
650 | | "let" { $$ = $1; } | |
651 | ||
ed493ddd | 652 | | "new" LexSetRegExp { $$ = $1; } |
cf7d4c69 | 653 | | "null" { $$ = $1; } |
c3c20102 | 654 | | "return" NewLineOpt { $$ = $1; } |
d35a3b07 | 655 | | "super" { $$ = $1; } |
cf7d4c69 JF |
656 | | "switch" { $$ = $1; } |
657 | | "this" { $$ = $1; } | |
c3c20102 | 658 | | "throw" NewLineOpt { $$ = $1; } |
cf7d4c69 JF |
659 | | "true" { $$ = $1; } |
660 | | "try" { $$ = $1; } | |
ed493ddd | 661 | | "typeof" LexSetRegExp { $$ = $1; } |
cf7d4c69 | 662 | | "var" { $$ = $1; } |
ed493ddd | 663 | | "void" LexSetRegExp { $$ = $1; } |
cf7d4c69 JF |
664 | | "while" { $$ = $1; } |
665 | | "with" { $$ = $1; } | |
2bf24581 | 666 | ; |
f2f0d1d1 | 667 | |
73f04979 | 668 | @begin ObjectiveC |
55fc1817 JF |
669 | WordOpt |
670 | : Word { $$ = $1; } | |
671 | | { $$ = NULL; } | |
672 | ; | |
73f04979 | 673 | @end |
55fc1817 | 674 | |
3fe283c5 | 675 | IdentifierType |
75b0a457 | 676 | : Identifier_ { $$ = $1; } |
534fb6da JF |
677 | |
678 | | "implements" { $$ = $1; } | |
679 | | "interface" { $$ = $1; } | |
680 | | "package" { $$ = $1; } | |
681 | | "private" { $$ = $1; } | |
682 | | "protected" { $$ = $1; } | |
683 | | "public" { $$ = $1; } | |
684 | | "static" { $$ = $1; } | |
685 | ||
686 | | "abstract" { $$ = $1; } | |
687 | | "boolean" { $$ = $1; } | |
688 | | "byte" { $$ = $1; } | |
534fb6da JF |
689 | | "double" { $$ = $1; } |
690 | | "final" { $$ = $1; } | |
691 | | "float" { $$ = $1; } | |
692 | | "goto" { $$ = $1; } | |
534fb6da | 693 | | "native" { $$ = $1; } |
534fb6da JF |
694 | | "synchronized" { $$ = $1; } |
695 | | "throws" { $$ = $1; } | |
696 | | "transient" { $$ = $1; } | |
534fb6da | 697 | |
dd983804 JF |
698 | // XXX: currently I only have this as Word |
699 | // | "let" { $$ = $1; } | |
700 | ||
6265f0de | 701 | | "yield" NewLineOpt { $$ = $1; } |
534fb6da JF |
702 | |
703 | | "each" { $$ = $1; } | |
480c8834 | 704 | | "of" { $$ = $1; } |
75b0a457 JF |
705 | ; |
706 | ||
3fe283c5 JF |
707 | Identifier |
708 | : IdentifierType | |
709 | | "char" { $$ = $1; } | |
710 | | "int" { $$ = $1; } | |
711 | | "long" { $$ = $1; } | |
712 | | "short" { $$ = $1; } | |
713 | | "volatile" { $$ = $1; } | |
714 | @begin C | |
715 | | "typedef" { $$ = $1; } | |
716 | | "unsigned" { $$ = $1; } | |
717 | | "signed" { $$ = $1; } | |
c5587ed7 | 718 | | "extern" { $$ = $1; } |
7b750785 JF |
719 | @end |
720 | @begin ObjectiveC | |
3fe283c5 JF |
721 | | "YES" { $$ = $1; } |
722 | | "NO" { $$ = $1; } | |
723 | @end | |
724 | ; | |
725 | ||
36cd3cb9 | 726 | IdentifierOpt |
cf7d4c69 JF |
727 | : Identifier { $$ = $1; } |
728 | | { $$ = NULL; } | |
1dbba6cc | 729 | ; |
c3b144b8 | 730 | /* }}} */ |
1dbba6cc | 731 | |
c3b144b8 JF |
732 | /* 7.8 Literals {{{ */ |
733 | Literal | |
cf7d4c69 | 734 | : NullLiteral { $$ = $1; } |
c3b144b8 | 735 | | ValueLiteral { $$ = $1; } |
561ac418 JF |
736 | ; |
737 | ||
c3b144b8 JF |
738 | ValueLiteral |
739 | : BooleanLiteral { $$ = $1; } | |
740 | | NumericLiteral { $$ = $1; } | |
741 | | StringLiteral { $$ = $1; } | |
3ea7eed0 | 742 | | RegularExpressionLiteral { $$ = $1; } |
1dbba6cc | 743 | ; |
c3b144b8 JF |
744 | /* }}} */ |
745 | /* 7.8.1 Null Literals {{{ */ | |
36cd3cb9 | 746 | NullLiteral |
cf7d4c69 | 747 | : "null" { $$ = $1; } |
1dbba6cc | 748 | ; |
c3b144b8 JF |
749 | /* }}} */ |
750 | /* 7.8.2 Boolean Literals {{{ */ | |
36cd3cb9 | 751 | BooleanLiteral |
cf7d4c69 JF |
752 | : "true" { $$ = $1; } |
753 | | "false" { $$ = $1; } | |
1dbba6cc | 754 | ; |
c3b144b8 JF |
755 | /* }}} */ |
756 | ||
757 | /* 7.9 Automatic Semicolon Insertion {{{ */ | |
758 | StrictSemi | |
6ce9ac92 | 759 | : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); } |
c3b144b8 JF |
760 | ; |
761 | ||
762 | Terminator | |
763 | : ";" | |
6df8474b | 764 | | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !yyla.value.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi |
c3b144b8 JF |
765 | ; |
766 | ||
767 | TerminatorOpt | |
768 | : ";" | |
769 | | error { yyerrok; driver.errors_.pop_back(); } StrictSemi | |
770 | ; | |
771 | /* }}} */ | |
1dbba6cc | 772 | |
1dbba6cc | 773 | /* 11.1 Primary Expressions {{{ */ |
3ea7eed0 | 774 | Parenthetical |
b0385401 | 775 | : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); } |
561ac418 JF |
776 | ; |
777 | ||
46f4f308 JF |
778 | Variable |
779 | : Identifier { $$ = CYNew CYVariable($1); } | |
780 | ; | |
781 | ||
3ea7eed0 | 782 | PrimaryExpression |
cf7d4c69 | 783 | : "this" { $$ = $1; } |
46f4f308 | 784 | | Variable { $$ = $1; } |
cf7d4c69 | 785 | | Literal { $$ = $1; } |
b3aa25d8 | 786 | | ArrayInitialiser { $$ = $1; } |
3ea7eed0 | 787 | | ObjectLiteral { $$ = $1; } |
3ea7eed0 JF |
788 | | Parenthetical { $$ = $1; } |
789 | | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } | |
1dbba6cc JF |
790 | ; |
791 | /* }}} */ | |
b3aa25d8 JF |
792 | /* 11.1.4 Array Initializer {{{ */ |
793 | ArrayInitialiser | |
794 | : ArrayLiteral { $$ = $1; } | |
795 | | ArrayComprehension { $$ = $1; } | |
796 | ; | |
797 | /* }}} */ | |
798 | /* 11.1.4.1 Array Literal {{{ */ | |
36cd3cb9 | 799 | ArrayLiteral |
440424e2 | 800 | : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); } |
1dbba6cc JF |
801 | ; |
802 | ||
36cd3cb9 | 803 | Element |
cf7d4c69 | 804 | : AssignmentExpression { $$ = $1; } |
5befe15e JF |
805 | ; |
806 | ||
807 | ElementOpt | |
808 | : Element { $$ = $1; } | |
691e4717 | 809 | | LexSetRegExp { $$ = NULL; } |
1dbba6cc JF |
810 | ; |
811 | ||
36cd3cb9 | 812 | ElementList |
2eb8215d JF |
813 | : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); } |
814 | | Element { $$ = CYNew CYElement($1, NULL); } | |
1dbba6cc | 815 | ; |
55fc1817 JF |
816 | |
817 | ElementListOpt | |
818 | : ElementList { $$ = $1; } | |
819 | | LexSetRegExp { $$ = NULL; } | |
820 | ; | |
1dbba6cc | 821 | /* }}} */ |
c2529502 | 822 | /* 11.1.4.2 Array Comprehension {{{ */ |
b3aa25d8 JF |
823 | ArrayComprehension |
824 | : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; } | |
c2529502 JF |
825 | ; |
826 | ||
b3aa25d8 JF |
827 | Comprehension |
828 | : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); } | |
c2529502 JF |
829 | ; |
830 | ||
b3aa25d8 JF |
831 | ComprehensionTail |
832 | : { $$ = NULL; } | |
833 | | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); } | |
834 | | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); } | |
835 | ; | |
836 | ||
837 | ComprehensionFor | |
838 | : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); } | |
839 | ; | |
840 | ||
841 | ComprehensionIf | |
842 | : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); } | |
c2529502 JF |
843 | ; |
844 | /* }}} */ | |
1dbba6cc | 845 | /* 11.1.5 Object Initialiser {{{ */ |
36cd3cb9 | 846 | ObjectLiteral |
440424e2 | 847 | : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); } |
1dbba6cc JF |
848 | ; |
849 | ||
aea76473 JF |
850 | PropertyDefinitionList_ |
851 | : "," PropertyDefinitionList { $$ = $2; } | |
70234143 | 852 | | "," LexSetRegExp { $$ = NULL; } |
cac61857 | 853 | | { $$ = NULL; } |
1dbba6cc JF |
854 | ; |
855 | ||
aea76473 JF |
856 | PropertyDefinitionList |
857 | : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; } | |
55fc1817 JF |
858 | ; |
859 | ||
aea76473 JF |
860 | PropertyDefinitionListOpt |
861 | : PropertyDefinitionList { $$ = $1; } | |
70234143 | 862 | | LexSetRegExp { $$ = NULL; } |
1dbba6cc JF |
863 | ; |
864 | ||
aea76473 | 865 | PropertyDefinition |
797cb0e5 JF |
866 | // XXX: this should be IdentifierName |
867 | : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); } | |
868 | | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); } | |
aea76473 JF |
869 | //| MethodDefinition |
870 | ; | |
871 | ||
b92ceddb | 872 | PropertyName_ |
4492c19c | 873 | : IdentifierName { $$ = $1; } |
36cd3cb9 JF |
874 | | StringLiteral { $$ = $1; } |
875 | | NumericLiteral { $$ = $1; } | |
1dbba6cc | 876 | ; |
b92ceddb JF |
877 | |
878 | PropertyName | |
879 | : LexSetRegExp PropertyName_ { $$ = $2; } | |
880 | ; | |
1dbba6cc JF |
881 | /* }}} */ |
882 | ||
63cd45c9 | 883 | /* 11.2 Left-Hand-Side Expressions {{{ */ |
9b5527f0 | 884 | MemberAccess |
440424e2 | 885 | : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); } |
5ccfc586 | 886 | | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); } |
7e5391fd | 887 | | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } |
9b5527f0 JF |
888 | ; |
889 | ||
55fc1817 | 890 | MemberExpression_ |
3ea7eed0 JF |
891 | : MemberExpression { $$ = $1; } |
892 | //| "super" { $$ = $1; } | |
55fc1817 JF |
893 | ; |
894 | ||
36cd3cb9 | 895 | MemberExpression |
3ea7eed0 | 896 | : LexSetRegExp PrimaryExpression { $$ = $2; } |
afbff131 | 897 | | LexSetRegExp FunctionExpression { $$ = $2; } |
3ea7eed0 JF |
898 | | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } |
899 | | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); } | |
1dbba6cc JF |
900 | ; |
901 | ||
36cd3cb9 | 902 | NewExpression |
cf7d4c69 | 903 | : MemberExpression { $$ = $1; } |
3ea7eed0 | 904 | | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); } |
1dbba6cc JF |
905 | ; |
906 | ||
3ea7eed0 JF |
907 | CallExpression_ |
908 | : MemberExpression_ | |
909 | | CallExpression | |
b1589845 JF |
910 | ; |
911 | ||
36cd3cb9 | 912 | CallExpression |
3ea7eed0 | 913 | : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); } |
7e5391fd | 914 | | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } |
1dbba6cc JF |
915 | ; |
916 | ||
3ea7eed0 | 917 | Arguments |
440424e2 | 918 | : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; } |
b1589845 JF |
919 | ; |
920 | ||
36cd3cb9 | 921 | ArgumentList_ |
cf7d4c69 JF |
922 | : "," ArgumentList { $$ = $2; } |
923 | | { $$ = NULL; } | |
1dbba6cc JF |
924 | ; |
925 | ||
55fc1817 JF |
926 | ArgumentList |
927 | : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); } | |
ed493ddd | 928 | | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); } |
55fc1817 JF |
929 | ; |
930 | ||
36cd3cb9 | 931 | ArgumentListOpt |
cf7d4c69 | 932 | : ArgumentList { $$ = $1; } |
691e4717 | 933 | | LexSetRegExp { $$ = NULL; } |
1dbba6cc JF |
934 | ; |
935 | ||
36cd3cb9 | 936 | LeftHandSideExpression |
cf7d4c69 JF |
937 | : NewExpression { $$ = $1; } |
938 | | CallExpression { $$ = $1; } | |
693d501b | 939 | ; |
63cd45c9 JF |
940 | /* }}} */ |
941 | /* 11.3 Postfix Expressions {{{ */ | |
36cd3cb9 | 942 | PostfixExpression |
3ea7eed0 | 943 | : %prec "" LeftHandSideExpression { $$ = $1; } |
2eb8215d JF |
944 | | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); } |
945 | | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); } | |
1dbba6cc | 946 | ; |
63cd45c9 JF |
947 | /* }}} */ |
948 | /* 11.4 Unary Operators {{{ */ | |
693d501b | 949 | UnaryExpression_ |
2eb8215d JF |
950 | : "delete" UnaryExpression { $$ = CYNew CYDelete($2); } |
951 | | "void" UnaryExpression { $$ = CYNew CYVoid($2); } | |
952 | | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); } | |
953 | | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); } | |
954 | | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); } | |
955 | | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); } | |
956 | | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); } | |
957 | | "+" UnaryExpression { $$ = CYNew CYAffirm($2); } | |
958 | | "-" UnaryExpression { $$ = CYNew CYNegate($2); } | |
959 | | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); } | |
960 | | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); } | |
693d501b JF |
961 | ; |
962 | ||
963 | UnaryExpression | |
964 | : PostfixExpression { $$ = $1; } | |
691e4717 | 965 | | LexSetRegExp UnaryExpression_ { $$ = $2; } |
693d501b | 966 | ; |
63cd45c9 JF |
967 | /* }}} */ |
968 | /* 11.5 Multiplicative Operators {{{ */ | |
36cd3cb9 | 969 | MultiplicativeExpression |
cf7d4c69 | 970 | : UnaryExpression { $$ = $1; } |
2eb8215d JF |
971 | | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); } |
972 | | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); } | |
973 | | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); } | |
1dbba6cc | 974 | ; |
63cd45c9 JF |
975 | /* }}} */ |
976 | /* 11.6 Additive Operators {{{ */ | |
36cd3cb9 | 977 | AdditiveExpression |
cf7d4c69 | 978 | : MultiplicativeExpression { $$ = $1; } |
2eb8215d JF |
979 | | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); } |
980 | | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); } | |
1dbba6cc | 981 | ; |
63cd45c9 JF |
982 | /* }}} */ |
983 | /* 11.7 Bitwise Shift Operators {{{ */ | |
36cd3cb9 | 984 | ShiftExpression |
cf7d4c69 | 985 | : AdditiveExpression { $$ = $1; } |
2eb8215d JF |
986 | | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); } |
987 | | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); } | |
988 | | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); } | |
1dbba6cc | 989 | ; |
63cd45c9 JF |
990 | /* }}} */ |
991 | /* 11.8 Relational Operators {{{ */ | |
3ea7eed0 | 992 | RelationalExpression |
05089169 JF |
993 | : ShiftExpression { $$ = $1; } |
994 | | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); } | |
995 | | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); } | |
996 | | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); } | |
997 | | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); } | |
998 | | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); } | |
999 | | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); } | |
693d501b | 1000 | ; |
63cd45c9 JF |
1001 | /* }}} */ |
1002 | /* 11.9 Equality Operators {{{ */ | |
36cd3cb9 | 1003 | EqualityExpression |
cf7d4c69 | 1004 | : RelationalExpression { $$ = $1; } |
2eb8215d JF |
1005 | | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); } |
1006 | | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); } | |
1007 | | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); } | |
1008 | | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); } | |
1dbba6cc | 1009 | ; |
63cd45c9 JF |
1010 | /* }}} */ |
1011 | /* 11.10 Binary Bitwise Operators {{{ */ | |
36cd3cb9 | 1012 | BitwiseANDExpression |
cf7d4c69 | 1013 | : EqualityExpression { $$ = $1; } |
2eb8215d | 1014 | | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); } |
1dbba6cc JF |
1015 | ; |
1016 | ||
36cd3cb9 | 1017 | BitwiseXORExpression |
cf7d4c69 | 1018 | : BitwiseANDExpression { $$ = $1; } |
2eb8215d | 1019 | | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); } |
1dbba6cc JF |
1020 | ; |
1021 | ||
36cd3cb9 | 1022 | BitwiseORExpression |
cf7d4c69 | 1023 | : BitwiseXORExpression { $$ = $1; } |
2eb8215d | 1024 | | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); } |
1dbba6cc | 1025 | ; |
63cd45c9 JF |
1026 | /* }}} */ |
1027 | /* 11.11 Binary Logical Operators {{{ */ | |
36cd3cb9 | 1028 | LogicalANDExpression |
cf7d4c69 | 1029 | : BitwiseORExpression { $$ = $1; } |
2eb8215d | 1030 | | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); } |
1dbba6cc JF |
1031 | ; |
1032 | ||
36cd3cb9 | 1033 | LogicalORExpression |
cf7d4c69 | 1034 | : LogicalANDExpression { $$ = $1; } |
2eb8215d | 1035 | | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); } |
1dbba6cc | 1036 | ; |
63cd45c9 JF |
1037 | /* }}} */ |
1038 | /* 11.12 Conditional Operator ( ? : ) {{{ */ | |
36cd3cb9 | 1039 | ConditionalExpression |
cf7d4c69 | 1040 | : LogicalORExpression { $$ = $1; } |
440424e2 | 1041 | | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); } |
c2faf0d3 | 1042 | | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); } |
693d501b | 1043 | ; |
63cd45c9 JF |
1044 | /* }}} */ |
1045 | /* 11.13 Assignment Operators {{{ */ | |
36cd3cb9 | 1046 | AssignmentExpression |
cf7d4c69 | 1047 | : ConditionalExpression { $$ = $1; } |
4b2fd91c | 1048 | | ArrowFunction { $$ = $1; } |
005a0939 JF |
1049 | | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); } |
1050 | | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); } | |
1051 | | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); } | |
1052 | | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); } | |
1053 | | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); } | |
1054 | | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); } | |
1055 | | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); } | |
1056 | | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); } | |
1057 | | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); } | |
1058 | | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); } | |
1059 | | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); } | |
1060 | | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); } | |
693d501b | 1061 | ; |
63cd45c9 JF |
1062 | /* }}} */ |
1063 | /* 11.14 Comma Operator {{{ */ | |
55fc1817 | 1064 | Expression |
b0385401 JF |
1065 | : AssignmentExpression { $$ = $1; } |
1066 | | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); } | |
693d501b JF |
1067 | ; |
1068 | ||
36cd3cb9 | 1069 | ExpressionOpt |
cf7d4c69 | 1070 | : Expression { $$ = $1; } |
691e4717 | 1071 | | LexSetRegExp { $$ = NULL; } |
1dbba6cc | 1072 | ; |
63cd45c9 | 1073 | /* }}} */ |
693d501b | 1074 | |
63cd45c9 | 1075 | /* 12 Statements {{{ */ |
3ea7eed0 | 1076 | Statement__ |
36cd3cb9 JF |
1077 | : Block { $$ = $1; } |
1078 | | VariableStatement { $$ = $1; } | |
1079 | | EmptyStatement { $$ = $1; } | |
cf7d4c69 | 1080 | | IfStatement { $$ = $1; } |
c8a0500b | 1081 | | BreakableStatement { $$ = $1; } |
36cd3cb9 JF |
1082 | | ContinueStatement { $$ = $1; } |
1083 | | BreakStatement { $$ = $1; } | |
1084 | | ReturnStatement { $$ = $1; } | |
cf7d4c69 JF |
1085 | | WithStatement { $$ = $1; } |
1086 | | LabelledStatement { $$ = $1; } | |
36cd3cb9 JF |
1087 | | ThrowStatement { $$ = $1; } |
1088 | | TryStatement { $$ = $1; } | |
c8a0500b | 1089 | | DebuggerStatement { $$ = $1; } |
1dbba6cc | 1090 | ; |
b10bd496 | 1091 | |
3ea7eed0 JF |
1092 | Statement_ |
1093 | : LexSetRegExp Statement__ { $$ = $2; } | |
1094 | | ExpressionStatement { $$ = $1; } | |
1095 | ; | |
1096 | ||
b10bd496 | 1097 | Statement |
3ea7eed0 | 1098 | : LexSetStatement Statement_ { $$ = $2; } |
b10bd496 | 1099 | ; |
c8a0500b | 1100 | |
3ea7eed0 | 1101 | Declaration__ |
c8a0500b JF |
1102 | : FunctionDeclaration { $$ = $1; } |
1103 | | LexicalDeclaration { $$ = $1; } | |
1104 | ; | |
1105 | ||
3ea7eed0 JF |
1106 | Declaration_ |
1107 | : LexSetRegExp Declaration__ { $$ = $2; } | |
1108 | ; | |
1109 | ||
1110 | Declaration | |
1111 | : LexSetStatement Declaration_ { $$ = $2; } | |
1112 | ; | |
1113 | ||
c8a0500b JF |
1114 | BreakableStatement |
1115 | : IterationStatement { $$ = $1; } | |
1116 | | SwitchStatement { $$ = $1; } | |
1117 | ; | |
63cd45c9 JF |
1118 | /* }}} */ |
1119 | /* 12.1 Block {{{ */ | |
cac61857 | 1120 | Block_ |
3ea7eed0 | 1121 | : BRACE StatementListOpt "}" { $$ = $2; } |
cac61857 JF |
1122 | ; |
1123 | ||
36cd3cb9 | 1124 | Block |
3ea7eed0 | 1125 | : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); } |
1dbba6cc JF |
1126 | ; |
1127 | ||
693d501b | 1128 | StatementList |
c8a0500b | 1129 | : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; } |
693d501b JF |
1130 | ; |
1131 | ||
1132 | StatementListOpt | |
1133 | : StatementList { $$ = $1; } | |
5d660bed | 1134 | | LexSetStatement LexSetRegExp { $$ = NULL; } |
1dbba6cc | 1135 | ; |
c8a0500b JF |
1136 | |
1137 | StatementListItem | |
1138 | : Statement { $$ = $1; } | |
3ea7eed0 | 1139 | | Declaration { $$ = $1; } |
c8a0500b JF |
1140 | ; |
1141 | /* }}} */ | |
c3b144b8 | 1142 | |
c8a0500b JF |
1143 | /* 12.2 Declarations {{{ */ |
1144 | BindingIdentifier | |
1145 | : Identifier { $$ = $1; } | |
1146 | ; | |
1147 | ||
c2529502 JF |
1148 | Binding |
1149 | : BindingIdentifier | |
1150 | ; | |
1151 | ||
c8a0500b JF |
1152 | // XXX: BindingPattern |
1153 | /* }}} */ | |
1154 | /* 12.2.1 Let and Const Declarations {{{ */ | |
1155 | LexicalDeclaration | |
1156 | : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } | |
1157 | ; | |
1158 | ||
1159 | LetOrConst | |
1160 | : "let" | |
1161 | | "const" | |
1162 | ; | |
63cd45c9 | 1163 | /* }}} */ |
c8a0500b | 1164 | /* 12.2.2 Variable Statement {{{ */ |
36cd3cb9 | 1165 | VariableStatement |
a87d7060 | 1166 | : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } |
1dbba6cc JF |
1167 | ; |
1168 | ||
36cd3cb9 | 1169 | VariableDeclarationList_ |
cf7d4c69 JF |
1170 | : "," VariableDeclarationList { $$ = $2; } |
1171 | | { $$ = NULL; } | |
1dbba6cc JF |
1172 | ; |
1173 | ||
55fc1817 JF |
1174 | VariableDeclarationList |
1175 | : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } | |
1176 | ; | |
1177 | ||
36cd3cb9 | 1178 | VariableDeclaration |
c8a0500b JF |
1179 | : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } |
1180 | // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); } | |
1dbba6cc JF |
1181 | ; |
1182 | ||
55fc1817 JF |
1183 | Initialiser |
1184 | : "=" AssignmentExpression { $$ = $2; } | |
1185 | ; | |
1186 | ||
36cd3cb9 | 1187 | InitialiserOpt |
cf7d4c69 | 1188 | : Initialiser { $$ = $1; } |
36cd3cb9 | 1189 | | { $$ = NULL; } |
1dbba6cc | 1190 | ; |
63cd45c9 | 1191 | /* }}} */ |
c8a0500b JF |
1192 | /* 12.2.4 Destructuring Binding Patterns {{{ */ |
1193 | // XXX: * | |
1194 | ||
1195 | BindingElement | |
1196 | : SingleNameBinding { $$ = $1; } | |
1197 | ; | |
1198 | ||
1199 | SingleNameBinding | |
1200 | : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } | |
1201 | ; | |
1202 | /* }}} */ | |
c3b144b8 | 1203 | |
63cd45c9 | 1204 | /* 12.3 Empty Statement {{{ */ |
36cd3cb9 | 1205 | EmptyStatement |
2eb8215d | 1206 | : ";" { $$ = CYNew CYEmpty(); } |
1dbba6cc | 1207 | ; |
63cd45c9 JF |
1208 | /* }}} */ |
1209 | /* 12.4 Expression Statement {{{ */ | |
36cd3cb9 | 1210 | ExpressionStatement |
3ea7eed0 | 1211 | : Expression Terminator { $$ = CYNew CYExpress($1); } |
1dbba6cc | 1212 | ; |
63cd45c9 JF |
1213 | /* }}} */ |
1214 | /* 12.5 The if Statement {{{ */ | |
36cd3cb9 JF |
1215 | ElseStatementOpt |
1216 | : "else" Statement { $$ = $2; } | |
c3c20102 | 1217 | | %prec "if" { $$ = NULL; } |
1dbba6cc JF |
1218 | ; |
1219 | ||
36cd3cb9 | 1220 | IfStatement |
2eb8215d | 1221 | : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); } |
1dbba6cc | 1222 | ; |
63cd45c9 | 1223 | /* }}} */ |
1dbba6cc | 1224 | |
63cd45c9 | 1225 | /* 12.6.1 The do-while Statement {{{ */ |
d5618df7 | 1226 | IterationStatement |
2eb8215d | 1227 | : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); } |
1dbba6cc | 1228 | ; |
63cd45c9 JF |
1229 | /* }}} */ |
1230 | /* 12.6.2 The while Statement {{{ */ | |
d5618df7 | 1231 | IterationStatement |
2eb8215d | 1232 | : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); } |
1dbba6cc | 1233 | ; |
63cd45c9 JF |
1234 | /* }}} */ |
1235 | /* 12.6.3 The for Statement {{{ */ | |
d5618df7 | 1236 | IterationStatement |
440424e2 | 1237 | : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); } |
1dbba6cc JF |
1238 | ; |
1239 | ||
36cd3cb9 | 1240 | ForStatementInitialiser |
3ea7eed0 | 1241 | : ExpressionOpt { $$ = $1; } |
a87d7060 | 1242 | | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); } |
1dbba6cc | 1243 | ; |
63cd45c9 | 1244 | /* }}} */ |
0d56ef32 | 1245 | /* 12.6.4 The for-in and for-of Statements {{{ */ |
d5618df7 | 1246 | IterationStatement |
440424e2 JF |
1247 | : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); } |
1248 | | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } | |
1dbba6cc JF |
1249 | ; |
1250 | ||
36cd3cb9 JF |
1251 | ForInStatementInitialiser |
1252 | : LeftHandSideExpression { $$ = $1; } | |
a87d7060 | 1253 | | LexSetRegExp Var_ VariableDeclaration { $$ = $3; } |
1dbba6cc | 1254 | ; |
63cd45c9 | 1255 | /* }}} */ |
1dbba6cc | 1256 | |
63cd45c9 | 1257 | /* 12.7 The continue Statement {{{ */ |
36cd3cb9 | 1258 | ContinueStatement |
5ccfc586 JF |
1259 | : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); } |
1260 | | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); } | |
1dbba6cc | 1261 | ; |
63cd45c9 JF |
1262 | /* }}} */ |
1263 | /* 12.8 The break Statement {{{ */ | |
36cd3cb9 | 1264 | BreakStatement |
5ccfc586 JF |
1265 | : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); } |
1266 | | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); } | |
1dbba6cc | 1267 | ; |
63cd45c9 JF |
1268 | /* }}} */ |
1269 | /* 12.9 The return Statement {{{ */ | |
36cd3cb9 | 1270 | ReturnStatement |
e0815d86 | 1271 | : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); } |
5ccfc586 | 1272 | | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); } |
1dbba6cc | 1273 | ; |
63cd45c9 JF |
1274 | /* }}} */ |
1275 | /* 12.10 The with Statement {{{ */ | |
36cd3cb9 | 1276 | WithStatement |
2eb8215d | 1277 | : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); } |
1dbba6cc | 1278 | ; |
63cd45c9 | 1279 | /* }}} */ |
1dbba6cc | 1280 | |
63cd45c9 | 1281 | /* 12.11 The switch Statement {{{ */ |
36cd3cb9 | 1282 | SwitchStatement |
2eb8215d | 1283 | : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); } |
1dbba6cc JF |
1284 | ; |
1285 | ||
1286 | CaseBlock | |
3ea7eed0 | 1287 | : BRACE CaseClausesOpt "}" { $$ = $2; } |
1dbba6cc JF |
1288 | ; |
1289 | ||
55fc1817 JF |
1290 | CaseClause |
1291 | : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); } | |
1292 | ; | |
1293 | ||
36cd3cb9 | 1294 | CaseClausesOpt |
cf7d4c69 JF |
1295 | : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } |
1296 | | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | |
1297 | | { $$ = NULL; } | |
1dbba6cc JF |
1298 | ; |
1299 | ||
36cd3cb9 | 1300 | DefaultClause |
2eb8215d | 1301 | : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); } |
1dbba6cc | 1302 | ; |
63cd45c9 JF |
1303 | /* }}} */ |
1304 | /* 12.12 Labelled Statements {{{ */ | |
36cd3cb9 | 1305 | LabelledStatement |
2eb8215d | 1306 | : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); } |
1dbba6cc | 1307 | ; |
63cd45c9 JF |
1308 | /* }}} */ |
1309 | /* 12.13 The throw Statement {{{ */ | |
36cd3cb9 | 1310 | ThrowStatement |
6265f0de | 1311 | : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); } |
5ccfc586 | 1312 | | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); } |
1dbba6cc | 1313 | ; |
63cd45c9 JF |
1314 | /* }}} */ |
1315 | /* 12.14 The try Statement {{{ */ | |
36cd3cb9 | 1316 | TryStatement |
2eb8215d | 1317 | : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); } |
1dbba6cc JF |
1318 | ; |
1319 | ||
1320 | CatchOpt | |
2eb8215d | 1321 | : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); } |
cf7d4c69 | 1322 | | { $$ = NULL; } |
1dbba6cc JF |
1323 | ; |
1324 | ||
1325 | FinallyOpt | |
2eb8215d | 1326 | : "finally" Block_ { $$ = CYNew CYFinally($2); } |
cf7d4c69 | 1327 | | { $$ = NULL; } |
1dbba6cc | 1328 | ; |
63cd45c9 | 1329 | /* }}} */ |
c8a0500b JF |
1330 | /* 12.14 The debugger Statement {{{ */ |
1331 | DebuggerStatement | |
1332 | : "debugger" Terminator { $$ = CYNew CYDebugger(); } | |
1333 | ; | |
1334 | /* }}} */ | |
1dbba6cc | 1335 | |
4b2fd91c | 1336 | /* 13.1 Function Definitions {{{ */ |
36cd3cb9 | 1337 | FunctionDeclaration |
3ea7eed0 | 1338 | : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } |
1dbba6cc JF |
1339 | ; |
1340 | ||
36cd3cb9 | 1341 | FunctionExpression |
440424e2 | 1342 | : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); } |
1dbba6cc JF |
1343 | ; |
1344 | ||
1345 | FormalParameterList_ | |
36cd3cb9 | 1346 | : "," FormalParameterList { $$ = $2; } |
cf7d4c69 | 1347 | | { $$ = NULL; } |
1dbba6cc JF |
1348 | ; |
1349 | ||
c8a0500b JF |
1350 | FormalParameterList |
1351 | // XXX: : FunctionRestParameter { $$ = $1; } | |
1352 | : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } | |
1353 | ; | |
1354 | ||
55fc1817 JF |
1355 | FormalParameterListOpt |
1356 | : FormalParameterList | |
1357 | | { $$ = NULL; } | |
1358 | ; | |
1359 | ||
c8a0500b JF |
1360 | /* XXX: FunctionRestParameter |
1361 | : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); } | |
1362 | ;*/ | |
1363 | ||
1364 | FormalParameter | |
1365 | : BindingElement { $$ = $1; } | |
1366 | ; | |
1367 | ||
36cd3cb9 | 1368 | FunctionBody |
c8a0500b | 1369 | : StatementListOpt { $$ = $1; } |
1dbba6cc | 1370 | ; |
63cd45c9 | 1371 | /* }}} */ |
4b2fd91c JF |
1372 | /* 13.2 Arrow Function Definitions {{{ */ |
1373 | ArrowFunction | |
a0be43fc | 1374 | : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); } |
4b2fd91c JF |
1375 | ; |
1376 | ||
1377 | ArrowParameters | |
1378 | : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); } | |
0afc9ba3 | 1379 | | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; } |
b0385401 | 1380 | | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); } |
4b2fd91c JF |
1381 | ; |
1382 | ||
1383 | ConciseBody | |
1384 | : AssignmentExpression { $$ = CYNew CYReturn($1); } | |
440424e2 | 1385 | | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; } |
4b2fd91c JF |
1386 | ; |
1387 | /* }}} */ | |
63cd45c9 | 1388 | /* 14 Program {{{ */ |
1dbba6cc | 1389 | Program |
c8a0500b | 1390 | : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); } |
1dbba6cc JF |
1391 | ; |
1392 | ||
55fc1817 JF |
1393 | ProgramBody |
1394 | : StatementList { $$ = $1; } | |
1395 | ; | |
1396 | ||
c8a0500b JF |
1397 | ProgramBodyOpt |
1398 | : ProgramBody { $$ = $1; } | |
5d660bed | 1399 | | LexSetStatement LexSetRegExp { $$ = NULL; } |
1dbba6cc | 1400 | ; |
63cd45c9 | 1401 | /* }}} */ |
e5332278 | 1402 | |
7b750785 JF |
1403 | @begin C |
1404 | /* Cycript (C): Type Encoding {{{ */ | |
663c538f | 1405 | TypeSignifier |
00b4cb83 JF |
1406 | : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); } |
1407 | | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; } | |
663c538f JF |
1408 | ; |
1409 | ||
46f4f308 | 1410 | SuffixedType |
00b4cb83 | 1411 | : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } |
3fe16be7 | 1412 | | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); } |
00b4cb83 JF |
1413 | | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); } |
1414 | | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); } | |
1415 | | TypeSignifier { $$ = $1; } | |
1416 | | { $$ = CYNew CYTypedIdentifier(@$); } | |
46f4f308 JF |
1417 | ; |
1418 | ||
1419 | PrefixedType | |
9a39f705 | 1420 | : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } |
46f4f308 JF |
1421 | ; |
1422 | ||
663c538f | 1423 | TypeQualifierLeft |
3fe283c5 JF |
1424 | : { $$ = NULL; } |
1425 | | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); } | |
1426 | | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } | |
663c538f JF |
1427 | ; |
1428 | ||
1429 | TypeQualifierRight | |
3fe283c5 | 1430 | : PrefixedType { $$ = $1; } |
9a39f705 | 1431 | | SuffixedType { $$ = $1; } |
3fe283c5 JF |
1432 | | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); } |
1433 | | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); } | |
1434 | ; | |
1435 | ||
1436 | IntegerType | |
1437 | : "int" { $$ = CYNew CYTypeVariable("int"); } | |
1438 | | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); } | |
1439 | | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); } | |
1440 | | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); } | |
1441 | | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); } | |
1442 | ; | |
1443 | ||
1444 | IntegerTypeOpt | |
1445 | : IntegerType { $$ = $1; } | |
22e0b32a | 1446 | | { $$ = CYNew CYTypeVariable("int"); } |
56e02e5b JF |
1447 | ; |
1448 | ||
663c538f | 1449 | PrimitiveType |
3fe283c5 JF |
1450 | : IdentifierType { $$ = CYNew CYTypeVariable($1); } |
1451 | | IntegerType { $$ = $1; } | |
1452 | | "void" { $$ = CYNew CYTypeVoid(); } | |
1453 | | "char" { $$ = CYNew CYTypeVariable("char"); } | |
1454 | | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); } | |
1455 | | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); } | |
46f4f308 JF |
1456 | ; |
1457 | ||
1458 | TypedIdentifier | |
3fe283c5 | 1459 | : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; } |
561e7f1c JF |
1460 | ; |
1461 | ||
46f4f308 | 1462 | PrimaryExpression |
57d55714 | 1463 | : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); } |
46f4f308 JF |
1464 | ; |
1465 | /* }}} */ | |
7b750785 JF |
1466 | @end |
1467 | ||
1468 | @begin ObjectiveC | |
4de0686f | 1469 | /* Cycript (Objective-C): @class Declaration {{{ */ |
b09da87b | 1470 | ClassSuperOpt |
3ea7eed0 JF |
1471 | /* XXX: why the hell did I choose MemberExpression? */ |
1472 | : ":" LexSetRegExp MemberExpression { $$ = $3; } | |
b09da87b JF |
1473 | | { $$ = NULL; } |
1474 | ; | |
1475 | ||
cfd73c6d | 1476 | ClassFieldListOpt |
b6a67580 | 1477 | : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); } |
70234143 | 1478 | | LexSetRegExp { $$ = NULL; } |
55fc1817 JF |
1479 | ; |
1480 | ||
cfd73c6d JF |
1481 | ClassFields |
1482 | : BRACE ClassFieldListOpt "}" { $$ = $2; } | |
1ba6903e JF |
1483 | ; |
1484 | ||
b09da87b JF |
1485 | MessageScope |
1486 | : "+" { $$ = false; } | |
1487 | | "-" { $$ = true; } | |
1488 | ; | |
1489 | ||
1490 | TypeOpt | |
104cc5f5 JF |
1491 | : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; } |
1492 | | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); } | |
b09da87b JF |
1493 | ; |
1494 | ||
1495 | MessageParameter | |
104cc5f5 | 1496 | : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); } |
b09da87b JF |
1497 | ; |
1498 | ||
55fc1817 JF |
1499 | MessageParameterList |
1500 | : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; } | |
1501 | ; | |
1502 | ||
b09da87b JF |
1503 | MessageParameterListOpt |
1504 | : MessageParameterList { $$ = $1; } | |
1505 | | { $$ = NULL; } | |
1506 | ; | |
1507 | ||
b09da87b JF |
1508 | MessageParameters |
1509 | : MessageParameterList { $$ = $1; } | |
104cc5f5 | 1510 | | Word { $$ = CYNew CYMessageParameter($1, NULL); } |
b09da87b JF |
1511 | ; |
1512 | ||
1513 | ClassMessageDeclaration | |
3ea7eed0 | 1514 | : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); } |
b09da87b JF |
1515 | ; |
1516 | ||
1517 | ClassMessageDeclarationListOpt | |
4e8c99fb | 1518 | : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; } |
1ba6903e | 1519 | | ClassMessageDeclarationListOpt Comment { $$ = $1; } |
b09da87b JF |
1520 | | { $$ = NULL; } |
1521 | ; | |
1522 | ||
e5bc40db JF |
1523 | ClassName |
1524 | : Identifier { $$ = $1; } | |
1525 | | "(" AssignmentExpression ")" { $$ = $2; } | |
1526 | ; | |
1527 | ||
367eebb1 JF |
1528 | ClassNameOpt |
1529 | : ClassName { $$ = $1; } | |
1530 | | { $$ = NULL; } | |
b09da87b JF |
1531 | ; |
1532 | ||
64b8d29f JF |
1533 | // XXX: this should be AssignmentExpressionNoRight |
1534 | ClassProtocols | |
2eb8215d | 1535 | : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); } |
64b8d29f JF |
1536 | ; |
1537 | ||
1538 | ClassProtocolsOpt | |
1539 | : "," ClassProtocols { $$ = $2; } | |
1540 | | { $$ = NULL; } | |
1541 | ; | |
1542 | ||
1543 | ClassProtocolListOpt | |
1544 | : "<" ClassProtocols ">" { $$ = $2; } | |
1545 | | { $$ = NULL; } | |
1546 | ; | |
1547 | ||
fb98ac0c | 1548 | ClassExpression |
440424e2 | 1549 | : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } |
fb98ac0c JF |
1550 | ; |
1551 | ||
1552 | ClassStatement | |
cfd73c6d | 1553 | : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } |
1ba6903e JF |
1554 | ; |
1555 | ||
1556 | CategoryName | |
a630a9eb | 1557 | : "(" WordOpt ")" |
367eebb1 JF |
1558 | ; |
1559 | ||
1560 | CategoryStatement | |
3ea7eed0 | 1561 | : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } |
367eebb1 JF |
1562 | ; |
1563 | ||
3ea7eed0 | 1564 | PrimaryExpression |
fb98ac0c | 1565 | : ClassExpression { $$ = $1; } |
367eebb1 JF |
1566 | ; |
1567 | ||
3ea7eed0 | 1568 | Statement__ |
fb98ac0c | 1569 | : ClassStatement { $$ = $1; } |
365abb0a | 1570 | | CategoryStatement { $$ = $1; } |
b09da87b | 1571 | ; |
cac61857 | 1572 | /* }}} */ |
4de0686f | 1573 | /* Cycript (Objective-C): Send Message {{{ */ |
693d501b | 1574 | VariadicCall |
2eb8215d | 1575 | : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); } |
693d501b JF |
1576 | | { $$ = NULL; } |
1577 | ; | |
1578 | ||
7e5391fd JF |
1579 | SelectorWordOpt |
1580 | : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; } | |
1581 | | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; } | |
1582 | ; | |
1583 | ||
55fc1817 JF |
1584 | SelectorCall_ |
1585 | : SelectorCall { $$ = $1; } | |
1586 | | VariadicCall { $$ = $1; } | |
1587 | ; | |
1588 | ||
693d501b | 1589 | SelectorCall |
2eb8215d | 1590 | : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); } |
693d501b JF |
1591 | ; |
1592 | ||
1593 | SelectorList | |
1594 | : SelectorCall { $$ = $1; } | |
2eb8215d | 1595 | | Word { $$ = CYNew CYArgument($1, NULL); } |
693d501b JF |
1596 | ; |
1597 | ||
1598 | MessageExpression | |
440424e2 JF |
1599 | : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } |
1600 | | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); } | |
693d501b JF |
1601 | ; |
1602 | ||
e7ed5354 | 1603 | SelectorExpression_ |
2eb8215d | 1604 | : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); } |
e7ed5354 JF |
1605 | ; |
1606 | ||
1607 | SelectorExpression | |
1608 | : SelectorExpression_ { $$ = $1; } | |
2eb8215d | 1609 | | Word { $$ = CYNew CYSelectorPart($1, false, NULL); } |
e7ed5354 JF |
1610 | ; |
1611 | ||
55fc1817 JF |
1612 | SelectorExpressionOpt |
1613 | : SelectorExpression_ { $$ = $1; } | |
1614 | | { $$ = NULL; } | |
1615 | ; | |
1616 | ||
3ea7eed0 | 1617 | PrimaryExpression |
693d501b | 1618 | : MessageExpression { $$ = $1; } |
440424e2 | 1619 | | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); } |
693d501b JF |
1620 | ; |
1621 | /* }}} */ | |
7b750785 JF |
1622 | @end |
1623 | ||
1624 | /* Cycript: @import Directive {{{ */ | |
417dcc12 JF |
1625 | Module |
1626 | : Module "." Word { $$ = CYNew CYModule($3, $1); } | |
1627 | | Word { $$ = CYNew CYModule($1); } | |
1ba6903e JF |
1628 | ; |
1629 | ||
417dcc12 JF |
1630 | Declaration__ |
1631 | : "@import" Module { $$ = CYNew CYImport($2); } | |
1ba6903e JF |
1632 | ; |
1633 | /* }}} */ | |
7b750785 JF |
1634 | |
1635 | @begin ObjectiveC | |
c3b144b8 JF |
1636 | /* Cycript (Objective-C): Boxed Expressions {{{ */ |
1637 | BoxableExpression | |
1638 | : NullLiteral { $$ = $1; } | |
1639 | | BooleanLiteral { $$ = $1; } | |
1640 | | NumericLiteral { $$ = $1; } | |
1641 | | StringLiteral { $$ = $1; } | |
1642 | | ArrayLiteral { $$ = $1; } | |
1643 | | ObjectLiteral { $$ = $1; } | |
1644 | | Parenthetical { $$ = $1; } | |
60496dd5 JF |
1645 | | "YES" { $$ = CYNew CYTrue(); } |
1646 | | "NO" { $$ = CYNew CYFalse(); } | |
c3b144b8 JF |
1647 | ; |
1648 | ||
1649 | PrimaryExpression | |
1650 | : "@" BoxableExpression { $$ = CYNew CYBox($2); } | |
4ea461c0 JF |
1651 | | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); } |
1652 | | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); } | |
1653 | | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); } | |
1654 | | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); } | |
1655 | | "@null" { $$ = CYNew CYBox(CYNew CYNull()); } | |
c3b144b8 JF |
1656 | ; |
1657 | /* }}} */ | |
56e02e5b | 1658 | /* Cycript (Objective-C): Block Expressions {{{ */ |
56e02e5b | 1659 | PrimaryExpression |
00b4cb83 | 1660 | : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); } |
56e02e5b JF |
1661 | ; |
1662 | /* }}} */ | |
61769f4f JF |
1663 | /* Cycript (Objective-C): Instance Literals {{{ */ |
1664 | PrimaryExpression | |
ac9d4181 | 1665 | : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); } |
61769f4f JF |
1666 | ; |
1667 | /* }}} */ | |
4de0686f JF |
1668 | @end |
1669 | ||
1670 | @begin C | |
1671 | /* Cycript (C): Pointer Indirection/Addressing {{{ */ | |
9465b86d JF |
1672 | LeftHandSideExpression |
1673 | : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); } | |
693d501b JF |
1674 | ; |
1675 | ||
1676 | UnaryExpression_ | |
2eb8215d | 1677 | : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); } |
693d501b JF |
1678 | ; |
1679 | ||
9b5527f0 | 1680 | MemberAccess |
2eb8215d | 1681 | : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); } |
5ccfc586 | 1682 | | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); } |
7e5391fd | 1683 | | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; } |
9b5527f0 | 1684 | ; |
cac61857 | 1685 | /* }}} */ |
a87d7060 JF |
1686 | /* Cycript (C): auto Compatibility {{{ */ |
1687 | Var_ | |
1688 | : "auto" | |
1689 | ; | |
1690 | /* }}} */ | |
690cf1a8 JF |
1691 | /* Cycript (C): Lambda Expressions {{{ */ |
1692 | TypedParameterList_ | |
1693 | : "," TypedParameterList { $$ = $2; } | |
1694 | | { $$ = NULL; } | |
1695 | ; | |
1696 | ||
1697 | TypedParameterList | |
1698 | : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); } | |
1699 | ; | |
1700 | ||
1701 | TypedParameterListOpt | |
1702 | : TypedParameterList { $$ = $1; } | |
1703 | | { $$ = NULL; } | |
1704 | ; | |
1705 | ||
1706 | PrimaryExpression | |
9a39f705 | 1707 | : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); } |
690cf1a8 JF |
1708 | ; |
1709 | /* }}} */ | |
60097023 JF |
1710 | /* Cycript (C): Type Definitions {{{ */ |
1711 | Statement__ | |
00b4cb83 | 1712 | : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); } |
60097023 JF |
1713 | ; |
1714 | /* }}} */ | |
c5587ed7 JF |
1715 | /* Cycript (C): extern "C" {{{ */ |
1716 | Statement__ | |
44fc505c | 1717 | : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); } |
c5587ed7 JF |
1718 | ; |
1719 | /* }}} */ | |
1720 | ||
4de0686f JF |
1721 | @end |
1722 | ||
320ce753 | 1723 | /* YUI: Documentation Comments {{{ */ |
3ea7eed0 | 1724 | Statement__ |
320ce753 JF |
1725 | : Comment { $$ = $1; } |
1726 | ; | |
1727 | /* }}} */ | |
1728 | ||
cb02f8ae | 1729 | @begin E4X |
691e4717 JF |
1730 | /* Lexer State {{{ */ |
1731 | LexPushRegExp | |
1732 | : { driver.PushCondition(CYDriver::RegExpCondition); } | |
1733 | ; | |
1734 | ||
1735 | LexPushXMLContent | |
1736 | : { driver.PushCondition(CYDriver::XMLContentCondition); } | |
1737 | ; | |
1738 | ||
1739 | LexPushXMLTag | |
1740 | : { driver.PushCondition(CYDriver::XMLTagCondition); } | |
1741 | ; | |
1742 | ||
1743 | LexPop | |
1744 | : { driver.PopCondition(); } | |
1745 | ; | |
1746 | ||
1747 | LexSetXMLContent | |
1748 | : { driver.SetCondition(CYDriver::XMLContentCondition); } | |
1749 | ; | |
1750 | ||
1751 | LexSetXMLTag | |
1752 | : { driver.SetCondition(CYDriver::XMLTagCondition); } | |
1753 | ; | |
1754 | /* }}} */ | |
c3b144b8 | 1755 | /* Virtual Tokens {{{ */ |
691e4717 JF |
1756 | XMLWhitespaceOpt |
1757 | : XMLWhitespace | |
1758 | | | |
1759 | ; | |
c3b144b8 | 1760 | /* }}} */ |
691e4717 JF |
1761 | |
1762 | /* 8.1 Context Keywords {{{ */ | |
1763 | Identifier | |
1764 | : "namespace" { $$ = $1; } | |
1765 | | "xml" { $$ = $1; } | |
1766 | ; | |
1767 | /* }}} */ | |
cb02f8ae JF |
1768 | /* 8.3 XML Initialiser Input Elements {{{ */ |
1769 | XMLMarkup | |
691e4717 JF |
1770 | : XMLComment { $$ = $1; } |
1771 | | XMLCDATA { $$ = $1; } | |
1772 | | XMLPI { $$ = $1; } | |
cb02f8ae JF |
1773 | ; |
1774 | /* }}} */ | |
c3b144b8 | 1775 | |
cb02f8ae | 1776 | /* 11.1 Primary Expressions {{{ */ |
3ea7eed0 | 1777 | PrimaryExpression |
2eb8215d | 1778 | : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); } |
691e4717 JF |
1779 | | XMLInitialiser { $$ = $1; } |
1780 | | XMLListInitialiser { $$ = $1; } | |
cb02f8ae JF |
1781 | ; |
1782 | ||
1783 | PropertyIdentifier | |
691e4717 JF |
1784 | : AttributeIdentifier { $$ = $1; } |
1785 | | QualifiedIdentifier { $$ = $1; } | |
1786 | | WildcardIdentifier { $$ = $1; } | |
cb02f8ae JF |
1787 | ; |
1788 | /* }}} */ | |
1789 | /* 11.1.1 Attribute Identifiers {{{ */ | |
1790 | AttributeIdentifier | |
2eb8215d | 1791 | : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); } |
691e4717 JF |
1792 | ; |
1793 | ||
1794 | PropertySelector_ | |
b92ceddb | 1795 | : PropertySelector { $$ = $1; } |
440424e2 | 1796 | | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); } |
cb02f8ae JF |
1797 | ; |
1798 | ||
1799 | PropertySelector | |
2eb8215d | 1800 | : Identifier { $$ = CYNew CYSelector($1); } |
691e4717 | 1801 | | WildcardIdentifier { $$ = $1; } |
cb02f8ae JF |
1802 | ; |
1803 | /* }}} */ | |
1804 | /* 11.1.2 Qualified Identifiers {{{ */ | |
691e4717 | 1805 | QualifiedIdentifier_ |
2eb8215d | 1806 | : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); } |
691e4717 JF |
1807 | | QualifiedIdentifier { $$ = $1; } |
1808 | ; | |
1809 | ||
cb02f8ae | 1810 | QualifiedIdentifier |
2eb8215d | 1811 | : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); } |
cb02f8ae JF |
1812 | ; |
1813 | /* }}} */ | |
1814 | /* 11.1.3 Wildcard Identifiers {{{ */ | |
1815 | WildcardIdentifier | |
2eb8215d | 1816 | : "*" { $$ = CYNew CYWildcard(); } |
cb02f8ae JF |
1817 | ; |
1818 | /* }}} */ | |
1819 | /* 11.1.4 XML Initialiser {{{ */ | |
1820 | XMLInitialiser | |
691e4717 JF |
1821 | : XMLMarkup { $$ = $1; } |
1822 | | XMLElement { $$ = $1; } | |
cb02f8ae JF |
1823 | ; |
1824 | ||
1825 | XMLElement | |
440424e2 JF |
1826 | : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn |
1827 | | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn | |
cb02f8ae JF |
1828 | ; |
1829 | ||
1830 | XMLTagContent | |
0347fadf | 1831 | : LexPushXMLTag XMLTagName XMLAttributes |
cb02f8ae JF |
1832 | ; |
1833 | ||
691e4717 | 1834 | XMLExpression |
3ea7eed0 | 1835 | : BRACE LexPushRegExp Expression LexPop "}" |
691e4717 JF |
1836 | ; |
1837 | ||
cb02f8ae | 1838 | XMLTagName |
691e4717 | 1839 | : XMLExpression |
cb02f8ae JF |
1840 | | XMLName |
1841 | ; | |
1842 | ||
0347fadf JF |
1843 | XMLAttributes_ |
1844 | : XMLAttributes_ XMLAttribute | |
1845 | | | |
cb02f8ae JF |
1846 | ; |
1847 | ||
0347fadf JF |
1848 | XMLAttributes |
1849 | : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt | |
1850 | | XMLAttributes_ XMLWhitespaceOpt | |
cb02f8ae JF |
1851 | ; |
1852 | ||
691e4717 JF |
1853 | XMLAttributeValue_ |
1854 | : XMLExpression | |
1855 | | XMLAttributeValue | |
1856 | ; | |
1857 | ||
cb02f8ae | 1858 | XMLAttribute |
691e4717 | 1859 | : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_ |
cb02f8ae JF |
1860 | ; |
1861 | ||
cb02f8ae | 1862 | XMLElementContent |
691e4717 | 1863 | : XMLExpression XMLElementContentOpt |
cb02f8ae JF |
1864 | | XMLMarkup XMLElementContentOpt |
1865 | | XMLText XMLElementContentOpt | |
1866 | | XMLElement XMLElementContentOpt | |
1867 | ; | |
1868 | ||
1869 | XMLElementContentOpt | |
1870 | : XMLElementContent | |
1871 | | | |
1872 | ; | |
1873 | /* }}} */ | |
1874 | /* 11.1.5 XMLList Initialiser {{{ */ | |
1875 | XMLListInitialiser | |
440424e2 | 1876 | : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); } |
691e4717 JF |
1877 | ; |
1878 | /* }}} */ | |
c3b144b8 | 1879 | |
691e4717 JF |
1880 | /* 11.2 Left-Hand-Side Expressions {{{ */ |
1881 | PropertyIdentifier_ | |
0347fadf | 1882 | : Identifier { $$ = $1; } |
691e4717 JF |
1883 | | PropertyIdentifier { $$ = $1; } |
1884 | ; | |
1885 | ||
1886 | MemberAccess | |
2eb8215d JF |
1887 | : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); } |
1888 | | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); } | |
1889 | | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); } | |
691e4717 JF |
1890 | ; |
1891 | /* }}} */ | |
1892 | /* 12.1 The default xml namespace Statement {{{ */ | |
b92ceddb | 1893 | /* XXX: DefaultXMLNamespaceStatement |
2eb8215d | 1894 | : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); } |
691e4717 JF |
1895 | ; |
1896 | ||
3ea7eed0 | 1897 | Statement__ |
691e4717 | 1898 | : DefaultXMLNamespaceStatement { $$ = $1; } |
b92ceddb | 1899 | ; */ |
cb02f8ae JF |
1900 | /* }}} */ |
1901 | @end | |
1902 | ||
cac61857 | 1903 | /* JavaScript 1.7: Array Comprehensions {{{ */ |
b3aa25d8 JF |
1904 | Comprehension |
1905 | : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); } | |
367eebb1 JF |
1906 | ; |
1907 | ||
b3aa25d8 JF |
1908 | ComprehensionFor |
1909 | : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); } | |
1910 | | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); } | |
367eebb1 | 1911 | ; |
cac61857 JF |
1912 | /* }}} */ |
1913 | /* JavaScript 1.7: for each {{{ */ | |
d5618df7 | 1914 | IterationStatement |
440424e2 | 1915 | : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); } |
cac61857 JF |
1916 | ; |
1917 | /* }}} */ | |
15b88a33 | 1918 | /* JavaScript 1.7: let Statements {{{ */ |
cac61857 | 1919 | LetStatement |
c8a0500b | 1920 | : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } |
cac61857 JF |
1921 | ; |
1922 | ||
3ea7eed0 | 1923 | Statement__ |
cac61857 JF |
1924 | : LetStatement |
1925 | ; | |
15b88a33 | 1926 | /* }}} */ |
4e11a430 | 1927 | |
6c093cce JF |
1928 | /* JavaScript FTW: Ruby Blocks {{{ */ |
1929 | RubyProcParameterList_ | |
1930 | : "," RubyProcParameterList { $$ = $2; } | |
1931 | | { $$ = NULL; } | |
1932 | ; | |
1933 | ||
1934 | RubyProcParameterList | |
c8a0500b | 1935 | : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); } |
6c093cce JF |
1936 | | { $$ = NULL; } |
1937 | ; | |
1938 | ||
d7205a63 | 1939 | RubyProcParameters |
6c093cce | 1940 | : "|" RubyProcParameterList "|" { $$ = $2; } |
d7205a63 JF |
1941 | | "||" { $$ = NULL; } |
1942 | ; | |
1943 | ||
1944 | RubyProcParametersOpt | |
1945 | : RubyProcParameters | |
6c093cce JF |
1946 | | { $$ = NULL; } |
1947 | ; | |
1948 | ||
1949 | RubyProcExpression | |
2eb8215d | 1950 | : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } |
6c093cce JF |
1951 | ; |
1952 | ||
3ea7eed0 | 1953 | PrimaryExpression |
440424e2 | 1954 | : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); } |
6c093cce JF |
1955 | ; |
1956 | ||
3ea7eed0 JF |
1957 | CallExpression |
1958 | : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } | |
6c093cce | 1959 | ; |
6c093cce | 1960 | /* }}} */ |
367eebb1 | 1961 | |
e5332278 | 1962 | %% |