File: parse.tex

package info (click to toggle)
sollya 7.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 13,864 kB
  • sloc: ansic: 117,441; yacc: 8,822; lex: 2,419; makefile: 870; cpp: 76
file content (59 lines) | stat: -rw-r--r-- 2,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
\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}.
\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, unexpected *. Will try to continue parsing (expecting ";"
). May leak memory.
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}
See also: \textbf{execute} (\ref{labexecute}), \textbf{readfile} (\ref{labreadfile}), \textbf{print} (\ref{labprint}), \textbf{error} (\ref{laberror}), \textbf{dieonerrormode} (\ref{labdieonerrormode})