CSCE 531 Spring 2010: The Triangle Language Processor

The Triangle language processor is briefly described in Section 2.7 of your textbook. It consists of a compiler, interpreter, and disassembler, each of which is written in Java.

These three language processors have been installed on the departmental Sun workstations and the departmental Linux workstations. In order to use them most easily, I recommend that you add the following line to your .cshrc or .tcshrc file:
source /usr/local/etc/csce531/csce531-spring07.csh
or the following line to your .bashrc file:
source /usr/local/etc/csce531/csce531-spring07.bash
In this way, your CLASSPATH environmental variable will be modified to include the directories with the relevant Java libraries, and your PATH environmental variable will be modified to include the directories with the relevant executable files.

After you do this, you may execute the triangle compiler, disassembler, and interpreter, by using the commands tc, td, and ti respectively. Here is a detailed example, which uses the following program, in file triangleTest.txt:

! test program
let
 var n: Integer
in
 begin
 n := 1;
 putint(n);
 puteol();
 end

mgv@hadar 32 % tc triangleTest.txt 
********** Triangle Compiler (Java Version 2.0) **********
Syntactic Analysis ...
Contextual Analysis ...
Code Generation ...
Compilation was successful.
mgv@hadar 33 % ll
total 2
-rw-r--r--   1 mgv      faculty       128 Sep 13 17:21 obj.tam
-rw-r--r--   1 mgv      faculty        82 Sep 13 17:21 triangleTest.txt

mgv@hadar 34 % ti
********** TAM Interpreter (Java Version 2.0) **********
1

Program has halted normally.
mgv@hadar 35 % td
********** TAM Disassembler (Sun Version 2.0) **********
0:  PUSH        1
1:  LOADL       1
2:  STORE (1)   0[SB]
3:  LOAD  (1)   0[SB]
4:  CALL        putint  
5:  CALL        puteol  
6:  POP   (0)   1
7:  HALT  
mgv@hadar 36 % 

Please see the textbook website by its authors for additional information on the software implementing the Triangle language processors. Please see the textbook for a description of the Triangle language (esp. Appendix B) and of the Triangle Abstract Machine (esp. Appendix C).