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