| FM Compiler Project |
Introduction
The ultimate goal of this project is understanding the structure of a compiler and building a compiler by implementing its fundamental components step by step. A compiler should be able to read and analyze entire program in a certain programming language, and then translate the source program to semantically equivalent program in a target language. To accomplish its roll, the compiler will have three major components - I/O, scanner, and parser component - in this project. Eventually, the compiler will take and compile source files in a simple language called FM (for flip movie) and will output Postscript files that describe the pages of a flip movie. However, a compiler for any other languages can be designed mostly in the same manner.
CompilerIO
A class CompilerIO will handle input and output for the compiler. The idea behind this class is that the compiler will use a single CompilerIO object to manage input and output, which will shield the rest of the compiler from the details of file handling. When the compiler starts, it will create an instance of the CompilerIO class. In addition to reading and writing files, the CompilerIO class will manage the temporary buffer to which the compiler emits generated code so that one can later use it several times as needed.
Scanner
A class Scanner (lexical analyzer) reads the characters representation of a program and transforms it into a stream of tokens representing the basic lexical items in the specified language. The scanner skips over whitespaces and comments in the source code; these are ignored by the compiler and do not appear in the token stream that will eventually be read by the parser. The scanner demonstrates the use of a simple DFA (Deterministic Finite Automata) to recognize regular expressions. (see also the keywords of FM language)
Parser
A class Parser reads the tokenized representation of a program (generated by the scanner) and validates it against the grammar for the language generated by the associated grammar. Thus, the parser takes advantage of CFG (Context-Free Grammar). The parser also creates symbol table entries for defined variables in the language, and generates actual codes in a target language as the parser discovers any specific structure of the program. Although the parser handles basic syntax errors and exceptions, it does not do extensive error processing or recovery as the industrial-power-compiler usually do. In this project, we adopts a Recursive-Descent Parser which is considered to be easier to implement, but sufficient for a simple language. Taken advantage of top-down parsing, we shall use LL(1), leftmost derivation with 1-pass lookahead, while we still need the power of ad-hoc in some cases. (see also the definition of FM language grammar)
Note: You're free to improve the program, or use it as a framework to build a compiler for another language. Just let me know if you happen to kick off an awesome compiler anyhow. I'd like to see it!
Full Packaged File
See JavaDocs for Source Files
Source Files List
Other Files Required
Other Optional Files
To View Postscript files (Flip movies)
Sample Still Images of Postscript files
|
|
by Hyung-Joon Kim, CSE 413, University of Washington






