%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
+%union { CYTarget *target_; }
%union { CYThis *this_; }
%union { CYTrue *true_; }
%union { CYWord *word_; }
%code {
+typedef cy::parser::token tk;
+
#undef yylex
_finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
if (driver.mark_ == CYMarkIgnore);
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::OpenBrace:
+ case tk::OpenBracket:
+ case tk::OpenParen:
+ driver.in_.push(false);
+ break;
+
+ case tk::_in_:
+ if (driver.in_.top())
+ token = tk::_in__;
+ break;
+
+ case tk::CloseBrace:
+ case tk::CloseBracket:
+ case tk::CloseParen:
+ driver.in_.pop();
+ break;
+
+
+ case tk::_yield_:
+ if (driver.yield_.top())
+ token = tk::_yield__;
+ break;
+
+ case tk::NewLine:
+ driver.newline_ = CYDriver::NewLineHere;
+ if (!driver.next_)
+ goto lex;
+ break;
+ }
+
+ driver.next_ = false;
return token;
}
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; \
} while (false)
+#define CYEOK() do { \
+ yyerrok; \
+ driver.errors_.pop_back(); \
+} while (false)
+
#define CYNOT(location) \
CYERR(location, "unimplemented feature")
+#define CYMPT(location) do { \
+ if (!yyla.empty() && yyla.type_get() != yyeof_) \
+ CYERR(location, "unexpected lookahead"); \
+} while (false)
+
}
%name-prefix "cy"
%token OpenBrace "{"
%token OpenBrace_ "\n{"
%token OpenBrace__ ";{"
+%token OpenBrace_let "let {"
%token CloseBrace "}"
%token OpenBracket "["
+%token OpenBracket_let "let ["
%token CloseBracket "]"
%token At_error_ "@error"
%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 _super__ "!super"
%token _switch_ "switch"
+%token _target_ "target"
%token _this_ "this"
%token _throw_ "throw"
%token _try_ "try"
%token _char_ "char"
%token _constructor_ "constructor"
%token _double_ "double"
+%token _eval_ "eval"
%token _final_ "final"
%token _float_ "float"
%token _from_ "from"
%token _int_ "int"
%token _interface_ "interface"
%token _let_ "let"
+%token _let__ "!let"
%token _long_ "long"
%token _native_ "native"
%token _package_ "package"
%token _auto_ "auto"
%token _each_ "each"
%token _of_ "of"
+%token _of__ "!of"
@begin E4X
%token _namespace_ "namespace"
%token <identifier_> Identifier_
%token <number_> NumericLiteral
%token <string_> StringLiteral
-%token <literal_> RegularExpressionLiteral
+%token <literal_> RegularExpressionLiteral_
%token <string_> NoSubstitutionTemplate
%token <string_> TemplateHead
%token <string_> TemplateMiddle
%token <string_> TemplateTail
+%type <target_> AccessExpression
%type <expression_> AdditiveExpression
%type <argument_> ArgumentList_
%type <argument_> ArgumentList
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
-%type <expression_> ArrayComprehension
+%type <target_> ArrayComprehension
%type <literal_> ArrayLiteral
%type <expression_> ArrowFunction
%type <functionParameter_> ArrowParameters
%type <statement_> BreakStatement
%type <statement_> BreakableStatement
%type <expression_> CallExpression_
-%type <expression_> CallExpression
+%type <target_> CallExpression
%type <clause_> CaseBlock
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> Catch
%type <identifier_> CatchParameter
%type <statement_> ClassDeclaration
-%type <expression_> ClassExpression
+%type <target_> ClassExpression
%type <classTail_> ClassHeritage
%type <classTail_> ClassHeritageOpt
%type <classTail_> ClassTail
-%type <expression_> Comprehension
+%type <target_> Comprehension
%type <comprehension_> ComprehensionFor
%type <comprehension_> ComprehensionIf
%type <comprehension_> ComprehensionTail
%type <element_> ElementList
%type <element_> ElementListOpt
%type <statement_> ElseStatementOpt
-%type <statement_> EmptyStatement
+%type <for_> EmptyStatement
%type <expression_> EqualityExpression
%type <expression_> Expression
%type <expression_> ExpressionOpt
+%type <for_> ExpressionStatement_
%type <statement_> ExpressionStatement
%type <finally_> Finally
%type <declaration_> ForBinding
-%type <declaration_> ForDeclaration
+%type <forin_> ForDeclaration
%type <forin_> ForInStatementInitializer
%type <for_> ForStatementInitializer
%type <declaration_> FormalParameter
%type <functionParameter_> FormalParameters
%type <statement_> FunctionBody
%type <statement_> FunctionDeclaration
-%type <expression_> FunctionExpression
+%type <target_> FunctionExpression
%type <statement_> FunctionStatementList
%type <statement_> GeneratorBody
%type <statement_> GeneratorDeclaration
-%type <expression_> GeneratorExpression
+%type <target_> GeneratorExpression
%type <method_> GeneratorMethod
%type <statement_> HoistableDeclaration
%type <identifier_> Identifier
+%type <identifier_> IdentifierNoOf
%type <identifier_> IdentifierType
+%type <identifier_> IdentifierTypeNoOf
%type <word_> IdentifierName
%type <variable_> IdentifierReference
%type <statement_> IfStatement
+%type <target_> IndirectExpression
%type <expression_> Initializer
%type <expression_> InitializerOpt
%type <statement_> IterationStatement
%type <identifier_> LabelIdentifier
%type <statement_> LabelledItem
%type <statement_> LabelledStatement
-%type <expression_> LeftHandSideExpression
+%type <assignment_> LeftHandSideAssignment
+%type <target_> LeftHandSideExpression
+%type <bool_> LetOrConst
%type <declaration_> LexicalBinding
+%type <for_> LexicalDeclaration_
%type <statement_> LexicalDeclaration
%type <literal_> Literal
%type <propertyName_> LiteralPropertyName
%type <expression_> LogicalANDExpression
%type <expression_> LogicalORExpression
%type <access_> MemberAccess
-%type <expression_> MemberExpression
+%type <target_> MemberExpression
%type <method_> MethodDefinition
%type <module_> ModulePath
%type <expression_> MultiplicativeExpression
-%type <expression_> NewExpression
+%type <target_> NewExpression
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
-%type <expression_> PrimaryExpression
+%type <target_> PrimaryExpression
%type <propertyName_> PropertyName
%type <property_> PropertyDefinition
%type <property_> PropertyDefinitionList_
%type <property_> PropertyDefinitionList
%type <property_> PropertyDefinitionListOpt
%type <declaration_> PropertySetParameterList
+%type <literal_> RegularExpressionLiteral
+%type <bool_> RegularExpressionSlash
%type <expression_> RelationalExpression
%type <statement_> ReturnStatement
%type <rubyProc_> RubyProcExpression
%type <statement_> StatementListOpt
%type <statement_> StatementListItem
%type <functionParameter_> StrictFormalParameters
-%type <expression_> SuperCall
-%type <expression_> SuperProperty
+%type <target_> SuperCall
+%type <target_> SuperProperty
%type <statement_> SwitchStatement
-%type <expression_> TemplateLiteral
+%type <target_> TemplateLiteral
%type <span_> TemplateSpans
%type <statement_> ThrowStatement
%type <statement_> TryStatement
%type <declaration_> VariableDeclaration
%type <declarations_> VariableDeclarationList_
%type <declarations_> VariableDeclarationList
+%type <for_> VariableStatement_
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
@end
@begin ObjectiveC
+%type <expression_> AssignmentExpressionClassic
%type <expression_> BoxableExpression
%type <statement_> CategoryStatement
%type <expression_> ClassSuperOpt
+%type <expression_> ConditionalExpressionClassic
%type <implementationField_> ImplementationFieldListOpt
%type <implementationField_> ImplementationFields
%type <message_> ClassMessageDeclaration
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
%type <statement_> ImplementationStatement
-%type <expression_> MessageExpression
+%type <target_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <messageParameter_> MessageParameterList
@end
/* }}} */
/* Token Priorities {{{ */
-%nonassoc ""
-%left "++" "--" "{"
-
%nonassoc "if"
%nonassoc "else"
/* }}} */
LexPopYield: { driver.yield_.pop(); };
LexSetRegExp
- : { 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
- : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
+ : { CYMPT(@$); driver.next_ = true; }
;
LexNoStar
;
Word
- : Identifier { $$ = $1; }
+ : IdentifierNoOf { $$ = $1; }
| "auto" { $$ = CYNew CYWord("auto"); }
| "break" { $$ = CYNew CYWord("break"); }
| "case" { $$ = CYNew CYWord("case"); }
| "catch" { $$ = CYNew CYWord("catch"); }
- | "class" { $$ = CYNew CYWord("class"); }
+ | "class" LexOf { $$ = CYNew CYWord("class"); }
| ";class" { $$ = CYNew CYWord("class"); }
| "const" { $$ = CYNew CYWord("const"); }
| "continue" { $$ = CYNew CYWord("continue"); }
| "extends" { $$ = CYNew CYWord("extends"); }
| "false" { $$ = CYNew CYWord("false"); }
| "finally" { $$ = CYNew CYWord("finally"); }
- | "function" { $$ = CYNew CYWord("function"); }
+ | "function" LexOf { $$ = CYNew CYWord("function"); }
| "if" { $$ = CYNew CYWord("if"); }
| "import" { $$ = CYNew CYWord("import"); }
| "!in" { $$ = CYNew CYWord("in"); }
+ | "!of" { $$ = CYNew CYWord("of"); }
| "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
| "null" { $$ = CYNew CYWord("null"); }
| "return" { $$ = CYNew CYWord("return"); }
- | "!return" { $$ = CYNew CYWord("return"); }
| "super" { $$ = CYNew CYWord("super"); }
- | "!super" { $$ = CYNew CYWord("super"); }
| "switch" { $$ = CYNew CYWord("switch"); }
| "this" { $$ = CYNew CYWord("this"); }
| "throw" { $$ = CYNew CYWord("throw"); }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
| Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
-
- // XXX: should be Identifier
- | "let" { $$ = CYNew CYIdentifier("let"); }
;
@begin ObjectiveC
| "false" { $$ = CYNew CYFalse(); }
;
/* }}} */
+/* 11.8.5 Regular Expression Literals {{{ */
+RegularExpressionSlash
+ : "/" { $$ = false; }
+ | "/=" { $$ = true; }
+ ;
+
+RegularExpressionLiteral
+ : RegularExpressionSlash { CYMPT(@$); driver.SetRegEx($1); } RegularExpressionLiteral_ { $$ = $3; }
+ ;
+/* }}} */
/* 11.9 Automatic Semicolon Insertion {{{ */
StrictSemi
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 CYEOK(); } StrictSemi
;
TerminatorOpt
;
BindingIdentifier
- : Identifier { $$ = $1; }
+ : IdentifierNoOf { $$ = $1; }
+ | "!of" { $$ = CYNew CYIdentifier("of"); }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
;
| "yield" { $$ = CYNew CYIdentifier("yield"); }
;
-IdentifierType
+IdentifierTypeNoOf
: Identifier_ { $$ = $1; }
| "abstract" { $$ = CYNew CYIdentifier("abstract"); }
| "await" { $$ = CYNew CYIdentifier("await"); }
| "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"); }
+ | "let" { $$ = CYNew CYIdentifier("let"); }
+ | "!let" LexBind { $$ = CYNew CYIdentifier("let"); }
| "native" { $$ = CYNew CYIdentifier("native"); }
- | "of" { $$ = CYNew CYIdentifier("of"); }
| "package" { $$ = CYNew CYIdentifier("package"); }
| "private" { $$ = CYNew CYIdentifier("private"); }
| "protected" { $$ = CYNew CYIdentifier("protected"); }
| "public" { $$ = CYNew CYIdentifier("public"); }
| "set" { $$ = CYNew CYIdentifier("set"); }
| "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
+ | "target" { $$ = CYNew CYIdentifier("target"); }
| "throws" { $$ = CYNew CYIdentifier("throws"); }
| "transient" { $$ = CYNew CYIdentifier("transient"); }
| "undefined" { $$ = CYNew CYIdentifier("undefined"); }
@end
;
-Identifier
- : IdentifierType
+IdentifierType
+ : IdentifierTypeNoOf { $$ = $1; }
+ | "of" { $$ = CYNew CYIdentifier("of"); }
+ ;
+
+IdentifierNoOf
+ : IdentifierTypeNoOf
| "char" { $$ = CYNew CYIdentifier("char"); }
| "int" { $$ = CYNew CYIdentifier("int"); }
| "long" { $$ = CYNew CYIdentifier("long"); }
| "YES" { $$ = CYNew CYIdentifier("YES"); }
@end
;
+
+Identifier
+ : IdentifierNoOf { $$ = $1; }
+ | "of" { $$ = CYNew CYIdentifier("of"); }
+ ;
/* }}} */
/* 12.2 Primary Expression {{{ */
PrimaryExpression
;
CoverParenthesizedExpressionAndArrowParameterList
- : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
- | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
- | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
- | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
+ : "(" Expression ")" { $$ = CYNew CYParenthetical($2); }
+ | "(" LexSetRegExp ")" { $$ = NULL; }
+ | "(" LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); }
+ | "(" Expression "," LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); }
;
/* }}} */
/* 12.2.4 Literals {{{ */
/* }}} */
/* 12.2.5 Array Initializer {{{ */
ArrayLiteral
- : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
+ : "[" ElementListOpt "]" { $$ = CYNew CYArray($2); }
;
ElementList
/* }}} */
/* 12.2.6 Object Initializer {{{ */
ObjectLiteral
- : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
+ : BRACE PropertyDefinitionListOpt "}" { $$ = CYNew CYObject($2); }
;
PropertyDefinitionList_
/* 12.3 Left-Hand-Side Expressions {{{ */
MemberAccess
- : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
+ : "[" Expression "]" { $$ = CYNew CYDirectMember(NULL, $2); }
| "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
| "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
| TemplateLiteral { CYNOT(@$); }
;
SuperProperty
- : LexSetRegExp "!super" "[" Expression "]" { $$ = CYNew CYSuperAccess($4); }
- | LexSetRegExp "!super" "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($4)); }
+ : 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
;
CallExpression_
- : MemberExpression
- | CallExpression
+ : MemberExpression { $$ = $1; }
+ | CallExpression { $$ = $1; }
;
CallExpression
- : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
+ : 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 { $$ = CYNew CYSuperCall($3); }
+ : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); }
;
Arguments
- : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
+ : "(" ArgumentListOpt ")" { $$ = $2; }
;
ArgumentList_
| LexSetRegExp { $$ = NULL; }
;
-LeftHandSideExpression
+AccessExpression
: NewExpression { $$ = $1; }
| CallExpression { $$ = $1; }
;
+
+LeftHandSideExpression
+ : AccessExpression LexCrement { $$ = $1; }
+ | LexSetRegExp IndirectExpression { $$ = $2; }
+ ;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
+LexCrement
+ : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); }
+ ;
+
PostfixExpression
- : %prec "" LeftHandSideExpression { $$ = $1; }
- | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
- | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
+ : AccessExpression LexCrement { $$ = $1; }
+ | AccessExpression LexCrement "++" { $$ = CYNew CYPostIncrement($1); }
+ | AccessExpression LexCrement "--" { $$ = CYNew CYPostDecrement($1); }
;
/* }}} */
/* 12.5 Unary Operators {{{ */
;
UnaryExpression
- : %prec "" PostfixExpression { $$ = $1; }
+ : PostfixExpression LexOpenBrace { $$ = $1; }
| LexSetRegExp UnaryExpression_ { $$ = $2; }
;
/* }}} */
;
/* }}} */
/* 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
;
Statement
- : LexSetStatement Statement_ { $$ = $2; }
+ : LexSetStatement LexLet Statement_ { $$ = $3; }
;
Declaration__
: HoistableDeclaration { $$ = $1; }
| ClassDeclaration { $$ = $1; }
- | LexicalDeclaration { $$ = $1; }
;
Declaration_
- : LexSetRegExp Declaration__ { $$ = $2; }
+ : LexLet LexSetRegExp Declaration__ { $$ = $3; }
+ | LexicalDeclaration { $$ = $1; }
;
Declaration
StatementListOpt
: StatementList { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ | LexSetStatement LexLet LexSetRegExp { $$ = NULL; }
;
StatementListItem
;
/* }}} */
/* 13.3 Let and Const Declarations {{{ */
+LexicalDeclaration_
+ : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); }
+ ;
+
LexicalDeclaration
- : LetOrConst BindingList Terminator { $$ = CYNew CYLet($2); }
+ : LexicalDeclaration_ Terminator { $$ = $1; }
+ ;
+
+LexLet
+ : { CYMAP(_let__, _let_); }
+ ;
+
+LexOf
+ : { CYMAP(_of__, _of_); }
+ ;
+
+LexBind
+ : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf
;
LetOrConst
- : "let"
- | "const"
+ : LexLet LexSetRegExp "!let" LexBind { $$ = false; }
+ | LexLet LexSetRegExp "const" { $$ = true; }
;
BindingList_
- : "," BindingList { $$ = $2; }
+ : "," LexBind BindingList { $$ = $3; }
| { $$ = NULL; }
;
;
/* }}} */
/* 13.3.2 Variable Statement {{{ */
+VariableStatement_
+ : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); }
+ ;
+
VariableStatement
- : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
+ : VariableStatement_ Terminator { $$ = $1; }
;
VariableDeclarationList_
;
VariableDeclarationList
- : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
+ : LexBind VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($2, $3); }
;
VariableDeclaration
;
ObjectBindingPattern
- : BRACE BindingPropertyListOpt "}"
+ : "let {" BindingPropertyListOpt "}"
;
ArrayBindingPattern
- : "[" { CYNOT(@$); }
+ : "let [" { CYNOT(@$); }
;
BindingPropertyList_
;
BindingElement
- : SingleNameBinding { $$ = $1; }
- | BindingPattern InitializerOpt { CYNOT(@$); }
+ : LexBind SingleNameBinding { $$ = $2; }
+ | LexBind BindingPattern InitializerOpt { CYNOT(@$); }
;
SingleNameBinding
;
/* }}} */
/* 13.5 Expression Statement {{{ */
+ExpressionStatement_
+ : Expression { $$ = CYNew CYExpress($1); }
+
ExpressionStatement
- : Expression Terminator { $$ = CYNew CYExpress($1); }
+ : ExpressionStatement_ Terminator { $$ = $1; }
;
/* }}} */
/* 13.6 The if Statement {{{ */
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 LexLet LexSetRegExp Var_ LexBind BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($8, $9), $12, $14); }
| "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(@$); }
+ : LexLet LexSetRegExp EmptyStatement { $$ = $3; }
+ | LexLet ExpressionStatement_ ";" { $$ = $2; }
+ | LexLet LexSetRegExp VariableStatement_ ";" { $$ = $3; }
+ | LexicalDeclaration_ ";" { $$ = $1; }
;
ForInStatementInitializer
- : LeftHandSideExpression { $$ = $1; }
- | LexSetRegExp Var_ ForBinding { $$ = $3; }
- | LexSetRegExp ForDeclaration { $$ = $2; }
+ : LexLet AccessExpression LexCrement { $$ = $2; }
+ | LexLet LexSetRegExp IndirectExpression { $$ = $3; }
+ | LexLet LexSetRegExp Var_ LexBind ForBinding { $$ = CYNew CYForVariable($5); }
+ | ForDeclaration { $$ = $1; }
;
ForDeclaration
- : LetOrConst ForBinding { $$ = $2; }
+ : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); }
;
ForBinding
/* }}} */
/* 13.10 The return Statement {{{ */
Return
- : "!return" LexNewLine
+ : "return" { if (!driver.return_.top()) CYERR(@1, "invalid return"); } LexNewLine
;
ReturnStatement
LabelledItem
: Statement { $$ = $1; }
- | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
+ | LexSetStatement LexLet LexSetRegExp FunctionDeclaration { $$ = $4; }
;
/* }}} */
/* 13.14 The throw Statement {{{ */
;
Catch
- : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
+ : "catch" "(" LexBind CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($4, $6); }
;
Finally
/* 14.1 Function Definitions {{{ */
FunctionDeclaration
- : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); }
+ : ";function" LexOf BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($3, $5, $9); }
;
FunctionExpression
- : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); }
+ : "function" LexOf BindingIdentifierOpt "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionExpression($3, $5, $9); }
;
StrictFormalParameters
;
FormalParameters
- : { $$ = NULL; }
+ : LexBind { $$ = NULL; }
| FormalParameterList
;
;
FormalParameterList
- : FunctionRestParameter { CYNOT(@$); }
+ : LexBind FunctionRestParameter { CYNOT(@$); }
| FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
;
;
/* }}} */
/* 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
ConciseBody
: AssignmentExpression { $$ = CYNew CYReturn($1); }
- | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
+ | LexSetRegExp ";{" FunctionBody "}" { $$ = $3; }
;
/* }}} */
/* 14.3 Method Definitions {{{ */
;
GeneratorDeclaration
- : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
+ : ";function" LexOf "*" LexOf BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
;
GeneratorExpression
- : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
+ : "function" LexOf "*" LexOf BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
;
GeneratorBody
;
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 { $$ = CYNew CYClassStatement($2, $3); }
+ : ";class" LexOf BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($3, $4); }
;
ClassExpression
- : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); }
+ : "class" LexOf BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($3, $4); }
;
ClassTail
;
ClassHeritage
- : "extends" LeftHandSideExpression { $$ = CYNew CYClassTail($2); }
+ : "extends" AccessExpression { $$ = CYNew CYClassTail($2); }
;
ClassHeritageOpt
ScriptBodyOpt
: ScriptBody { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ | LexSetStatement LexLet LexSetRegExp { $$ = NULL; }
;
/* }}} */
/* 15.2 Modules {{{ */
;
ModuleItem
- : LexSetStatement LexSetRegExp ImportDeclaration
- | LexSetStatement LexSetRegExp ExportDeclaration
+ : LexSetStatement LexLet LexSetRegExp ImportDeclaration
+ | LexSetStatement LexLet LexSetRegExp ExportDeclaration
| StatementListItem
;
/* }}} */
;
ExportDeclaration
- : "export" LexSetStatement LexSetRegExp ExportDeclaration_
+ : "export" LexSetStatement LexLet LexSetRegExp ExportDeclaration_
| "export" Declaration
;
/* Cycript (C): Type Encoding {{{ */
TypeSignifier
: IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
- | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
+ | "(" "*" TypeQualifierRight ")" { $$ = $3; }
;
SuffixedType
: SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
- | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
- | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
- | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
+ | "(" "^" TypeQualifierRight ")" "(" TypedParameterListOpt ")" { $$ = $3; $$->modifier_ = CYNew CYTypeBlockWith($6, $$->modifier_); }
+ | TypeSignifier "(" TypedParameterListOpt ")" { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
+ | "(" TypedParameterListOpt ")" { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($2, $$->modifier_); }
| TypeSignifier { $$ = $1; }
| { $$ = CYNew CYTypedIdentifier(@$); }
;
;
ImplementationFieldListOpt
- : TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($1, $3); }
+ : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); }
| LexSetRegExp { $$ = NULL; }
;
;
MessageParameter
- : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
+ : Word ":" TypeOpt BindingIdentifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
;
MessageParameterList
/* }}} */
/* Cycript (Objective-C): Send Message {{{ */
VariadicCall
- : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
+ : "," AssignmentExpressionClassic VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
| { $$ = NULL; }
;
;
SelectorCall
- : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
+ : SelectorWordOpt ":" AssignmentExpressionClassic SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
;
SelectorList
;
MessageExpression
- : "[" LexPushInOff AssignmentExpression { 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); }
+ : "[" AssignmentExpressionClassic { driver.contexts_.push_back($2); } SelectorList "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($2, $4); }
+ | "[" LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" { $$ = CYNew CYSendSuper($5); }
;
SelectorExpression_
PrimaryExpression
: MessageExpression { $$ = $1; }
- | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
+ | "@selector" "(" SelectorExpression ")" { $$ = CYNew CYSelector($3); }
;
/* }}} */
@end
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
PrimaryExpression
- : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->location_, "expected parameters"); }
+ : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE FunctionBody "}" { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $5); else CYERR($2->location_, "expected parameters"); }
;
/* }}} */
/* Cycript (Objective-C): Instance Literals {{{ */
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
-LeftHandSideExpression
- : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
+UnaryExpression_
+ : IndirectExpression { $$ = $1; }
+ ;
+
+IndirectExpression
+ : "*" UnaryExpression { $$ = CYNew CYIndirect($2); }
;
UnaryExpression_
;
PrimaryExpression
- : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
+ : "[" LexSetRegExp "&" LexSetRegExp "]" "(" TypedParameterListOpt ")" "->" TypedIdentifier BRACE FunctionBody "}" { $$ = CYNew CYLambda($10, $7, $12); }
;
/* }}} */
/* Cycript (C): Type Definitions {{{ */
PropertySelector_
: PropertySelector { $$ = $1; }
- | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
+ | "[" Expression "]" { $$ = CYNew CYSelector($2); }
;
PropertySelector
;
ComprehensionFor
- : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
+ : "for" "each" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($6, $9); }
;
/* }}} */
/* JavaScript FTL: for each {{{ */
;
ArrayComprehension
- : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
+ : "[" Comprehension "]" { $$ = $2; }
;
Comprehension
;
ComprehensionFor
- : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
- | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
+ : "for" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($5, $8); }
+ | "for" "(" LexPushInOn LexBind ForBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
;
ComprehensionIf
;
RubyProcParameterList
- : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
+ : BindingIdentifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
| { $$ = NULL; }
;
RubyProcParametersOpt
: RubyProcParameters { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
+ ;
+
+LexOpenBrace
+ : { CYLIN(OpenBrace); }
;
RubyProcExpression
;
PrimaryExpression
- : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
+ : BRACE RubyProcParameters StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
;
PostfixExpression
- : PostfixExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
+ : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); }
;
/* }}} */