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