Decaf compiler for Jasmin assembler. Raj kumar Nagarajan - rknagara@csc.ncsu.edu Introduction: Decaf is a subset of Java language. Jasmin is an assembler, that generates Java Class files, given a .j file. The decaf compiler generates a jasmin file given a decaf program input. The jasmin file can be compiled using jasmin, when can be then run on Java. Compiler Flow: 1. Generate the tokens (lexical analysis) 2. Parse the input file based on the grammar (syntax checking) 3. Generate the Abstract Syntax Tree (AST) 4. Generate the Symbol Table from the AST. 5. Do the Type Checking using the symbol table and AST. 6. Generate the code. AST: The AST has several structures, that generates a tree structure given a decaf file. AST is used by all the other stages of the compiler. Symbol Table: The symbol table is genrated from the AST. There are 4 differant kinds of symbol table types. a. class_type - Contains the information about the class. Contains the method table and field table for the class. b. method_type - Contains the information about the method. Contains the formal arguments table for the method. c. field_type - Contains the information about the field. d. var_type - Contains the information about the variable. The symbol table handling routines of appel have been used for this purpose, with slight modifications. It is basically a hash table. Type Checking: The type checking is done based on the given specification. All the type checking cases have been handled. The following are the decaf_types. a. Primitive types - IntType, CharType, BooleanType, VoidType b. ClassType - Class type. Conatins the class name. c. ArrType - Array type. Contains the type of array and also the dimensions. d. MethodType - Method Type. Contains the Return Type and the list of arguments type. e. TypeError - Error Type. Code Generation: A temporary buffer is maintained for the code generated, before it is written on to the jasmin file. This buffer is in the form of Sections, which has a linked list of output lines. Three sections are defined for a class: a. field_section - Contains the field directives. b. constr_section - Contains the definition for the constructor. c. method_section - Contains the definition for all the methods. Both type checking and code genration use active_stack, a symbol table for storing all the intermediate symbol types. Reference: http://www.cs.princeton.edu/~appel/modern/java/