GZCC is a simple compiler-compiler for Java and C++. Some course in Compiler Principle is a prerequisition for using this tool. The output of GZCC is a compiler with an LR1 syntax analyzer (parser) and a DFA Lexical analyzer. GZCC supports Chinese characters and those of the other countries.

(1) Introduction
GZCC accepts a single compiler description file and generates a compiler in either Java or C++.
GZCC accepts files of 2 formats.
a) JCC format which is more powerful and complicated.
b) GZCC format which is simpler.

(2) Install and run.
INSTALLATION (after installing JAVA and opening a CMD prompt)
a) First unzip "gzcc.zip" into a folder. After unzipping, there will be 3 folders (gzcc, jcc, & jcg) and some files (README.txt, ACompiler.cpp, cal.gzcc, etc).
b) Compile GZCC with command:
javac jcg\*.java jcc\*.java gzcc\*.java

RUN A EXAMPLE
a) An integer calculator (cal.gzcc) is implemented in GZCC format as an example. The first step is to generate a Java (or C++) format compiler with this compiler description file "cal.gzcc" with the following command:
java gzcc.gzcc cal.gzcc
b) When finished, two files will be generated: "cal.jcc" and "cal.java". The generated compiler is "cal.java". We run this compiler for integer calculation with the following commands:
javac cal.java
java cal
c) Input an integer formula in the console, such as 4*(3+5), followed by a  and press . The result of the input formular will be shown.

(3) Generating a C++ format compiler.
a) Open "cal.gzcc" and change "// Java" in line 3 to "// C++" (which tell the compiler-compiler to generate a C++ format compiler). 
b) Run the following command again:
java gzcc.gzcc cal.gzcc
and the compiler "cal.cpp" will be generated.

(4) Structure of the GZCC project
The project includes 3 packages: jcg, jjc, & gzcc
a) The "jcg" package contains the compiler framework and the compiler generation tools. Specifically, a compiler-driver which contains the function calls required by the generated compilers (for C++ format compilers, the compiler-driver is "ACompiler.cpp"); a LR1 table generator, and a DFA tablegenerator.
b) The "jcc" package contains the code which translate a JCC format compiler description to a Java (or C++) format compiler.
c) The "gzcc" package contains the code which translate a GZCC format compiler description to a JCC format compiler description.

(5) Understanding and reading the source code
a) Read "cal.gzcc" for a basic understand of the GZCC format. In this file, "%import" is a keywork, and "%{...}%" designate some code that will be copied to the output compiler file (in Java or C++). Here "%import" means the following code will be copy to the first lines of the output Java file. Each terminal is presented with a regular expression and each nonterminal has a type. Line 6-8 defines type "Int", and line 10 declares that nonterminals "E", "T", and "F" are of type "Int". In line 12, "start" is a keyword which represents the start symbol (or the whole input file) of the compiler. The rest of the input file consists of grammar expressions and thier reduction actions (the code inside "%{...}%" following each grammar expression). In each grammar expression "->" is a keyword which separates the left side and the right side of the grammar expression. Inside the action code, we use %i to represent the the i-th symbol in the grammar expression, starting from position 0. For example, in lines 16-21, "%0" represents "E" on the left side of the grammar expression and "%1" represents "E" on the right side. Note that terminals are automatically asigned to type "String" as in Java, and each nonterminal must be manually asigned a type before used. In this example, since "E" was defined as of type "Int", "%0" and "%1" can access the member variable "value" of type "Int".

b) Read "gzcc/gzcc.gzcc" for a deeper understanding of the GZCC format. This file is a GZCC format compiler description which translates a GZCC format file to a JCC format file (i.e., this file contains a description of its own format). Keywords "%constructor", "%member", and "%error" function similarly to "%import". They copy code to different places in the output Java/C++ file (which can be found by comparing the JCC and the output JAVA file).

c) To understand the JCC format, one can compare any GZCC file with its corresponding JCC format file. In a JCC format file, every terminal must be defined with a regular expression. "ret" is a predefined type for symbols (terminals and nonterminals). "air" is also a predefined type for terminals which means a type of terminals that will be ignored by the parser. In JCC, handles for symbol in a grammar expression is defined explicitly by a identifier following a symbol surrounding by a pair of parenthesis.

d) To understand the JCC format deeper, read all the JCC files inside folder "jcc". These files describe a translator which read a JCC format file and create an object of a data structure that will be further processed to generate a Java or C++ compiler by the "jcg" package (i.e., these files in the JCC format contain a description of the JCC format itself). Note that the JCC format has additional functions compared to the GZCC format, which include calling between compilers. That is why there are multiple JCC format files in the "jcc" folder -- "data.jcc" calls the other JCC files.

(6) Generating compiler from a JCC format file.
With the following command:
java jcc.jcc cal.jcc
Here "cal.jcc" should be replaced by whatever JCC format file you create.

    Source: geocities.com/gzcliu_proj/gzcc

               ( geocities.com/gzcliu_proj)