%% NOTE: this file is shared directly between the Alegra Users Manual and
%%       the RTC writeup in alegra/toolkit/rtcompiler/writeup.tex

\subsection{The RTC language}

The RTC language can be thought of as a small subset of the
C language with a couple minor modifications. 

\subsubsection{Operators}

The RTC language has the following operators that work exactly as they do in C
and have the same precedence as they do in C:
\begin{itemize}
  \item $+$  Addition
  \item $-$  Subtration
  \item $-$  Negation
  \item $*$  Multiplication
  \item $/$  Division
  \item $==$ Equality
  \item $>$  Greater than
  \item $<$  Less than
  \item $>=$ Greater than or equal to
  \item $<=$ Less than or equal to
  \item $=$  Assignment
  \item $||$ Logical or
  \item $\&\&$ Logical and
  \item $!=$ Inequality
  \item $\%$ Modulo
  \item $!$  Logical not
\end{itemize}

\noindent The following operators do not occur in the C language, but were added to the RTC language for convenience:

\begin{itemize}
  \item \begin{verbatim}^ Exponentiation \end{verbatim}
\end{itemize}


\subsubsection{Control flow}

The RTC language has the following control flow statements:

\begin{itemize}
  \item for( expr ; expr ; expr ) \{ ... \}
  \item while( expr )  \{ ... \}
  \item if (expr) \{...\}
  \item else if (expr) \{...\}
  \item else \{...\}
\end{itemize}

\noindent These control flow statements work exactly as they do in C
except that the code blocks following a control flow statement 
\textbf{MUST} be enclosed within braces even if the block only consists of 
one line.

\subsubsection{Line Structure}

The line structure in the RTC language is the same as that of C. Expressions
end with a semicolon unless they are inside a control flow statement.

\subsubsection{Variables}

Declaring scalar variables in RTC is done exactly as it is done in C except 
that only the following types are supported:

\begin{itemize}
  \item int
  \item float
  \item double
  \item char
\end{itemize}

\noindent For scalars, variables can be declared and assigned all at once. Both of the 
following approaches will work:

{\ttfamily \begin{verbatim}
int myVar = 9;

OR

int myVar;
myVar = 9;
\end{verbatim}
}

\noindent Arrays work a little differently in RTC than they do in C. There are
no \emph{new} or \emph{malloc} operators, instead the user may 
declare dynamically sized arrays in the same manner as statically sized 
arrays. Also, in C all the values of an array may be initialized at once by 
putting the values within braces. This is not supported in the RTC language.
Users will have to loop through the array and assign the values one by one.
For example:

{\ttfamily \begin{verbatim}
LEGAL:
   int ia[x*y];  //Note: in C this would not be legal for non-const x,y
   int ia2[3];

NOT LEGAL:
   int ia[3] = {1, 2, 3};
\end{verbatim}
}

\noindent Indexing arrays can be done using the index operator:
array[expr] = ...;

\noindent Bounds checking is done at run time. If the bounds of an array are exceeded, 
it will dump an error to stdout. 

\subsubsection{Math}

The following math.h functions are available in RTC:

\begin{itemize}
  \item asin(arg)  : returns the arc sine of arg
  \item acos(arg)  : returns the arc cosine of arg
  \item atan(arg)  : returns the arc tangent of arg
  \item atan2(y, x): returns the arc tangent of y/x
  \item sin(arg)   : returns the sine of arg
  \item cos(arg)   : returns the cosine of arg
  \item tan(arg)   : returns the tangent of arg
  \item sqrt(arg)  : returns the square root of arg
  \item exp(arg)   : returns the natural logarithm base e raised to the arg 
                     power
  \item sinh(arg)  : returns the hyperbolic sine of arg
  \item cosh(arg)  : returns the hyperbolic cosine of arg
  \item tanh(arg)  : returns the hyperbolic tangent of arg
  \item log(arg)   : returns the natural logarithm for arg
  \item log10(arg) : returns the base 10 logarithm for arg
  \item rand(arg)  : returns a system-generated random integer between 0 and RAND\_MAX using seed arg
  \item fabs(arg)  : returns the absolute value of arg
  \item pow(b, e)  : returns b to the e power 
                     (Note: the Exponentiation operator is available)
  \item j0(arg)    : Bessel function of order zero
  \item j1(arg)    : Bessel function of order one
  \item i0(arg)    : Modified Bessel function of order zero
  \item i1(arg)    : Modified Bessel function of order one
  \item erf(arg)   : Error function 
  \item erfc(arg)  : Complementary error function  (1.0 - erf(x))
  \item gamma(arg)  : returns $\Gamma(arg)$
\end{itemize}

\subsubsection{Strings}

The user may pass quoted strings as arguments to 
functions. Note: it may be necessary to escape-out the double quotes so that they
do not confuse the input-file parser. See printf section below for an example.

\subsubsection{Printf}

The RTC printf method is called just like its C counterpart. The first argument
is a quoted character string. This string will contain the \% symbol 
which will tell RTC to output the corresponding argument. The only difference
between RTC's printf and C's printf is that in RTC's version, a type character 
after the \% is unnecessary. For example, inside an RTC method
the following is appropriate:

{\ttfamily \begin{verbatim}
printf(\"One:% Two:% Three:% \", 5-4, 2.0e0, 'c');\n\
\end{verbatim} }

\noindent
Which would generate this output: One:1 Two:2 Three:c

\subsubsection{Comments}

The traditional C-comment mechanism may be used inside RTC
functions. Use /* to begin a comment and */ to end the comment.

\subsubsection{Unsupported Features}

Implementing the entire C-language was well beyond the intent of RTC. Features 
that were too difficult or did not add enough value have been left out. 
The following is a list of common C features that are unsupported in RTC:
\begin{itemize}
  \item There are no $++$ or $--$ operators. Use $i = i + 1$ instead of $++i$
  \item Structs
  \item Pointers
  \item Instant array initialization: int array[5] = {1,2,3,4,5};
  \item Case statements
  \item Casting
  \item Labels and gotos
  \item Function definition/declaration
  \item stdio
  \item Keywords: break, continue, const, enum, register, return, sizeof,
    typedef, union, volatile, static.
\end{itemize} 

