%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
+%union { CYTarget *target_; }
%union { CYThis *this_; }
%union { CYTrue *true_; }
%union { CYWord *word_; }
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)
%token _import_ "import"
%token _in_ "in"
%token _in__ "!in"
+%token _Infinity_ "Infinity"
%token _instanceof_ "instanceof"
%token _new_ "new"
%token _return_ "return"
%token _char_ "char"
%token _constructor_ "constructor"
%token _double_ "double"
+%token _eval_ "eval"
%token _final_ "final"
%token _float_ "float"
%token _from_ "from"
%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_> LabelIdentifier
%type <statement_> LabelledItem
%type <statement_> LabelledStatement
-%type <expression_> LeftHandSideExpression
-%type <statement_> LetStatement
+%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 <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
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
%type <statement_> ImplementationStatement
-%type <expression_> MessageExpression
+%type <target_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <messageParameter_> MessageParameterList
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
: Word { $$ = $1; }
| "for" { $$ = CYNew CYWord("for"); }
| "in" { $$ = CYNew CYWord("in"); }
+ | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
| "instanceof" { $$ = CYNew CYWord("instanceof"); }
;
| "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"); }
: NullLiteral { $$ = $1; }
| BooleanLiteral { $$ = $1; }
| NumericLiteral { $$ = $1; }
+ | "Infinity" { $$ = CYNew CYNumber(std::numeric_limits<double>::infinity()); }
| StringLiteral { $$ = $1; }
;
/* }}} */
;
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; }
;
;
/* }}} */
/* 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_
;
/* }}} */
/* 13.3.2 Variable Statement {{{ */
+VariableStatement_
+ : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); }
+ ;
+
VariableStatement
- : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
+ : VariableStatement_ Terminator { $$ = $1; }
;
VariableDeclarationList_
;
/* }}} */
/* 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 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; }
+ | LexSetRegExp Var_ ForBinding { $$ = CYNew CYForVariable($3); }
| LexSetRegExp ForDeclaration { $$ = $2; }
;
ForDeclaration
- : LetOrConst ForBinding { $$ = $2; }
+ : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); }
;
ForBinding
: "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