From 0345245e860375a32c9a437c4a9d9cae807134e9 Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 29 May 2017 12:40:26 +0530 Subject: CMSCOPE changed --- modules/string/macros/tree2code.sci | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 modules/string/macros/tree2code.sci (limited to 'modules/string/macros/tree2code.sci') diff --git a/modules/string/macros/tree2code.sci b/modules/string/macros/tree2code.sci new file mode 100755 index 000000000..776924c20 --- /dev/null +++ b/modules/string/macros/tree2code.sci @@ -0,0 +1,71 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - Vincent Couvert +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt + + +function C=tree2code(P,bprettyprintformat) + // Convert a tree returned by macr2tree() to a macro code + // Input: + // - P: 'program' tlist + // - bprettyprintformat: boolean value, if FALSE (default value), generated code is not formated else it is + // Output: + // - C: character string matrix (colum vector) + + // Verify good type for input + if typeof(P)<>"program" then + error(msprintf(gettext("%s: Wrong type for input argument #%d: ''%s'' expected.\n"),"tree2code",2,"program tree")); + end + + // Default value + rhs = argn(2); + if rhs==1 then + bprettyprintformat=%F + end + + C="" + + // Function prototype + lhsstr=[] + rhsstr=[] + if P.name<>"" then // Not a batch file + for k=1:size(P.outputs) + lhsstr=[lhsstr,expression2code(P.outputs(k))] + end + lhsstr="["+strcat(lhsstr,",")+"]" + + for k=1:size(P.inputs) + rhsstr=[rhsstr,expression2code(P.inputs(k))] + end + rhsstr="("+strcat(rhsstr,",")+")" + + C="function "+lhsstr+" = "+P.name+rhsstr; + end + + I=P.statements + + // To avoid to have some instructions on the first line (function prototype) + if I(1)<>list("EOL") then + C=cat_code(C,instruction2code(list("EOL"),%T)); + end + + // For each statement, generate corresponding code + for i=1:size(I)-2 // -2 to ignore last return+EOL + if bprettyprintformat then + C=cat_code(C," "+instruction2code(I(i),bprettyprintformat)); + else + C=cat_code(C,instruction2code(I(i),bprettyprintformat)); + end + C = format_txt(C,I(i),bprettyprintformat,I(i+1)); + end + + if P.name<>"" then // Not a batch file + C=cat_code(C,"endfunction"); // Replace last return + C=cat_code(C,""); + end +endfunction + -- cgit