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