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