\subsection{parse}
\label{labparse}
\noindent Name: \textbf{parse}\\
\phantom{aaa}parses an expression contained in a string\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_parse(sollya_obj_t)|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{parse}(\emph{string}) : \textsf{string} $\rightarrow$ \textsf{function} $|$ \textsf{error}\\
\end{center}
Parameters: 
\begin{itemize}
\item \emph{string} represents a character sequence
\end{itemize}
\noindent Description: \begin{itemize}

\item \textbf{parse}(\emph{string}) parses the character sequence \emph{string} containing an
   expression built on constants and base functions.
    
   If the character sequence does not contain a well-defined expression, a
   warning is displayed indicating a syntax error and \textbf{parse} returns a \textbf{error} of
   type \textsf{error}.

\item The character sequence to be parsed by \textbf{parse} may contain commands that
   return expressions, including \textbf{parse} itself. Those commands get executed
   after the string has been parsed. \textbf{parse}(\emph{string}) will return the
   expression computed by the commands contained in the character sequence
   \emph{string}.

\item \textbf{parse} expects an expression (or a command returning an expression) but
   cannot be used to evaluate a command producing a side effect without
   returning a result, nor to evaluate a sequence of instructions. However, such
   a behavior may be obtained by encapsulating the side effects into an
   anonymous procedure that parse can handle and by immediately applying it (see
   examples below).
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> parse("exp(x)");
exp(x)
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> text = "remez(exp(x),5,[-1;1])";
> print("The string", text, "gives", parse(text));
The string remez(exp(x),5,[-1;1]) gives 8.73819098827562036768683157316876049039
64388498642e-3 * x^5 + 4.3793696379596015478233171265365272893795005588381e-2 * 
x^4 + 0.16642465614952768185129433844012193925654065755905 * x^3 + 0.49919698262
963614991826575452094101562044819693772 * x^2 + 1.000038346505998154663400680582
31011540878088492516 * x + 1.00004475029559502606203712816558243384077522932213
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> verbosity = 1!;
> parse("5 + * 3");
Warning: syntax error. Will try to continue parsing (expecting ";"). May leak me
mory.
Warning: the string "5 + * 3" could not be parsed by the miniparser.
Warning: at least one of the given expressions or a subexpression is not correct
ly typed
or its evaluation has failed because of some error on a side-effect.
error
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 4: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> i = 17;
> parse("i = 42");
error
> i;
17
> (parse("proc () { i = 42; }"))();
> i;
42
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{execute} (\ref{labexecute}), \textbf{readfile} (\ref{labreadfile}), \textbf{print} (\ref{labprint}), \textbf{error} (\ref{laberror}), \textbf{dieonerrormode} (\ref{labdieonerrormode}), \textbf{proc} (\ref{labproc})
