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