****************************************************
TACG: Three Address Code Generator for a subset of C
****************************************************
TACG is a bare-bones version of a C-like compiler.
It includes 3 modules for
1. Lexical analysis
2. Parsing & symbol table management
3. 3 address code generation
TACG supports code generation for only integer types and
statements and expressions involving integer literals,
variables and operators.
It contains only two kinds of statements in the following
order-
1. declaration (and/or initialization) of int variables
2. statements and expressions involving integers
The source may also contain single line comments that
begin with "\\" and end with a new line character.
The operators allowed are same as that of K&R-C for int
types. Operators in decreasing order of precedence are-
1. parenthesis ()
2. logical not !
one's complement ~
pre/post increment ++
decrement --
unary plus +
unary minus -
3. multiplication *
division /
modulus %
4. addition +
subtraction -
5. logical left shift <<
logical right shift >>
6. less than <
less than or equal to <=
greater than >
greater than or equal to >=
7. conditional equal to ==
conditional not equal to !=
8. bitwise and &
9. bitwise ex-or ^
10. bitwise or |
11. logical and (long circuit) &&
12. logical or (long circuit) ||
13. conditional operator ?:
14. assignment operators =, +=, -=, *=,
/=, %=, &=, ^=,
|=, <<=, >>=
15. comma ,
Note: The logical AND and logical OR operators are a
deviation from the otherwise short circuit operation.
Associativity rules are also same as usual, all except
the unary operators, conditional and assignment operators
are left associative.
--------
Contents
--------
The tacg directory structure-
tacg
+--bin
| +--tacg.jar
| +--tacg.bat
| +--tacg.html
| +--readme.html
+--src
| +--Tacg.java
| +--TacgApplet.java
| +--[other java files for code generation]
| +--Yylex.flex
| +--tacg.CUP
| +--flexify.bat
| +--cupify.bat
| +--compile.bat
| +--jarify.bat
+--examples
| +--[text input files]
| +--[.tac output files]
+--readme.txt
------
Usage
------
You need a jre 1.5.x to be installed on your machine
before you can use Tacg. Tacg can be run in two modes.
1. Command line mode (for input and output to be in the
form of files) using tacg.bat file.
>>java tacg.Tacg [input file]
You can add the tacg/bin directly to the path variable
in case you want to run it from any directory.
2. GUI mode using the TacgApplet.html
To run the applet, simply open the html file
TacgApplet.html from the tacg/bin directory.
-------------------
Development Details
-------------------
This utility has been developed in the java programming
language and j2sdk-1.5.0_01 was used to compile the
source.
The Tacg class contains the basic interface to interact
with the application. It also contains a main program to
run tacg from the command prompt. The package also
contains TacgApplet class using which you can run the
tacg using a web browser.
The scanner is generated using the JFlex
lexical analyzer generator (Yylex.java). The file
tacg\src\Yylex.flex is the input file for generating the
scanner from JFlex.
The CUP parser generator(sym.java and parser.java).
The input file for the same is tacg\bin\parser.CUP.
The SymbolTable class implements a symbol table using the
Hashtable class of the java.util package.
The TACG has bare minimum at error handling and reporting
routines. Most of the errors are handled by the parser
since there is no semantic analyser routine.
The code generation logic is handled by the following
java class hierarchy-
CodeGenerator(I)
+--Expression(A)
+--Literal
+--Identifier
+--Operator(A)
+--UnaryOperator
| +--IncDecOperator
+--BinaryOperator
| +--AssignmentOperator
+--TernaryOperator
(Key I:Interface A:Abstract class)
The design of the code generator is an instance of the
Composite design pattern (see Gamma et al).
-------------
Build details
-------------
Step 1: Modify Yylex.flex if reqd and run
flexify
Step 2: Modify tacg.CUP if reqd and run
cupify
Step 3: Modify other java files if required and run
compile
Step 4: update the tacg folder in tacg.jar by running
jarify
These are 4 bat files in src.
Thankyou for downloading TACG. Do send in your comments,
suggestions or bug reports to C.M.Shivkumar.
Code Unleash