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