code_->Single(out, CYRight(flags), CYCompactShort);
}
-void CYForDeclarations::Output(CYOutput &out, CYFlags flags) const {
- out << "var" << ' ';
- declarations_->Output(out, CYRight(flags));
-}
-
void CYForLexical::Output(CYOutput &out, CYFlags flags) const {
out << (constant_ ? "const" : "let") << ' ';
declaration_->Output(out, CYRight(flags));
%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 <target_> LeftHandSideExpression
%type <bool_> LetOrConst
%type <declaration_> LexicalBinding
+%type <for_> LexicalDeclaration_
%type <statement_> LexicalDeclaration
%type <literal_> Literal
%type <propertyName_> LiteralPropertyName
%type <declaration_> VariableDeclaration
%type <declarations_> VariableDeclarationList_
%type <declarations_> VariableDeclarationList
+%type <for_> VariableStatement_
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
;
/* }}} */
/* 13.3 Let and Const Declarations {{{ */
+LexicalDeclaration_
+ : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); }
+ ;
+
LexicalDeclaration
- : LetOrConst BindingList Terminator { $$ = CYNew CYLet($1, $2); }
+ : LexicalDeclaration_ Terminator { $$ = $1; }
;
LetOrConst
;
/* }}} */
/* 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 ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($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
next_->Replace(context);
}
-CYStatement *CYEmpty::Replace(CYContext &context) {
+CYForInitializer *CYEmpty::Replace(CYContext &context) {
return NULL;
}
return $ CYReturn(expression_);
}
-CYStatement *CYExpress::Replace(CYContext &context) {
+CYForInitializer *CYExpress::Replace(CYContext &context) {
context.Replace(expression_);
return this;
}
return this;
}
-CYExpression *CYForDeclarations::Replace(CYContext &context) {
- return declarations_->Replace(context, CYIdentifierVariable);
-}
-
CYStatement *CYForLexical::Initialize(CYContext &context, CYExpression *value) {
if (value == NULL) {
if (declaration_->initialiser_ == NULL)
return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_), parameters_->TypeSignature(context, typed_->Replace(context)));
}
-CYStatement *CYLet::Replace(CYContext &context) {
+CYForInitializer *CYLet::Replace(CYContext &context) {
if (CYExpression *expression = declarations_->Replace(context, CYIdentifierLexical))
return $E(expression);
return $ CYEmpty();
return next_->TypeSignature(context, $ CYAdd(prefix, typed_->Replace(context)));
}
-CYStatement *CYVar::Replace(CYContext &context) {
+CYForInitializer *CYVar::Replace(CYContext &context) {
if (CYExpression *expression = declarations_->Replace(context, CYIdentifierVariable))
return $E(expression);
return $ CYEmpty();
typedef CYList<CYStatement> CYStatements;
+struct CYForInitializer :
+ CYStatement
+{
+ virtual CYForInitializer *Replace(CYContext &context) = 0;
+ virtual void Output(CYOutput &out, CYFlags flags) const = 0;
+};
+
struct CYWord :
CYThing,
CYPropertyName
virtual CYStatement *Return();
};
-struct CYForInitializer {
- virtual CYExpression *Replace(CYContext &context) = 0;
- virtual void Output(CYOutput &out, CYFlags flags) const = 0;
-};
-
struct CYTarget;
struct CYVar;
struct CYString;
struct CYExpression :
- CYForInitializer,
CYThing
{
virtual int Precedence() const = 0;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYForDeclarations :
- CYForInitializer
-{
- CYDeclarations *declarations_;
-
- CYForDeclarations(CYDeclarations *declarations) :
- declarations_(declarations)
- {
- }
-
- virtual CYExpression *Replace(CYContext &context);
- virtual void Output(CYOutput &out, CYFlags flags) const;
-};
-
struct CYVar :
- CYStatement
+ CYForInitializer
{
CYDeclarations *declarations_;
CYCompact(None)
- virtual CYStatement *Replace(CYContext &context);
+ virtual CYForInitializer *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYLet :
- CYStatement
+ CYForInitializer
{
bool constant_;
CYDeclarations *declarations_;
CYCompact(None)
- virtual CYStatement *Replace(CYContext &context);
+ virtual CYForInitializer *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
};
struct CYExpress :
- CYStatement
+ CYForInitializer
{
CYExpression *expression_;
CYCompact(None)
- CYStatement *Replace(CYContext &context) override;
+ CYForInitializer *Replace(CYContext &context) override;
virtual void Output(CYOutput &out, CYFlags flags) const;
virtual CYStatement *Return();
};
struct CYEmpty :
- CYStatement
+ CYForInitializer
{
CYCompact(Short)
- virtual CYStatement *Replace(CYContext &context);
+ virtual CYForInitializer *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};