Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Português - 日本語 - Русский
Aide de Scilab >> Fonctions avancées > tree2code

tree2code

generates the text definition of a Scilab function from its internal code

Syntax

txt = tree2code(tree, prettyprint)

Arguments

tree

a macro internal tree (coming from macr2tree).

prettyprint

an optional boolean value:

%T : The generated code is indented and beautified
%F : The generated code is not beautified (default)
txt

column of texts: Scilab instructions defining the function

Description

Given a loaded Scilab function "tree" (returned by macr2tree), tree2code allows to re-generate the code defining the function.

Examples

tree = macr2tree(log2);   // note that the input is log2 (the function handle), not "log2"
txt = tree2code(tree, %T);
printf("%s\n", txt);
--> printf("%s\n",c)
function [f,e] = log2(x)
  // x may be positive, negative, or complex
  [lhs,rhs] = argn(0)
  if rhs<>1 then
    msg = gettext("%s: Wrong number of input argument(s): %d expected.\n")
    error(msprintf(msg, "log2", 1))
  end;
  if argn(1)==1 then
    f = log(x)/log(2)
  else
    [f,e] = frexp(x)
  end
endfunction

See also

  • macr2tree — fournit le code interne d'une fonction compilée en Scilab
  • macrovar — variables d'une fonction
  • string — conversion en chaîne de caractères
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Feb 12 19:15:45 CET 2018