Green Compiler Manual


            This page shows how you can compile your Green program. First of all, you should prepare the compiler by downloading Then, unzip in a directory, say, C:\green. It will be created a compiler directory. In a DOS window, initialize classpath:

     set classpath=%classpath%;c:\green\compiler;c:\green\compiler\tests

Be very careful in typing this. A missing ; or letter will make the compiler unusable.

Compile the compiler:

     cd c:\green\compiler

     javac GreenCompiler\


Of course, you need the Java compiler for that. The required Java version is 1.3 or greater. The Java compiler can be got from

            The Green Compiler source code use is regulated by the  GNU General Public License. Therefore you can copy, modify, and redistribute it in accordance with this license.


            Suppose you created a program with classes Program, A, and B in files Program.g, A.g, and B.g. The main class is, say, Program. These files are in a directory “c:\user”. There are two ways to compile your program. The first is the easier. Create a text file “list.txt” with the names of the classes. The main class should appear first:






 list.txt  should be in the directory “c:\user”, the same directory as the classes. The file extension of  list” can be anyone but “.gp”. Now, in a DOS window, type

     java GreenCompiler.gc list.txt c:\green\compiler

Of course, we assumed the current directory is “c:\user”. The second argument for the Green compiler, “c:\green\compiler”, is the directory where the compiler is. The compiler will be called and it will compile classes Program, A, and B producing some Java classes (the compiled code).


To compile the java code the compiler produced, type


It takes a long time to compile. To run the code, type


It takes a long time to run.


There is already a test program like this in directory compiler\test2. You can use it to learn how to compile in Green.


            Before you type a Green program, you should know the compiler has some restrictions. Not everything that is in the manual was implemented. But almost everything was.


In the above example, the Green compiler creates a file “list.gpcontaining the project of the Green program. The content of this file is given below. The project contains all the information needed to compile a program.







arraydir = c:\green\compiler\test1\arraytmp

classdir = c:\green\compiler\test1\classtmp

interfacedir = c:\green\compiler\test1\interface

projectdir = c:\user

basiclib = c:\green\compiler\BasicTypes

wrapper = c:\green\compiler\Wrapper

templatedir = c:\green\compiler\ArrayCreate

lib = c:\green\compiler\IRL

lib = c:\green\compiler\BasicArrays

lib = c:\green\compiler\exceptionlib

lib = c:\green\compiler\GreenLib

lib = c:\green\compiler\GreenLib\DS


            The user could create directly a file “”. This is the second and more difficult way to compile a Green program. The Green compiler should be called as

       java GreenCompiler.gc


            The question you should be asking is “what is the meaning of the names that appear in ?”. That is explained later.


            We made 178 programs to test the compiler. They are in the directory compiler\tests. Before compiling them, you should follow some directions:

1. go to the directory tests:

            cd c:\green\compiler\tests

2. execute crebat:

             java CreBat 

     a file z.bat will be created. Execute it:

             z  c:\green\compiler     

     File z.bat will create one directory for each test. There will be 178 of them. Each directory contains the files of the test. If the directory begins with ok, like ok-sin02, the test should compile without errors. If it begins with er, like er-sem06, the compiler should signal an error during the compilation.


Go to one of the directories created and call the compiler:

   cd ok-ger01

   java GreenCompiler.gc

Then call do.bat:


and run:





The Project File


The project obeys the following grammar:


    Project ::= FileNameList  *OPTIONS OptionsList

    FileNameList ::= | FileNameList FileName

    OptionsList ::= Option | OptionsList Option

    Option ::=

       BASICLIB "=" FileName |

       LIB "=" FileName |

       WRAPPER "=" FileName |

       ARRAYDIR "=" FileName |

       CLASSDIR "=" FileName |

       JAVALIB "=" FileName  |

       TEMPLATEDIR  "=" FileName |

       PROJECTDIR "=" FileName |

       INTERFACEDIR "=" FileName |


       USEIRL |



    FileName ::= STRING | PATHNAME


FileNameList is a list of file names, the Green files (.g or .gi) that compose the program. They should not include the “.g” or “.gi” extension. The .gi file is a file created by the compiler for each .g file and contains the interface of the class of the .g file. “gi” stands for “Green Interface”.

            After the word “*options” there should appear a list of compiler options and directories. The options are:


The list of directories should contain at least arraydir, classdir, interfacedir, templatedir, wrapper, projectdir, and basiclib. They should appear like in the example arraydir should be the directory in which the compiler-created arrays are put. Each time an array like “array(A)[]” is used in the program the compiler creates an array class that is put in the directory arraydir. classdir is the directory in which the parameterized classes are put. If the program uses List(A), the compiler creates a class “List(A)” (whose Java name is $pc$List$1$_A) and puts it at directory classdir. interfacedir is the directory in which the compiler puts the interfaces representing  each program method ─ the compiler creates a Java interface for each method of the program.

            templatedir is where the templates for the array classes are located. Each array class is created from a generic class of the file “array-any-1.g” that should be in the directory templatedir.

            basiclib is the directory of the basic classes like char and integer. wrapper is the directory of the wrapper classes like Byte and Integer. projectdir is the directory of the project itself. All classes of the program should be in this directory. Finally, there may be any number of lib directory:

    lib = c:\green\mydir_1

    lib = c:\mydir2

Each should contain .g or .gi files that are included in the project.

Caveat: do not change classdir, interfacedir, or arraydir directories. That is, do not do this:

    classdir = c:\mydir2\classdir

    interfacedir = c:\mydir2\intdir

The compiler will not find some files it needs for the compilation.