?? smif.tex
字號:
NOPOWER IGNORE {[WORD] 123} } GET SINGLE {}\end{verbatim}In this example, the words \texttt{123} and \texttt{234} are ignoredby the first and the third \texttt{GET} command, while the second oneignores only \texttt{234}. (The integer part in the word\texttt{blabla1234} is not ignored since this is not a seperatetoken.)\subsubsection{The \texttt{SKIP} command}While executing a \texttt{GET} command, the file pointer in the textfile is moved character by character. Apart from \texttt{GET} command,\texttt{SKIP} is the only command which influences the file pointerposition:\texttt{SKIP} \emph{n} \texttt{LINE}\texttt{SKIP UNTIL SEE} \emph{controldefinestring}\texttt{SKIP UNTIL SEEN} \emph{controldefinestring}Suppose that the file pointer points at some position in line $x$.The first \texttt{SKIP} command moves the file pointer to thebeginning of line $x + n$. $n$ can be positive or negative. This isthe only possibility to move the file pointer backwards in the textfile.The other two commands move the text pointer forward until one of thecharacters or words given by \emph{controldefinestring} are read (oruntil an EOF condition is encountered). \texttt{SKIP UNTIL SEE} movesthe pointer to the first character or the beginning of the first wordgiven in \emph{controldefinestring}. \texttt{SKIP UNTIL SEEN} movesthe pointer to the position after the first specified character orword. If a character or a word is specified by an \texttt{IGNORE}command, this character or word will be ignored by every SMif command.It is not possible to search for these strings.\subsubsection{More \texttt{GET} commands}The following variants for \texttt{GET} commands are defined:\texttt{GET SINGLE \{} \emph{subscript} \texttt{\}}\texttt{GET INT \{} \emph{subscript} \texttt{\}}\texttt{GET LIST \{} \emph{subscript} \texttt{\}}\texttt{GET LIST FOR NEXT} \emph{n} \texttt{ITEM \{} \emph{subscript}\texttt{\}}\texttt{GET LIST FOR NEXT} \emph{n} \texttt{LINE \{} \emph{subscript}\texttt{\}}\texttt{GET POL \{} \emph{subscript} \texttt{\}}\texttt{GET POL FOR NEXT} \emph{n} \texttt{LINE \{} \emph{subscript}\texttt{\}}The \texttt{GET SINGLE} and \texttt{GET INT} commands return oneinteger. The first \texttt{GET LIST} command returns a list of singleprecision integers and possible sublists while the \texttt{GET LIST FOR ... LINE} and \texttt{GET LIST FOR ... ITEM} return only a listof single precision integers.A list returned by a \texttt{GET LIST FOR NEXT} \emph{n} \texttt{ITEM}command consists of exactly $n$ single precision integers. A listreturned by a \texttt{GET LIST FOR NEXT} \emph{n} \texttt{LINE}command consists of all the integers within the next \emph{n} linesunless the \texttt{GET} command is terminated by a \texttt{STOPGET}command or an enclosing \texttt{REPEAT} command or end of file isreached.\texttt{GET POL} gets a string and treats this string as a polynomial.The command returns a \#--terminated polynomial in complete monomials.This representation is readily understood by SIMATH functions. Thepolynomial representation in the text file must suffice the followingconditions:1. The coefficients of the complete monomials must be valid singleprecision integers.2. If some but not all multiplications of variables are denoted by\texttt{$\star$}, this must not lead to ambiguities. For example,\texttt{ab(a+b)} is a valid representation with variables \texttt{a}and \texttt{b}. But this must not be written as\texttt{ab$\star$(a+b)} since in this case SMif treats \texttt{ab} asa new variable.\emph{subscript} always denotes a sub script which is executed at thebeginning of a \texttt{GET} command. In the \emph{subscripts} of someof the \texttt{GET} commands, not all of the control commands areavailable. Sub scripts can be empty.The following table shows which \texttt{GET} and control commands canbe used in sub scripts of a given \texttt{GET} command. Here, $+$means that the operation is supported, and $-$ means that theoperation is not allowed.\begin{displaymath}\begin{array}{|c|c|c|c|c|c|c|c|}\hline & \texttt{GET} & \texttt{GET} & \texttt{GET} & \texttt{GET} & \texttt{GET} & \texttt{GET} & \texttt{GET} \\ & \texttt{SINGLE} & \texttt{INT} & \texttt{LIST} & \texttt{LIST} & \texttt{LIST} & \texttt{POL} & \texttt{POL} \\ & & & \{ \} & \texttt{ITEM} & \texttt{LINE} & \{ \} & \texttt{LINE} \\\hline\texttt{IGNORE} & + & + & + & + & + & + & + \\\hline\texttt{IGNORE NEWLINE} & + & + & + & + & + & + & + \\\hline\texttt{SETITEM} & + & + & + & + & + & - & - \\\hline\texttt{STOPGET} & + & + & + & + & + & + & + \\\hline\texttt{SKIP} & + & + & + & + & - & + & + \\\hline\texttt{GET SINGLE (INT)} & - & - & - & - & - & - & - \\\hline\texttt{GET LIST} & - & - & + & - & - & - & - \\\hline\texttt{GET POL} & - & - & - & - & - & - & - \\\hline\end{array}\end{displaymath}As explained above, the use of \texttt{SETITEM} in \texttt{GET INT} isrestricted. Only the sub script of \texttt{GET LIST \{ ... \}} commandis allowed to contain further \texttt{GET LIST} commands. Apart fromthis, no \texttt{GET} command is allowed to be contained in the subscript of a \texttt{GET} command.\subsubsection{Conditionals}{~}\texttt{REPEAT UNTIL SEE} \emph{controldefinestring} \texttt{\{}\emph{script} \texttt{\}}\texttt{IF SEE} \emph{controldefinestring} \texttt{\{} \emph{script}\texttt{\}}\texttt{IF SEE} \emph{controldefinestring} \texttt{\{} \emph{script1}\texttt{\}} \texttt{ELSE} \texttt{\{} \emph{script2} \texttt{\}}\texttt{SWITCH NEXTOBJ} \texttt{$\backslash$} \newline \hspace*{64pt}\emph{controldefinestring\_1} \texttt{\{} \emph{script\_1} \texttt{\}}\texttt{$\backslash$} \newline \hspace*{64pt} \texttt{.....}\texttt{$\backslash$} \newline \hspace*{64pt}\emph{controldefinestring\_n} \texttt{\{} \emph{script\_n} \textrm{\}}\texttt{$\backslash$} \newline \hspace*{64pt} \texttt{OTHERWISE}\texttt{\{} \emph{script\_n+1} \texttt{\}}In SMif scripts, one can write a part of a command in a new line byusing the $\backslash$ symbol. (See the syntax of the \texttt{SWITCH NEXTOBJ} command above.)The \texttt{REPEAT UNTIL SEE} command executes the sub script\emph{script} until one of the following conditions is fulfilled.1. A character or a word defined by \emph{controldefinestring} isread. \emph{controldefinestring} can be empty.2. A \texttt{REPEAT} or \texttt{GET} command enclosing the\texttt{REPEAT} command terminates.3. End of file is reached.An \texttt{IF SEE} command first tests whether the next character orthe next word is defined by \emph{controldefinestring}. In this case\emph{script} resp.\ \emph{script1} is executed. If the condition isnot fulfilled and there is an \texttt{ELSE} part of the \texttt{IF SEE} command \emph{script2} is executed.The \texttt{SWITCH NEXTOBJ} command works similar to the \texttt{IF SEE} command with the difference that there are arbitrary many casesavailable. Only one sub script is executed.Using the command described above one can write SMif scripts whichwork on large classes of similar text files.\textbf{Beispiel.} In most cases, SMif scripts will consist of a fewlines only. Here, we give an example of a very complicated script todemonstrate the use of the different SMif commands. Suppose we want toprocess the following text file:\begin{verbatim} *** TEXT FILE: textf *** BLOCK a 1 2 3 4 5 6 7 8 *** BLOCK b 1111 2\ 2\ 22 3333 4444 *** BLOCK c 123123123123123123 *** BLOCK d %1 = 2x(x+y(2x+y)) *** END\end{verbatim}We consider the follwing SMif script:\begin{verbatim}1 # comment line.2 # scriptname: scriptf3 4 IGNORE NEWLINE AFTER {[CHAR] \\}5 REPEAT UNTIL SEE {} {6 SKIP UNTIL SEEN {[WORD] BLOCK}7 SWITCH NEXTOBJ \8 {[CHAR] a} { SETITEM SIZE 4 PATTERN {$1+$2+$3+$4}9 REPEAT UNTIL SEE {[CHAR] *} {10 GET SINGLE {}11 }12 NOPOWER SETITEM13 } \14 {[CHAR] b} { GET LIST {15 REPEAT UNTIL SEE {[CHAR] *} {16 GET LIST FOR NEXT 2 ITEM {}17 } 18 STOPGET IF SEE {[CHAR] *}19 }20 } \21 {[CHAR] c} { GET INT {} } \22 {[CHAR] d} { SKIP UNTIL SEEN {[CHAR] = }23 GET POL {24 STOPGET IF SEE {[CHAR] *}25 }26 }27 # end SWITCH command28 }\end{verbatim}\begin{itemize}\item Line 1: Comments start with a \# sign.\item Line 4: $\backslash$ characters must be escaped. Similar for \texttt{'\{'}, \texttt{'\}'}, \texttt{'\#'} characters.\item Line 5: The subscript of the \texttt{REPEAT} command is repeated until end of file is reached.\item Line 6: After the \texttt{SKIP UNTIL SEEN} command has been executed, the file pointer points at the first character after the word \texttt{BLOCK}.\item Line 7: The next object is the character \texttt{'a'}, \texttt{'b'}, \texttt{'c'}, \texttt{'d'}, or the word \texttt{"a"}, \texttt{"b"}, \texttt{"c"}, \texttt{"d"}.\item Line 8: Here \texttt{\{[CHAR] a\}} is the same as \texttt{\{[WORD] a\}}\item Line 10: This \texttt{GET} command is repeated twice. The first time it returns $1+2+3+4 = 10$ and the second time it returns $5+6+7+8 = 26$.\item Line 12: The \texttt{NOPOWER SETITEM} command cancels the definition of line 8.\item Lines 14--19: This returns the list \texttt{( (1111 2222) (3333 4444) )}.\item Line 24: \texttt{GET POL} reads the polynomial \texttt{2x(x+y(2x+y))} and returns \texttt{2*x\^{}2*y\^{}0 + 4*x\^{}2*y\^{}1 + 2*x\^{}1*y\^{}2\#}.\end{itemize}If a SIMATH program executes\texttt{SMifRes\_FromFile(smifres, "textf", "scriptf")}; where\texttt{smifres} is an initialized variable of type \texttt{SMifRes},the following contents woll be assigned to the variable\texttt{smifres}.Number of entries: \texttt{SMifRes\_Count(smifres) = 5}Entry 1: \texttt{SM\_single}: "10"Entry 2: \texttt{SM\_single}: "26"Entry 3: \texttt{SM\_list}: "( (1111 2222) (3333 4444) )"Entry 4: \texttt{SM\_int}: "123123123123123123"Entry 5: \texttt{SM\_pol}: "2*x\^{}2*y\^{}0 + 4*x\^{}2*y\^{}1 +2*x\^{}1*y\^{}2\#"\end{document}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -