From 3f9ad55432f06d055e51ad7bb1d26eb5d577188c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 22:18:52 +0200 Subject: [PATCH] - allow multiple expressions in 'for' iteration part. --- src/scripting/zscript/zcc-parse.lemon | 1 + src/scripting/zscript/zcc_compile.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index aa618fa94..cf7eb4566 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -1859,6 +1859,7 @@ for_init(X) ::= for_bump(A). { X = A /*X-overwrites-A*/; } %type for_bump{ZCC_Statement *} for_bump(X) ::= . { X = NULL; } for_bump(X) ::= expression_statement(A). { X = A; /*X-overwrites-A*/ } +for_bump(X) ::= for_bump(A) COMMA expression_statement(B). { X = A; /*X-overwrites-A*/ AppendTreeNodeSibling(X, B); } /*----- If Statements -----*/ diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 8dfed30e7..fe93be7c9 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -3482,7 +3482,15 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) } else if (iter->LoopBumper != nullptr) { - return new FxForLoop(nullptr, ConvertNode(iter->LoopCondition), ConvertNode(iter->LoopBumper), ConvertNode(iter->LoopStatement), *ast); + FArgumentList bumper; + ConvertNodeList(bumper, iter->LoopBumper); + FxCompoundStatement *bumps = new FxCompoundStatement(*ast); + for (auto &ex : bumper) + { + bumps->Add(ex); + ex = nullptr; + } + return new FxForLoop(nullptr, ConvertNode(iter->LoopCondition), bumps, ConvertNode(iter->LoopStatement), *ast); } else {