summaryrefslogtreecommitdiff
path: root/macros/ASTManagement/AST_HandleWhileStatem.sci
diff options
context:
space:
mode:
authorsiddhu89902017-06-21 15:18:15 +0530
committersiddhu89902017-06-21 15:18:15 +0530
commitadbc46709966e50b3fed6ff061afff9e59d4b79c (patch)
treec0a375b9c280a878e451d06f9cac2e90a433165d /macros/ASTManagement/AST_HandleWhileStatem.sci
parent240e5e93815eef0992834ec7bd2a8162acca13f0 (diff)
parent18f7cf96174799b674115e43f108423fa5d0fc9c (diff)
downloadscilab2c-adbc46709966e50b3fed6ff061afff9e59d4b79c.tar.gz
scilab2c-adbc46709966e50b3fed6ff061afff9e59d4b79c.tar.bz2
scilab2c-adbc46709966e50b3fed6ff061afff9e59d4b79c.zip
Merged Ukasha's work, code generation for control loop changed
Diffstat (limited to 'macros/ASTManagement/AST_HandleWhileStatem.sci')
-rw-r--r--macros/ASTManagement/AST_HandleWhileStatem.sci60
1 files changed, 33 insertions, 27 deletions
diff --git a/macros/ASTManagement/AST_HandleWhileStatem.sci b/macros/ASTManagement/AST_HandleWhileStatem.sci
index 79fb516d..d8c2f73c 100644
--- a/macros/ASTManagement/AST_HandleWhileStatem.sci
+++ b/macros/ASTManagement/AST_HandleWhileStatem.sci
@@ -36,6 +36,8 @@ global SCI2CSTACK
global StackPosition;
global STACKDEDUG
+IfCondArg = [];
+NIfCondArg = 0;
// ------------------------------
// --- Check input arguments. ---
@@ -70,36 +72,40 @@ PrintStringInfo(' Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPa
// --- Generate C code. ---
// ------------------------
//#RNU_RES_E
-if(SharedInfo.WhileExpr.CondVar == '')
- //#RNU_RES_B
- // It means that we are handling something like while(a) or while(1)
- // The while condition variable is generated by the HandleEndGenFun.
- //#RNU_RES_E
-
- // --- Pop the name of the condition variable or number. ---
- Pop1 = AST_PopASTStack();
-
- [ArgName,ArgScope] = AST_ExtractNameAndScope(Pop1);
- if (length(ArgName) == 0)
- PrintStringInfo(' ',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: Expected while(variable) or while(number).','','stdout','y');
- PrintStringInfo('SCI2CERROR: Expected a variable or number in the AST while expression.','','stdout','y');
- PrintStringInfo('SCI2CERROR: Report this error to http://forge.scilab.org/index.php/p/scilab2c/issues/.','','stdout','y');
- PrintStringInfo(' ',ReportFileName,'both','y');
- error(9999, 'Expected a conditional variable in the while expression');
+flagendpop = 0;
+IfExprField = AST_PopASTStack();
+
+NOp=0;
+Op=[];
+while (flagendpop == 0)
+ if (IfExprField~='<EOL>')
+ if (IfExprField=='WhileExpression:')
+ flagendpop = 1;
+ // Pop Again the If tag from the AST.
+ IfExprField = AST_PopASTStack();
+ elseif (IfExprField=='Operands:')
+ flagendpop = 0;
+ g = AST_PopASTStack();
+ else
+ if (IfExprField=='&&' | IfExprField=='||')
+ NOp = NOp + 1;
+ Op(NOp) = IfExprField;
+ //PrintStringInfo('operators are '+Op(NOp),ReportFileName,'file','y');
+ else
+ NIfCondArg = NIfCondArg + 1;
+ IfCondArg(NIfCondArg) = IfExprField;
+ end
+ //[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
+ //[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
+ end
end
+ IfExprField = AST_PopASTStack();
+ PrintStringInfo('operators are '+IfExprField,ReportFileName,'file','y');
+end
- SharedInfo.WhileExpr.CondVar = ArgName;
- //#RNU_RES_B
- // --- Repush strings into the AST stack. ---
- //#RNU_RES_E
-
- AST_PushASTStack(Pop1);
+IfCondArg = SCI2Cflipud(IfCondArg);
-elseif (SharedInfo.WhileExpr.DimCondVar > 0)
- error(9999, 'Cannot manage while with matrix conditions');
-end
-SharedInfo = C_WhileExpression(FileInfo,SharedInfo);
+SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo);
// --------------------------
// --- Update SharedInfo. ---