Ruhs Gunnar Compiler - Person Info Gunnar Ruhs Gunnar Ruhs (2) Gunnar Ruhs Impressum

CC Course 2008

PmWiki

Recent Changes Printable View Page History Edit Page

DIALECT - Compiler (self-compiling)

  • Gunnar Ruhs / gunnar ~at~ ruhs.org

Download Area
Dialect Documentation (PDF) Note: Dialect EBNF = Appendix I
Dialect Presentation (PDF, June 19, 2008)
 
Dialect Source Code (.dia file, zipped )
Dialect Executable Compiler (.exe, Win32, Windows Vista, zipped)

 In order to compile the compiler (or any other Dialect Source Code) simply follow these steps:
 * Download the Dialect Executable Compiler  (dialect.exe)
 * Download the Dialect Source Code   (dialect_compiler.dia)
 * On the CMD-Command Line (Windows Vista) change to the directory with the downloaded (and extracted) files and enter:

          dialect.exe < dialect_compiler.dia > output.exe

 (Note: dialect_compiler.dia can be replaced by any DIA source code)
 (Note 2: The Dialect compiler should also run under Windows XP, but this hasn't been tested yet)
 (Note 3: Please consider, that any compilation errors will be sent to STDOUT (and end up  
in the .exe file instead of the machine code. So before executing the created file,
I suggest to look at the file size. If it is only a few bytes long, view the error by
entering 'type output.exe')


Dialect Compiler - Cheat Sheet
Quick Facts:

 The Dialect Compiler...
 * ...compiles a new procedural programming language called Dialect
 * ...directly generates WIN32?/PEEXE machine code (tested under Windows Vista only)
 * ...is  Self-Compiling     
 * ...supports the following basic types: Char, Integer, Arrays, Records (+ limited support for Strings)    
 * ...supports parameterized local hiding: Procedures + Functions
 * ...supports parameter call-by-reference (Keyword REF) and call-by-value   
 * ...supports all standard arithmetic operations, such as +, -, *, DIV, MOD
 * ...is a recursive decent, top-down, and - up to Object-Code generation - single pass compiler
 * ...takes input through STDIN ( use < on command line)
 * ...writes output and errors to STDOUT (use > on command line)

 The Dialect Compiler does not
 * ... support global hiding / separate compilation
 * ... use a Virtual Machine (but instead directly generates executable machine code)
 * ... currently require a separate linker (due to missing support for separate compilation)
 * ... bring you breakfast to bed in the morning (which is a shame)

Hello World in Dialect Variables in Dialect Constants in Dialect Types in Dialect
 MODUL helloWorld 
   IST HAUPTMODUL;
 BLOCK
   AUSGABE ('Seawas');
 BLOCKENDE;
 MODUL varExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    i, j : integerzahl;
    c : zeichen;
 BLOCK
    i << 1;
    j << i + 10;
    c << 'x';
    AUSGABE (j);
    AUSGABE (c);
 BLOCKENDE;
 MODUL constExample 
         IST HAUPTMODUL;
 KONSTANTEN_DEFINIEREN
    cDummyConst = 123;
 VARIABLEN_DEFINIEREN
    i : integerzahl;
 BLOCK
    i << cDummyConst;
    AUSGABE (i);
 BLOCKENDE;
 MODUL typeExample 
        IST HAUPTMODUL;
 TYPEN_DEFINIEREN
   tArr = array[1 : 5] 
        ELEMENTE zeichen; 
 VARIABLEN_DEFINIEREN
    a : tArr;
 BLOCK
    a[1] << 'x';
    a[2] << a[1];
    AUSGABE (a[2]);
 BLOCKENDE;

if/else - Construct for-Loop - Construct repeat ... until (not) - Construct while-loop - Construct
 MODUL ifExample 
   IST HAUPTMODUL;
 BLOCK
   WENN (1 = 2)
       AUSGABE('Nein!')
   SONST
      BLOCK
       AUSGABE('JA!!!');
       AUSGABE('JO!!!');
      BLOCKENDE;
 BLOCKENDE;
 MODUL forExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    i : integerzahl;
 BLOCK
    HOCHZAEHLEN (i) 
           VON 1 BIS 10
       BLOCK
           AUSGABE (i);
       BLOCKENDE;
 BLOCKENDE;
 MODUL repeatExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    i : integerzahl;
 BLOCK
    i << 2;
    SCHLEIFE
        i << i + 1;
        AUSGABE (i);
    SOLANGE i < 10;
 BLOCKENDE;
 MODUL whileExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    i : integerzahl;
 BLOCK
    i << 2;
    SCHLEIFEWENN (i < 10)
       BLOCK
         i << i + 1;
         AUSGABE (i);
       BLOCKENDE;
    ;
 BLOCKENDE;

Procedures/Functions Procedures/Functions Forward Declaration
 MODUL procExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    x : integerzahl;

 PROZEDURBLOCK sq ( REF i : integerzahl ) IST
    BLOCK
        i << i * i;
    BLOCKENDE;

 FUNKTIONSBLOCK inc ( i : integerzahl ) : integerzahl IST
    BLOCK
        inc << i + 1;
    BLOCKENDE;

 BLOCK
    x << 2;
    sq (x);  % procedure call: x = x * x %
    x << inc (x);
    AUSGABE(x);
 BLOCKENDE;

 MODUL forwardDeclExample 
         IST HAUPTMODUL;
 VARIABLEN_DEFINIEREN
    x : integerzahl;

 PROZEDURBLOCK sq ( REF i : integerzahl ) IST
     NICHT HIER;

 FUNKTIONSBLOCK sq_inc ( i : integerzahl ) : integerzahl IST
    BLOCK
        sq(i);
        sq_inc << i + 1;
    BLOCKENDE;

 PROZEDURBLOCK sq ( REF i : integerzahl ) IST
    BLOCK
        i << i * i;
    BLOCKENDE;

 BLOCK
    x << 2;
    x << sq_inc (x);
    AUSGABE(x);
 BLOCKENDE;

More Info
 * Comments begin and end with % and can go over more lines 
 * Read Keyboard/STDIN input with built-in procedure einlesen(REF ch:zeichen)
 * You can use Boolean Type WAHRFALSCH, where true/1 is WAHR and false/0 is FALSCH
 * You may use HEX-Values by putting a $ in front: e.g. $0A = 10
 * You may use Records as Array-Elements
 * Built-In procedure HALT exits the program at any time
 * Logical Op's are: AND, OR, NICHT
 * Reserved Keywords/Predefined Functions/Predefined Data Types are:

             KONSTANTEN_DEFINIEREN      STRING
             VARIABLEN_DEFINIEREN       FALSCH
             EINLESEN_BIS_RETURN        ARRAY
             AUSGABE_MIT_RETURN         BLOCK
             TYPEN_DEFINIEREN           MODUL
             FUNKTIONSBLOCK             NICHT
             PROZEDURBLOCK              SONST
             SCHLEIFEWENN               HALT
             END_OF_FILE                HIER
             HOCHZAEHLEN                WENN
             INTEGERZAHL                WAHR
             HAUPTMODUL                 AND
             WAHRFALSCH                 BIS
             BLOCKENDE                  CHR
             EINLESEN                   DIV
             ELEMENTE                   IST
             SCHLEIFE                   MOD
             AUSGABE                    ORD
             SOLANGE                    REF
             ZEICHEN                    VON
             RECORD                     OR        

Gunnar Ruhs Compiler - Universität Salzburg Gunnar Ruhs Gunnar Ruhs (2) Gunnar Ruhs Impressum