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