Rz language

(This compiler is still a work in progress.  For an older system (generate code for S2 processor), please visit the Rz compiler tools kit page )

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:
For C programmer, please note, no: for, break, do, missing many operators especially ++, -- 

Quick Start  (simple tutorial for Rz version 3.3)

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( "the max value is ", 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.

increment(x){
  *x = *x + 1;
}

main(){
  a = 1;
  increment(&a);
  print(a);
}

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 (writing a translator to convert Rz to C is a trivial task).

Current state of implementation

rz3.zip  is a work in progress.  This is a new implementation of Rz language.  The new parser generator is written.  The grammar of Rz language is simplified.  The compiler is modified to output a parse-tree.  The parse-tree is an intermediate and explicit representation.  A separate code generator can be written for any desired target processor. (The original Rz is compiled into its own byte-code.  The original system also included a byte-code interpreter. For more information about the original system please visit Rz-language )

rz3 included:
comp:  the whole compiler
lexgen:  lexical analyser generator
pgen-c:  parser generator, the input is "rz-grammar9.txt"

rz3 version 1.0  include its "meta-interpreter".   readme
rz3 version 2.0  is an excercise in code generation.  It outputs a linear-code (assembly-like) to illustrate how to traverse and transform Rz parse-tree.  See example of output.
rz3 version 3.3 outputs s-code (version som-v2).  The output object code is run under Som-v2 virtual machine.
rz3 version 3.5 with preprossing of input to use indentation as { }  and \n as ";".  The output is s-code (som-v2).  See a new Rz look here  bubble.txt

Here is the sample session with v3.3 and v3.5
> rz33  bubble.txt
> somv2x bubble.obj
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Code Release

12 Nov 2010    rz3.zip
16 Nov 2010    rz31.zip    readme 
28 Nov 2010    rz32.zip
28 Aug 2011     rz33.zip   rz33-1.zip  (bug fix)
1 Sept 2011      rz35.zip   with a new look see example bubble.txt
26 Sept 2011    rz35-1.zip  (bug fix and include "syscall")  readme

last update 7 June 2012