Debian Codegraph @

packages/pamgen/doc/sand_report/rtclang.tex

raw
1 %% NOTE: this file is shared directly between the Alegra Users Manual and
2 %% the RTC writeup in alegra/toolkit/rtcompiler/writeup.tex
3
4 \subsection{The RTC language}
5
6 The RTC language can be thought of as a small subset of the
7 C language with a couple minor modifications.
8
9 \subsubsection{Operators}
10
11 The RTC language has the following operators that work exactly as they do in C
12 and have the same precedence as they do in C:
13 \begin{itemize}
14 \item $+$ Addition
15 \item $-$ Subtration
16 \item $-$ Negation
17 \item $*$ Multiplication
18 \item $/$ Division
19 \item $==$ Equality
20 \item $>$ Greater than
21 \item $<$ Less than
22 \item $>=$ Greater than or equal to
23 \item $<=$ Less than or equal to
24 \item $=$ Assignment
25 \item $||$ Logical or
26 \item $\&\&$ Logical and
27 \item $!=$ Inequality
28 \item $\%$ Modulo
29 \item $!$ Logical not
30 \end{itemize}
31
32 \noindent The following operators do not occur in the C language, but were added to the RTC language for convenience:
33
34 \begin{itemize}
35 \item \begin{verbatim}^ Exponentiation \end{verbatim}
36 \end{itemize}
37
38
39 \subsubsection{Control flow}
40
41 The RTC language has the following control flow statements:
42
43 \begin{itemize}
44 \item for( expr ; expr ; expr ) \{ ... \}
45 \item while( expr ) \{ ... \}
46 \item if (expr) \{...\}
47 \item else if (expr) \{...\}
48 \item else \{...\}
49 \end{itemize}
50
51 \noindent These control flow statements work exactly as they do in C
52 except that the code blocks following a control flow statement
53 \textbf{MUST} be enclosed within braces even if the block only consists of
54 one line.
55
56 \subsubsection{Line Structure}
57
58 The line structure in the RTC language is the same as that of C. Expressions
59 end with a semicolon unless they are inside a control flow statement.
60
61 \subsubsection{Variables}
62
63 Declaring scalar variables in RTC is done exactly as it is done in C except
64 that only the following types are supported:
65
66 \begin{itemize}
67 \item int
68 \item float
69 \item double
70 \item char
71 \end{itemize}
72
73 \noindent For scalars, variables can be declared and assigned all at once. Both of the
74 following approaches will work:
75
76 {\ttfamily \begin{verbatim}
77 int myVar = 9;
78
79 OR
80
81 int myVar;
82 myVar = 9;
83 \end{verbatim}
84 }
85
86 \noindent Arrays work a little differently in RTC than they do in C. There are
87 no \emph{new} or \emph{malloc} operators, instead the user may
88 declare dynamically sized arrays in the same manner as statically sized
89 arrays. Also, in C all the values of an array may be initialized at once by
90 putting the values within braces. This is not supported in the RTC language.
91 Users will have to loop through the array and assign the values one by one.
92 For example:
93
94 {\ttfamily \begin{verbatim}
95 LEGAL:
96 int ia[x*y]; //Note: in C this would not be legal for non-const x,y
97 int ia2[3];
98
99 NOT LEGAL:
100 int ia[3] = {1, 2, 3};
101 \end{verbatim}
102 }
103
104 \noindent Indexing arrays can be done using the index operator:
105 array[expr] = ...;
106
107 \noindent Bounds checking is done at run time. If the bounds of an array are exceeded,
108 it will dump an error to stdout.
109
110 \subsubsection{Math}
111
112 The following math.h functions are available in RTC:
113
114 \begin{itemize}
115 \item asin(arg) : returns the arc sine of arg
116 \item acos(arg) : returns the arc cosine of arg
117 \item atan(arg) : returns the arc tangent of arg
118 \item atan2(y, x): returns the arc tangent of y/x
119 \item sin(arg) : returns the sine of arg
120 \item cos(arg) : returns the cosine of arg
121 \item tan(arg) : returns the tangent of arg
122 \item sqrt(arg) : returns the square root of arg
123 \item exp(arg) : returns the natural logarithm base e raised to the arg
124 power
125 \item sinh(arg) : returns the hyperbolic sine of arg
126 \item cosh(arg) : returns the hyperbolic cosine of arg
127 \item tanh(arg) : returns the hyperbolic tangent of arg
128 \item log(arg) : returns the natural logarithm for arg
129 \item log10(arg) : returns the base 10 logarithm for arg
130 \item rand(arg) : returns a system-generated random integer between 0 and RAND\_MAX using seed arg
131 \item fabs(arg) : returns the absolute value of arg
132 \item pow(b, e) : returns b to the e power
133 (Note: the Exponentiation operator is available)
134 \item j0(arg) : Bessel function of order zero
135 \item j1(arg) : Bessel function of order one
136 \item i0(arg) : Modified Bessel function of order zero
137 \item i1(arg) : Modified Bessel function of order one
138 \item erf(arg) : Error function
139 \item erfc(arg) : Complementary error function (1.0 - erf(x))
140 \item gamma(arg) : returns $\Gamma(arg)$
141 \end{itemize}
142
143 \subsubsection{Strings}
144
145 The user may pass quoted strings as arguments to
146 functions. Note: it may be necessary to escape-out the double quotes so that they
147 do not confuse the input-file parser. See printf section below for an example.
148
149 \subsubsection{Printf}
150
151 The RTC printf method is called just like its C counterpart. The first argument
152 is a quoted character string. This string will contain the \% symbol
153 which will tell RTC to output the corresponding argument. The only difference
154 between RTC's printf and C's printf is that in RTC's version, a type character
155 after the \% is unnecessary. For example, inside an RTC method
156 the following is appropriate:
157
158 {\ttfamily \begin{verbatim}
159 printf(\"One:% Two:% Three:% \", 5-4, 2.0e0, 'c');\n\
160 \end{verbatim} }
161
162 \noindent
163 Which would generate this output: One:1 Two:2 Three:c
164
165 \subsubsection{Comments}
166
167 The traditional C-comment mechanism may be used inside RTC
168 functions. Use /* to begin a comment and */ to end the comment.
169
170 \subsubsection{Unsupported Features}
171
172 Implementing the entire C-language was well beyond the intent of RTC. Features
173 that were too difficult or did not add enough value have been left out.
174 The following is a list of common C features that are unsupported in RTC:
175 \begin{itemize}
176 \item There are no $++$ or $--$ operators. Use $i = i + 1$ instead of $++i$
177 \item Structs
178 \item Pointers
179 \item Instant array initialization: int array[5] = {1,2,3,4,5};
180 \item Case statements
181 \item Casting
182 \item Labels and gotos
183 \item Function definition/declaration
184 \item stdio
185 \item Keywords: break, continue, const, enum, register, return, sizeof,
186 typedef, union, volatile, static.
187 \end{itemize}
188