Rz language version 3.6
(This compiler is still a work in progress. )
Rz is a descendant of R1, a concurrent language for small control
applications. (Have a look at full report and implementation from my research work web
page). Rz is aimed to be a teaching language for system
programming and computer architecture subjects, which emphasises a small
language that can be used to illustrate all the "inner" working parts of a
computer system (compilation, code generation, ISA simulation), in other
words it allows students to "play" with the system. R1 is a
concurrent language. Rz simplifies that by eliminating all the real-time
concurrency language features and retains only the most basic language
constructs. In a way, Rz "looks like" C (without type).
Short description
The language is a small subset of C look-alike language. It has no type (or
having only one type which is "int"). Global variables must be
declared but local variables are automatic. A variable can be either a
scalar or an array. There is no user defined data type. An array
is one dimension. RZ language can be summarised as follows:
- It has only integer as primitive data. (natural size depends on
implementation)
- Global variables must be declared before their use. Local
variables are automatic (not required to be declared).
- Global variables can be array. The size of array must be known
at compile time. An array has only one dimension. Local
variables can be only scalar.
- Reserved words are: if, else, while, return, print.
- Operators are: +, -, *,
/, ==, !=, <, <=, >, >=, !, &&, ||, *
(dereference), & (address).
For C programmer, please note, no: for, break, do, missing many operators
especially ++, -- . The syntax is changed to use indentation
instead of {} and a newline terminates a statement instead of ';'.
Examples
It is easier just to look at an example to know most of the syntax.
Here is an example of Rz
// find max
in an array
a[10], N
init()
i = 0
while (
i < N )
a[i] = i
i = i + 1
main()
N = 10
init()
max =
a[0]
i = 1
while(
i < N )
if( max < a[i] ) max = a[i]
i = i + 1
print(max)
The variables a[], N are globals, max, i are locals. For an array, the
size must be known at compile time. (A note of C user, there is no ++,
--, and no "break", "print" is not "printf"). "print" knows only integer and
string. The size of basic unit (integer) depends on the target
machine.
// sum array
ax[10]
sum()
i = 0
s = 0
while( ax[i] != 0 )
s = s + ax[i]
i = i + 1
return s
main()
ax[0] = 11
ax[1] = 22
ax[2] = 33
ax[3] = 44
ax[4] = 0
print(sum())
The call by reference can be achived using the * and & operators just
like in C. In short, you can think of RZ syntax as C without type
declaration.
increment(x)
*x = *x + 1
main()
a = 1
increment(&a)
print(a)
last update 13 Jan 2013