⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tinyscript-manual.tex

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 TEX
📖 第 1 页 / 共 2 页
字号:
Addition       & + & val = val + 2;\\ \hlineSubtraction    & - & val = a - b; \\ \hlineDivision       & / & val = bsize() / 2; \\ \hlineMultiplication & * & val = 2 * b; \\ \hlineExponentiation & $^{\wedge}$ & val = val $^{\wedge}$ 2 \\ \hline\end{tabular}\label{fig:arithmetic}}\subfigure[Comparison Operations]{\scriptsize\begin{tabular}{|l|c|l|} \hlineName                  & Operator & Example \\ \hlineLess than             & $<$  & val = val $<$ 2;\\ \hlineGreater than          & $>$  & val = a $>$ b; \\ \hlineLess than or equal    & $<=$ & val = bsize() $<=$ 8; \\ \hlineGreater than or equal & $>=$ & val = b $>=$ 2; \\ \hlineNot equal             & $<>$ & cond = val $<>$ b \\ \hline\end{tabular}\label{fig:comparison}}\caption{TinyScript Computational Primitives}\label{fig:tscriptcomp}\end{figure}TinyScript also supports logical operations, which are show inFigure~\ref{fig:logic}. All of these operations only accept integersas operands. For the boolean operators (e.g., and, not), a value ofzero is considered false; all other values are considered true. Alloperators use 0 as false and 1 as true. So, {\tt 1 and 2} resolves to1, while {\tt 0 and 34} resolves to 0. Figure~\ref{fig:tables}contains the truth tables for the boolean operators.\begin{figure}\centering\scriptsize\subfigure[Logical Operations] {\begin{tabular}{|l|c|l|} \hlineName           & Operator & Example \\ \hlineAnd          & AND, and        & ready = full and idle;\\ \hlineOr           & OR, or          & ready = full OR idle;\\ \hlineNot          & NOT, not        & ready = not idle; \\ \hlineExclusive or & XOR, xor        & diff = a XOR b; \\ \hlineEquivalent   & EQV, eqv        & rval = a eqv b; \\ \hlineImplies      & IMP, imp        & ready = a imp b; \\ \hlineLogical And  & \&              & bits = packetbits \& mask; \\ \hlineLogical Or   & $\mid$          & bits = firstbit $\mid$ secondbi t; \\ \hlineLogical Not  & $^{\sim}$       & mask = $^{\sim}$bits; \\ \hline\end{tabular}\label{fig:logic}}\subfigure[Truth Tables] {\begin{tabular}{|c||c|c||c|c||c|c||}\hline&\multicolumn{2}{|c||}{and}&\multicolumn{2}{c||}{or}&\multicolumn{2}{c||}{not} \\ \hline  & F & T & F & T & \multicolumn{2}{|c||}{} \\ \hlineF & {\bf F} & {\bf F} & {\bf F} & {\bf T} & \multicolumn{2}{|c||}{{\bf T}} \\ \hlineT & {\bf F} & {\bf T} & {\bf T} & {\bf T} & \multicolumn{2}{|c||}{{\bf F}} \\ \hline \hline&\multicolumn{2}{|c|}{xor}&\multicolumn{2}{|c|}{eqv}&\multicolumn{2}{|c|}{imp} \\ \hline  & F & T & F & T & F & T \\ \hlineF & {\bf F} & {\bf T} & {\bf T} & {\bf F} & {\bf T} & {\bf T} \\ \hlineT & {\bf T} & {\bf F} & {\bf F} & {\bf T} & {\bf F} & {\bf T} \\ \hline\end{tabular}}\caption{TinyScript Logical Primitives}\label{fig:tables}\end{figure}The logical operations manipulate integer bit fields. Instead ofmanipulating the integer as a singe value, they operate on each bit,in a manner similar to C operators. For example, {\tt 1 and 2}resolves to 1, while {\tt 1 \& 2} resolves to zero (1 and 2 share nocommon bits), and {\tt 1 $\mid$ 2} resolves to 3.Finally, TinyScript has standard comparison operators, as shown inFigure~\ref{fig:comparison}. They resolve to one if true, zero iffalse.\subsection{Control Structures}TinyScript supports standard language control structures such asconditionals and loops.The first set of control structures, conditionals, take this form:\begin{quotation}\begin{verbatim}if <expression> then                if <expression> then <block 1>                           <block 1>end if                              else                                      <block 2>                                    end if\end{verbatim}\end{quotation}If expression resolves to true, then block 1 executes. If thestatement has an else clause and expression resolves to false, thenblock 2 executes. There can be nested if-then statements:\begin{quotation}\begin{verbatim}shared idle;buffer buf;if bfull(buf) then  idle = 0;  if rand() & 1 then    send(buf);    bclear(buf);  end if  idle = 1;end if\end{verbatim}\end{quotation}TinyScript provides loops through the {\tt for} construct. There aretwo basic forms, unconditional and conditional. Unconditional (for-to)loops run a specific number of times; their termination condition whenthe loop variable takes a specific value. Conditional (for-until)loops run until an arbitrary condition becomes true. {\tt next}defines the end of the loop block, and increments the loopvariable. By default, the variable increments by one. However, theincrement step can be set with the {\tt step} keyword. In summary:\begin{quotation}\begin{verbatim}for <x> = <expression> to <to-constant>  ...next <x>for <x> = <expression> to <to-constant> step <step-constant>  ...next <x>for <x> = <expression> until <until-exp>  ...next <x>for <x> = <expression> step <step-constant> until <until-exp>  ...next <x>\end{verbatim}\end{quotation}For example, this loop will run one hundred times, blinking the leds,\begin{quotation}\begin{verbatim}private i;for i = 1 to 100  leds(i & 7)next i\end{verbatim}\end{quotation}while this loop will put the values 1,3,5...21 in the buffer (when it hasten values, it will be full),\begin{quotation}\begin{verbatim}private i;buffer buf;bclear(buf);for i = 1 step 1 until i > 10  buf[] = i * 2;next i\end{verbatim}\end{quotation}Standard while loops can be implemented by setting a step ofzero. This loop, for example, will put random values into a bufferuntil it is full:\begin{quotation}\begin{verbatim}private i;buffer buf;for i = 0 step 0 until bfull(buf)  buf[] = rand();next i\end{verbatim}\end{quotation}Parenthesis pairs can be added to define precedence, or for readability.\begin{quotation}\begin{verbatim}private i;buffer buf;bclear(buf);for i = 1 step 1 until i > 10  buf[] = ((i * 2) + 1);next ii = (5 + 2 * 2);    ! i = 9i = (5 + 2) * 2;    ! i = 14i = ((((5))));      ! i = 5\end{verbatim}\end{quotation}\mate is under active development. Bugs, contexts, and functions can be sentto Phil Levis ({\tt pal@cs.berkeley.edu}).\section{Appendix A: Grammar}\em \begin{tabbing}\grammarindentTinyScript-file: \\\>  variable-list\opt statement-list\opt\\\\variable-list:\\\> variable \\\> variable-list variable\\\\variable:\\\> \kw{shared} identifier\\\> \kw{private} identifier\\\> \kw{buffer} identifier\\\\statement-list:\\\> statement\\\> statement-list statement\\\\statement:\\\> assignment\\\> control-statement\\\> function-statement \\\\control:\\\> if-statement\\\> for-unconditional\\\> for-conditional\\\\if-statement:\\\> \kw{if} expression \kw{then} then-clause \kw{end if}\\\\then-clause:\\\> statement-list\\\> statement-list \kw{else} statement-list \\\\for-unconditional:\\\> \kw{for} variable-ref \kw{=} expression \kw{to} constant-expression step statement-list \kw{next} variable-ref\\\\for-conditional:\\\> \kw{for} scalar-ref \kw{=} constant-expression step for-condition statement-list \kw{next} scalar-ref\\\\for-condition:\\\> \kw{until} expression\\\> \kw{while} expression\\\\constant-expression:\\\> constant\\\\function-statement:\\\> function-call \kw{;}\\\\function-call:\\\> name \kw{(} parameter-list\opt \kw{)}\\\\parameter-list:\\\> parameter\\\> parameter-list \kw{,} parameter\\\\parameter:\\\> expression\\\\assignment:\\\> l-value \kw{=} expression \kw{;} \\\\l-value:\\\> var-ref\\\> buffer-ref\\\\scalar-ref:\\\> identifer\\\\var-ref:\\\> identifier\\\\buffer-ref:\\\> identifier \kw{[]}\\\> identifier \kw{[} expression \kw{]}\\\\expression:\\\> function-call\\\> constant-expression\\\> variable-expression\\\> paren-expression\\\> unary-expression\\\> binary-expression\\\> conditional-expression\\\\variable-expression:\\\> buffer-access\\\> variable-access\\\\buffer-access:\\\> identifier \kw{[]}\\\> identifier \kw{[} expression \kw{]}\\\\variable-access:\\\> identifier\\\\paren-expression:\\\> \kw{(} expression \kw{)}\\\\unary-expression:\\\> \kw{-} expression\\\> $\approx$ expression\\\> \kw{NOT} expression\\\\binary-expression:\\\> expression \kw{+} expression\\\> expression \kw{-} expression\\\> expression \kw{*} expression\\\> expression \kw{/} expression\\\> expression \kw{\%} expression\\\> expression \kw{\&} expression\\\> expression \kw{|} expression\\\> expression \kw{\#} expression\\\> expression \kw{AND} expression\\\> expression \kw{XOR} expression\\\> expression \kw{OR} expression\\\> expression \kw{EQV} expression\\\> expression \kw{IMP} expression\\\\conditional-expression:\\\> expression $=$ expression\\\> expression $!=$ expression\\\> expression $>=$ expression\\\> expression $>$ expression\\\> expression $<=$ expression\\\> expression $<$ expression\\\\constant:\\\> \kw{[1-9][0-9]}*\\\\identifier:\\\> \kw{[A-Za-z\_][A-Za-z\_0-9]*}\\\end{tabbing}\end{document}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -