X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/feac356a1c2fa442ab70e9ea3e4f058a8f3e17ed..620c82a1d5e2c350acdfa2f3622cdb5c04cbe525:/Parser.ypp.in?ds=inline diff --git a/Parser.ypp.in b/Parser.ypp.in index 2a00d69..7d12aa2 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -42,11 +42,13 @@ %union { bool bool_; } +%union { CYMember *access_; } %union { CYArgument *argument_; } %union { CYAssignment *assignment_; } %union { CYBoolean *boolean_; } %union { CYClause *clause_; } %union { cy::Syntax::Catch *catch_; } +%union { CYClassTail *classTail_; } %union { CYComprehension *comprehension_; } %union { CYDeclaration *declaration_; } %union { CYDeclarations *declarations_; } @@ -61,7 +63,7 @@ %union { CYIdentifier *identifier_; } %union { CYInfix *infix_; } %union { CYLiteral *literal_; } -%union { CYMember *member_; } +%union { CYMethod *method_; } %union { CYModule *module_; } %union { CYNull *null_; } %union { CYNumber *number_; } @@ -72,6 +74,7 @@ %union { CYSpan *span_; } %union { CYStatement *statement_; } %union { CYString *string_; } +%union { CYTarget *target_; } %union { CYThis *this_; } %union { CYTrue *true_; } %union { CYWord *word_; } @@ -84,10 +87,9 @@ @end @begin ObjectiveC -%union { CYClassName *className_; } -%union { CYClassField *classField_; } %union { CYMessage *message_; } %union { CYMessageParameter *messageParameter_; } +%union { CYImplementationField *implementationField_; } %union { CYProtocol *protocol_; } %union { CYSelectorPart *selector_; } @end @@ -111,6 +113,8 @@ int cylex(YYSTYPE *, CYLocation *, void *); %code { +typedef cy::parser::token tk; + #undef yylex _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) { if (driver.mark_ == CYMarkIgnore); @@ -122,19 +126,66 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY return cy::parser::token::MarkModule; } + lex: + if (driver.newline_ == CYDriver::NewLineHere) + driver.newline_ = CYDriver::NewLineLast; + else if (driver.newline_ == CYDriver::NewLineLast) + driver.newline_ = CYDriver::NewLineNone; + YYSTYPE data; int token(cylex(&data, location, driver.scanner_)); *semantic = data.semantic_; + + switch (token) { + case tk::_in_: + if (driver.in_.top()) + token = tk::_in__; + break; + + case tk::_yield_: + if (driver.yield_.top()) + token = tk::_yield__; + break; + + case tk::HyphenHyphen: + if (driver.newline_ == CYDriver::NewLineLast) + token = tk::HyphenHyphen_; + break; + + case tk::NewLine: + driver.newline_ = CYDriver::NewLineHere; + if (!driver.next_) + goto lex; + break; + + case tk::PlusPlus: + if (driver.newline_ == CYDriver::NewLineLast) + token = tk::PlusPlus_; + break; + } + + driver.next_ = false; return token; } +#define CYLEX() do if (yyla.empty()) { \ + YYCDEBUG << "Mapping a token: "; \ + yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + YY_SYMBOL_PRINT("Next token is", yyla); \ +} while (false) + #define CYMAP(to, from) do { \ - if (yyla.empty()) \ - yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + CYLEX(); \ if (yyla.type == yytranslate_(token::from)) \ yyla.type = yytranslate_(token::to); \ } while (false) +#define CYLIN(from) do { \ + CYLEX(); \ + if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \ + yyla.type = yytranslate_(token::from ## _); \ +} while (false) + #define CYERR(location, message) do { \ error(location, message); \ YYABORT; \ @@ -316,12 +367,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _import_ "import" %token _in_ "in" %token _in__ "!in" +%token _Infinity_ "Infinity" %token _instanceof_ "instanceof" %token _new_ "new" %token _return_ "return" -%token _return__ "!return" %token _super_ "super" %token _switch_ "switch" +%token _target_ "target" %token _this_ "this" %token _throw_ "throw" %token _try_ "try" @@ -336,7 +388,9 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _boolean_ "boolean" %token _byte_ "byte" %token _char_ "char" +%token _constructor_ "constructor" %token _double_ "double" +%token _eval_ "eval" %token _final_ "final" %token _float_ "float" %token _from_ "from" @@ -351,6 +405,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _package_ "package" %token _private_ "private" %token _protected_ "protected" +%token _prototype_ "prototype" %token _public_ "public" %token _set_ "set" %token _short_ "short" @@ -395,12 +450,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token TemplateMiddle %token TemplateTail +%type AccessExpression %type AdditiveExpression %type ArgumentList_ %type ArgumentList %type ArgumentListOpt %type Arguments -%type ArrayComprehension +%type ArrayComprehension %type ArrayLiteral %type ArrowFunction %type ArrowParameters @@ -420,19 +476,22 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type BreakStatement %type BreakableStatement %type CallExpression_ -%type CallExpression +%type CallExpression %type CaseBlock %type CaseClause %type CaseClausesOpt %type Catch %type CatchParameter %type ClassDeclaration -%type ClassExpression -%type Comprehension +%type ClassExpression +%type ClassHeritage +%type ClassHeritageOpt +%type ClassTail +%type Comprehension %type ComprehensionFor %type ComprehensionIf %type ComprehensionTail -%type ComputedPropertyName +%type ComputedPropertyName %type ConditionalExpression %type ContinueStatement %type ConciseBody @@ -445,14 +504,15 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type ElementList %type ElementListOpt %type ElseStatementOpt -%type EmptyStatement +%type EmptyStatement %type EqualityExpression %type Expression %type ExpressionOpt +%type ExpressionStatement_ %type ExpressionStatement %type Finally %type ForBinding -%type ForDeclaration +%type ForDeclaration %type ForInStatementInitializer %type ForStatementInitializer %type FormalParameter @@ -461,42 +521,45 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type FormalParameters %type FunctionBody %type FunctionDeclaration -%type FunctionExpression +%type FunctionExpression %type FunctionStatementList %type GeneratorBody %type GeneratorDeclaration -%type GeneratorExpression -%type GeneratorMethod +%type GeneratorExpression +%type GeneratorMethod %type HoistableDeclaration %type Identifier %type IdentifierType %type IdentifierName %type IdentifierReference %type IfStatement +%type IndirectExpression %type Initializer %type InitializerOpt %type IterationStatement %type LabelIdentifier %type LabelledItem %type LabelledStatement -%type LeftHandSideExpression -%type LetStatement +%type LeftHandSideAssignment +%type LeftHandSideExpression +%type LetOrConst %type LexicalBinding +%type LexicalDeclaration_ %type LexicalDeclaration %type Literal %type LiteralPropertyName %type LogicalANDExpression %type LogicalORExpression -%type MemberAccess -%type MemberExpression -%type MethodDefinition +%type MemberAccess +%type MemberExpression +%type MethodDefinition %type ModulePath %type MultiplicativeExpression -%type NewExpression +%type NewExpression %type NullLiteral %type ObjectLiteral %type PostfixExpression -%type PrimaryExpression +%type PrimaryExpression %type PropertyName %type PropertyDefinition %type PropertyDefinitionList_ @@ -522,8 +585,10 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type StatementListOpt %type StatementListItem %type StrictFormalParameters +%type SuperCall +%type SuperProperty %type SwitchStatement -%type TemplateLiteral +%type TemplateLiteral %type TemplateSpans %type ThrowStatement %type TryStatement @@ -532,6 +597,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type VariableDeclaration %type VariableDeclarationList_ %type VariableDeclarationList +%type VariableStatement_ %type VariableStatement %type WithStatement %type Word @@ -556,19 +622,20 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end @begin ObjectiveC +%type AssignmentExpressionClassic %type BoxableExpression %type CategoryStatement -%type ClassFieldListOpt -%type ClassFields -%type ClassStatement %type ClassSuperOpt +%type ConditionalExpressionClassic +%type ImplementationFieldListOpt +%type ImplementationFields %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt -%type ClassName %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt -%type MessageExpression +%type ImplementationStatement +%type MessageExpression %type MessageParameter %type MessageParameters %type MessageParameterList @@ -608,7 +675,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY /* }}} */ /* Token Priorities {{{ */ %nonassoc "" -%left "++" "--" "{" +%left "{" %nonassoc "if" %nonassoc "else" @@ -633,12 +700,16 @@ LexPopIn: { driver.in_.pop(); }; LexPushReturnOn: { driver.return_.push(true); }; LexPopReturn: { driver.return_.pop(); }; +LexPushSuperOn: { driver.super_.push(true); }; +LexPushSuperOff: { driver.super_.push(false); }; +LexPopSuper: { driver.super_.pop(); }; + LexPushYieldOn: { driver.yield_.push(true); }; LexPushYieldOff: { driver.yield_.push(false); }; LexPopYield: { driver.yield_.pop(); }; LexSetRegExp - : { driver.SetCondition(CYDriver::RegExpCondition); } + : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } ; LexNewLine @@ -716,7 +787,6 @@ Word | "new" LexSetRegExp { $$ = CYNew CYWord("new"); } | "null" { $$ = CYNew CYWord("null"); } | "return" { $$ = CYNew CYWord("return"); } - | "!return" { $$ = CYNew CYWord("return"); } | "super" { $$ = CYNew CYWord("super"); } | "switch" { $$ = CYNew CYWord("switch"); } | "this" { $$ = CYNew CYWord("this"); } @@ -767,7 +837,7 @@ TerminatorSoft Terminator : ";" - | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi + | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi ; TerminatorOpt @@ -803,23 +873,31 @@ IdentifierType | "await" { $$ = CYNew CYIdentifier("await"); } | "boolean" { $$ = CYNew CYIdentifier("boolean"); } | "byte" { $$ = CYNew CYIdentifier("byte"); } + | "constructor" { $$ = CYNew CYIdentifier("constructor"); } | "double" { $$ = CYNew CYIdentifier("double"); } | "each" { $$ = CYNew CYIdentifier("each"); } + | "eval" { $$ = CYNew CYIdentifier("eval"); } | "final" { $$ = CYNew CYIdentifier("final"); } | "float" { $$ = CYNew CYIdentifier("float"); } + | "from" { $$ = CYNew CYIdentifier("from"); } + | "get" { $$ = CYNew CYIdentifier("get"); } | "goto" { $$ = CYNew CYIdentifier("goto"); } | "implements" { $$ = CYNew CYIdentifier("implements"); } + | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } | "interface" { $$ = CYNew CYIdentifier("interface"); } | "native" { $$ = CYNew CYIdentifier("native"); } | "of" { $$ = CYNew CYIdentifier("of"); } | "package" { $$ = CYNew CYIdentifier("package"); } | "private" { $$ = CYNew CYIdentifier("private"); } | "protected" { $$ = CYNew CYIdentifier("protected"); } + | "prototype" { $$ = CYNew CYIdentifier("prototype"); } | "public" { $$ = CYNew CYIdentifier("public"); } - | "static" { $$ = CYNew CYIdentifier("static"); } + | "set" { $$ = CYNew CYIdentifier("set"); } | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); } + | "target" { $$ = CYNew CYIdentifier("target"); } | "throws" { $$ = CYNew CYIdentifier("throws"); } | "transient" { $$ = CYNew CYIdentifier("transient"); } + | "undefined" { $$ = CYNew CYIdentifier("undefined"); } @begin ObjectiveC | "bool" { $$ = CYNew CYIdentifier("bool"); } | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); } @@ -831,13 +909,10 @@ IdentifierType Identifier : IdentifierType | "char" { $$ = CYNew CYIdentifier("char"); } - | "from" { $$ = CYNew CYIdentifier("from"); } - | "get" { $$ = CYNew CYIdentifier("get"); } | "int" { $$ = CYNew CYIdentifier("int"); } | "long" { $$ = CYNew CYIdentifier("long"); } - | "set" { $$ = CYNew CYIdentifier("set"); } | "short" { $$ = CYNew CYIdentifier("short"); } - | "undefined" { $$ = CYNew CYIdentifier("undefined"); } + | "static" { $$ = CYNew CYIdentifier("static"); } | "volatile" { $$ = CYNew CYIdentifier("volatile"); } @begin C | "extern" { $$ = CYNew CYIdentifier("extern"); } @@ -920,15 +995,15 @@ PropertyDefinitionListOpt ; PropertyDefinition - : IdentifierReference { $$ = CYNew CYProperty($1->name_, $1); } + : IdentifierReference { $$ = CYNew CYPropertyValue($1->name_, $1); } | CoverInitializedName { CYNOT(@$); } - | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); } + | PropertyName ":" AssignmentExpression { $$ = CYNew CYPropertyValue($1, $3); } | MethodDefinition { $$ = $1; } ; PropertyName : LiteralPropertyName { $$ = $1; } - | ComputedPropertyName { CYNOT(@$); /* $$ = $1; */ } + | ComputedPropertyName { $$ = $1; } ; LiteralPropertyName @@ -938,7 +1013,7 @@ LiteralPropertyName ; ComputedPropertyName - : "[" AssignmentExpression "]" { $$ = $2; } + : "[" AssignmentExpression "]" { $$ = CYNew CYComputed($2); } ; CoverInitializedName @@ -977,14 +1052,14 @@ MemberAccess MemberExpression : LexSetRegExp PrimaryExpression { $$ = $2; } | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - | SuperProperty { CYNOT(@$); } + | SuperProperty { $$ = $1; } | MetaProperty { CYNOT(@$); } | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); } ; SuperProperty - : LexSetRegExp "super" "[" Expression "]" - | LexSetRegExp "super" "." IdentifierName + : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "[" Expression "]" { $$ = CYNew CYSuperAccess($5); } + | LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($5)); } ; MetaProperty @@ -1001,18 +1076,18 @@ NewExpression ; CallExpression_ - : MemberExpression - | CallExpression + : MemberExpression { $$ = $1; } + | CallExpression { $$ = $1; } ; CallExpression - : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); } - | SuperCall { CYNOT(@$); } + : CallExpression_ Arguments { if (!$1->Eval()) $$ = CYNew CYCall($1, $2); else $$ = CYNew CYEval($2); } + | SuperCall { $$ = $1; } | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } ; SuperCall - : LexSetRegExp "super" Arguments + : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); } ; Arguments @@ -1034,16 +1109,21 @@ ArgumentListOpt | LexSetRegExp { $$ = NULL; } ; -LeftHandSideExpression +AccessExpression : NewExpression { $$ = $1; } | CallExpression { $$ = $1; } ; + +LeftHandSideExpression + : AccessExpression { $$ = $1; } + | LexSetRegExp IndirectExpression { $$ = $2; } + ; /* }}} */ /* 12.4 Postfix Expressions {{{ */ PostfixExpression - : %prec "" LeftHandSideExpression { $$ = $1; } - | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); } - | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); } + : AccessExpression { $$ = $1; } + | AccessExpression "++" { $$ = CYNew CYPostIncrement($1); } + | AccessExpression "--" { $$ = CYNew CYPostDecrement($1); } ; /* }}} */ /* 12.5 Unary Operators {{{ */ @@ -1062,7 +1142,7 @@ UnaryExpression_ ; UnaryExpression - : PostfixExpression { $$ = $1; } + : %prec "" PostfixExpression LexOpenBrace { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; /* }}} */ @@ -1137,28 +1217,46 @@ LogicalORExpression ; /* }}} */ /* 12.13 Conditional Operator ( ? : ) {{{ */ +@begin ObjectiveC +ConditionalExpressionClassic + : LogicalORExpression { $$ = $1; } + | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpressionClassic { $$ = CYNew CYCondition($1, $4, $7); } + ; +@end + ConditionalExpression : LogicalORExpression { $$ = $1; } | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); } ; /* }}} */ /* 12.14 Assignment Operators {{{ */ +LeftHandSideAssignment + : LeftHandSideExpression "=" { $$ = CYNew CYAssign($1, NULL); } + | LeftHandSideExpression "*=" { $$ = CYNew CYMultiplyAssign($1, NULL); } + | LeftHandSideExpression "/=" { $$ = CYNew CYDivideAssign($1, NULL); } + | LeftHandSideExpression "%=" { $$ = CYNew CYModulusAssign($1, NULL); } + | LeftHandSideExpression "+=" { $$ = CYNew CYAddAssign($1, NULL); } + | LeftHandSideExpression "-=" { $$ = CYNew CYSubtractAssign($1, NULL); } + | LeftHandSideExpression "<<=" { $$ = CYNew CYShiftLeftAssign($1, NULL); } + | LeftHandSideExpression ">>=" { $$ = CYNew CYShiftRightSignedAssign($1, NULL); } + | LeftHandSideExpression ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($1, NULL); } + | LeftHandSideExpression "&=" { $$ = CYNew CYBitwiseAndAssign($1, NULL); } + | LeftHandSideExpression "^=" { $$ = CYNew CYBitwiseXOrAssign($1, NULL); } + | LeftHandSideExpression "|=" { $$ = CYNew CYBitwiseOrAssign($1, NULL); } + ; + +@begin ObjectiveC +AssignmentExpressionClassic + : ConditionalExpressionClassic { $$ = $1; } + | LeftHandSideAssignment AssignmentExpressionClassic { $1->SetRight($2); $$ = $1; } + ; +@end + AssignmentExpression : ConditionalExpression { $$ = $1; } | LexSetRegExp YieldExpression { $$ = $2; } | ArrowFunction { $$ = $1; } - | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); } - | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); } - | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); } - | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); } - | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); } - | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); } - | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); } - | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); } - | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); } - | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); } - | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); } - | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); } + | LeftHandSideAssignment AssignmentExpression { $1->SetRight($2); $$ = $1; } ; AssignmentExpressionOpt @@ -1252,13 +1350,17 @@ StatementListItem ; /* }}} */ /* 13.3 Let and Const Declarations {{{ */ +LexicalDeclaration_ + : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); } + ; + LexicalDeclaration - : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); } + : LexicalDeclaration_ Terminator { $$ = $1; } ; LetOrConst - : "let" - | "const" + : "let" { $$ = false; } + | "const" { $$ = true; } ; BindingList_ @@ -1276,8 +1378,12 @@ LexicalBinding ; /* }}} */ /* 13.3.2 Variable Statement {{{ */ +VariableStatement_ + : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); } + ; + VariableStatement - : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } + : VariableStatement_ Terminator { $$ = $1; } ; VariableDeclarationList_ @@ -1346,8 +1452,11 @@ EmptyStatement ; /* }}} */ /* 13.5 Expression Statement {{{ */ +ExpressionStatement_ + : Expression { $$ = CYNew CYExpress($1); } + ExpressionStatement - : Expression Terminator { $$ = CYNew CYExpress($1); } + : ExpressionStatement_ Terminator { $$ = $1; } ; /* }}} */ /* 13.6 The if Statement {{{ */ @@ -1364,25 +1473,28 @@ IfStatement IterationStatement : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); } | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); } - | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); } + | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); } + | "for" "(" LexPushInOn LexSetRegExp Var_ BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($6, $7), $10, $12); } | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); } - | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } + | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } ; ForStatementInitializer - : ExpressionOpt { $$ = $1; } - | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); } - | LexSetRegExp LexicalDeclaration { CYNOT(@$); } + : LexSetRegExp EmptyStatement { $$ = $2; } + | ExpressionStatement_ ";" { $$ = $1; } + | LexSetRegExp VariableStatement_ ";" { $$ = $2; } + | LexSetRegExp LexicalDeclaration_ ";" { $$ = $2; } ; ForInStatementInitializer - : LeftHandSideExpression { $$ = $1; } - | LexSetRegExp Var_ ForBinding { $$ = $3; } + : AccessExpression { $$ = $1; } + | LexSetRegExp IndirectExpression { $$ = $2; } + | LexSetRegExp Var_ ForBinding { $$ = CYNew CYForVariable($3); } | LexSetRegExp ForDeclaration { $$ = $2; } ; ForDeclaration - : LetOrConst ForBinding { $$ = $2; } + : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); } ; ForBinding @@ -1412,7 +1524,7 @@ BreakStatement /* }}} */ /* 13.10 The return Statement {{{ */ Return - : "!return" LexNewLine + : "return" { if (!driver.return_.top()) CYERR(@1, "invalid return"); } LexNewLine ; ReturnStatement @@ -1497,11 +1609,11 @@ DebuggerStatement /* 14.1 Function Definitions {{{ */ FunctionDeclaration - : ";function" BindingIdentifier "(" FormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } + : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); } ; FunctionExpression - : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); } + : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); } ; StrictFormalParameters @@ -1540,8 +1652,12 @@ FunctionStatementList ; /* }}} */ /* 14.2 Arrow Function Definitions {{{ */ +LexEqualRight + : { CYLIN(EqualRight); } + ; + ArrowFunction - : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); } + : LexSetRegExp ArrowParameters LexEqualRight "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $6); } ; ArrowParameters @@ -1556,10 +1672,10 @@ ConciseBody /* }}} */ /* 14.3 Method Definitions {{{ */ MethodDefinition - : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYFunctionMethod($1, $3, $6); */ } + : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyMethod($1, $3, $6); } | GeneratorMethod { $$ = $1; } - | "get" PropertyName "(" ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodGet($2, $6); */ } - | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodSet($2, $4); */ } + | "get" PropertyName "(" ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyGetter($2, $6); } + | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertySetter($2, CYNew CYFunctionParameter($4), $7); } ; PropertySetParameterList @@ -1588,31 +1704,31 @@ Yield ; YieldExpression - : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } + : Yield LexSetRegExp NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ } | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ } ; /* }}} */ /* 14.5 Class Definitions {{{ */ ClassDeclaration - : ";class" BindingIdentifier ClassTail { CYNOT(@$); } + : ";class" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); } ; ClassExpression - : "class" BindingIdentifierOpt ClassTail { CYNOT(@$); } + : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); } ; ClassTail - : ClassHeritageOpt BRACE ClassBodyOpt "}" + : ClassHeritageOpt { driver.class_.push($1); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $1; } ; ClassHeritage - : "extends" LeftHandSideExpression + : "extends" LeftHandSideExpression { $$ = CYNew CYClassTail($2); } ; ClassHeritageOpt - : ClassHeritage - | + : ClassHeritage { $$ = $1; } + | { $$ = CYNew CYClassTail(NULL); } ; ClassBody @@ -1634,8 +1750,8 @@ ClassElementListOpt ; ClassElement - : MethodDefinition - | "static" MethodDefinition + : MethodDefinition { if (CYFunctionExpression *constructor = $1->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$1; } + | "static" MethodDefinition { driver.class_.top()->static_->*$2; } | ";" ; /* }}} */ @@ -1853,13 +1969,13 @@ ClassSuperOpt | { $$ = NULL; } ; -ClassFieldListOpt - : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); } +ImplementationFieldListOpt + : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); } | LexSetRegExp { $$ = NULL; } ; -ClassFields - : BRACE ClassFieldListOpt "}" { $$ = $2; } +ImplementationFields + : BRACE ImplementationFieldListOpt "}" { $$ = $2; } ; MessageScope @@ -1891,7 +2007,7 @@ MessageParameters ; ClassMessageDeclaration - : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); } + : MessageScope TypeOpt MessageParameters BRACE LexPushSuperOn FunctionBody "}" LexPopSuper { $$ = CYNew CYMessage($1, $2, $3, $6); } ; ClassMessageDeclarationListOpt @@ -1899,11 +2015,6 @@ ClassMessageDeclarationListOpt | { $$ = NULL; } ; -ClassName - : Identifier { $$ = $1; } - | "(" AssignmentExpression ")" { $$ = $2; } - ; - // XXX: this should be AssignmentExpressionNoRight ClassProtocols : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); } @@ -1919,8 +2030,8 @@ ClassProtocolListOpt | { $$ = NULL; } ; -ClassStatement - : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } +ImplementationStatement + : "@implementation" Identifier ClassSuperOpt ClassProtocolListOpt ImplementationFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYImplementation($2, $3, $4, $5, $6); } ; CategoryName @@ -1928,17 +2039,17 @@ CategoryName ; CategoryStatement - : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } + : "@implementation" Identifier CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } ; Statement__ - : ClassStatement { $$ = $1; } + : ImplementationStatement { $$ = $1; } | CategoryStatement { $$ = $1; } ; /* }}} */ /* Cycript (Objective-C): Send Message {{{ */ VariadicCall - : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); } + : "," AssignmentExpressionClassic VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); } | { $$ = NULL; } ; @@ -1953,7 +2064,7 @@ SelectorCall_ ; SelectorCall - : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); } + : SelectorWordOpt ":" AssignmentExpressionClassic SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); } ; SelectorList @@ -1962,7 +2073,7 @@ SelectorList ; MessageExpression - : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } + : "[" LexPushInOff AssignmentExpressionClassic { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); } ; @@ -2035,8 +2146,12 @@ PrimaryExpression @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ -LeftHandSideExpression - : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); } +UnaryExpression_ + : IndirectExpression { $$ = $1; } + ; + +IndirectExpression + : "*" UnaryExpression { $$ = CYNew CYIndirect($2); } ; UnaryExpression_ @@ -2266,7 +2381,7 @@ Comprehension ; ComprehensionFor - : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); } + : "for" "each" "(" LexPushInOn ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); } ; /* }}} */ /* JavaScript FTL: for each {{{ */ @@ -2274,15 +2389,6 @@ IterationStatement : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); } ; /* }}} */ -/* JavaScript FTL: let Statements {{{ */ -LetStatement - : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } - ; - -Statement__ - : LetStatement - ; -/* }}} */ /* JavaScript FTW: Array Comprehensions {{{ */ PrimaryExpression @@ -2304,8 +2410,8 @@ ComprehensionTail ; ComprehensionFor - : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } - | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); } + : "for" "(" LexPushInOn ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } + | "for" "(" LexPushInOn ForBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); } ; ComprehensionIf @@ -2340,7 +2446,11 @@ RubyProcParameters RubyProcParametersOpt : RubyProcParameters { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } + ; + +LexOpenBrace + : { CYLIN(OpenBrace); } ; RubyProcExpression @@ -2352,7 +2462,7 @@ PrimaryExpression ; PostfixExpression - : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } + : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); } ; /* }}} */