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