Compilers Notes: Triangle

This is the zip file. It contains the source code

This is the jar file. It contains the bytecode

Here are some *.trifiles for you to try with the Triangle compiler:
Example One
Example Two
Example Three

To run the TriangleCompiler/Interpreter (you must have Java):

        Download the jar file onto your computer

        Using the command prompt type the following command inthe directory where you saved Triangle.jar (you may need to use ‘cd <yourdirectory>’):

C:\myDirectory>jar -xf Triangle.jar

        Download one of the (dot).tri files listed above orcreate your own in the same directory

        To compile it type:

C:\myDirectory>java Triangle.Compiler mySourceCode.tri

        To run the compiled code (saved as 'obj.tam') type:

C:\myDirectory>java TAM.Interpreter obj.tam

        That's it. You can now run any source code you find inthe book. If anyone knows how Example Three works, let me know.

To compile theTriangle Source Code:

          Before you try to do this, there is abug in the file.  Online 181, “case SourceFile.eot:” should be changed to “case ‘\000’:” asspecified by page 121 of your book. Once you have corrected this, you may beginthe following instructions, which pertain to the command prompt environment. If you’d like to use JBuilder7 Personal instead, click here.

        Download the file onto your computer

        Unzip the file into a folder (preferably the C drivefor easy access). Rename it if you like.

        Using the command prompt type the following command inthe directory where you’ve unzipped (you may need to use ‘cd<your directory>’):

C:\myTriangle>javac –classpath TAM\*.java

This compiles all the java files located in yourTAM directory. At this point, you may want to verify this using your Windowsenvironment.

        Similarly, you can compile the Triangle folder.

C:\myTriangle>javac –classpath “.” Triangle\*.java

The extra “.” is necessary because Triangle hasfive subdirectories with java files as well, and this tells the compiler tolook for those as well.

         That’s it. You can now run the Triangle.Compiler and TAM.Interpreter using the commandsmentioned in the previous section

C:\myTriangle>java Triangle.CompilermySourceCode.tri
C:\myTriangle>java TAM.Interpreter obj.tam

        You may notice that your class files and java files areknow mixed up in the same directories. If this bothers you, you can type:

C:\myTriangle>javac –d Tools –classpath “.” Triangle\*.java

What this does is place all the class files in the empty Tools directory thatyou already have. The only thing is that you must ‘cd’ into that directorybefore you trry to run Triangle.Compiler or TAM.Interpreter because those classfiles are now there.


By David Herrera, Spring 2003. Revised by Nigel Ward, Spring 2004.