Coordinator: Gary Zoppetti
Students implement a compiler for a simplified modern programming language. Theory of compiler construction including finite state automata, LL(l) grammars and top-down parsing. Project includes lexical and syntax analysis, name storage, scope and type analysis, error recovery and code generation. Advanced topics covered as time permits including LR(k) grammars, bottom-up parsing, compiler generators (e.g., LEX and YACC) and code optimization. Offered infrequently.
C- or higher in CSCI 330, CSCI 340, and CSCI 362
- Recite the main phases of compilation; trace a compilation showing the transformation of a source program into different representations as it passes through these phases
- Design a finite state automaton (FSA) that recognizes the vocabulary of a given programming language; implement the FSA to yield a lexical analyzer for the programming language
- Implement a parser using bison
- Enhance the parser to give adequate error messages and to adequately recover from syntax errors in a source program
- Enhance the parser to provide scope and type analysis and to give appropriate error messages for an invalid source program
- Translate fundamental language constructs (e.g., declarations, expressions, assignments, I/O statements, boolean expressions, control statements, subprogram call/return, parameter transmission) into machine code
Major Topics Covered
- Phases of compilation
- Passes of compilation
- Single-pass compilation
- Multi-pass compilation
B. Compiler Administration
- Source file handling
- Listing file handling
- Compiler directives
- Top-level compiler structure
C. Lexical Analysis
- Theory: FSA and Regular Expressions
- Intermediate representation = tokens
- Symbol management and name storage
- Handling white space and comments
D. Syntax Analysis
- Theory: LL(1) grammars, top-down parsing, first and follow sets, grammar restrictions on LL(1) parsing
- Intermediate representation = parse tree
- Parser construction rules
E. Scope Analysis
- Blocks and scope rules
- Data structures needed
F. Type Analysis
- Standard types
G. Error Recovery
- Goals of error recovery
- The fundamental problem of error recovery
- Error recovery strategy
H. A Computer and its Machine Code
- Machine code format
- The stack
- Address computation
- Expression evaluation
- Statement execution
- Procedure activation
I. Code Generation of Source Code into Machine Code
- Generation of machine code instructions
- Variable Addressing Code
- Expression Code
- Statement Code
- Procedure Code
J. Additional Topics
- Regular Expressions and FSA
- LR(k) Grammars and bottom-up parsing
Sample Laboratory Projects
Open laboratories (2 weeks each)
- Commence implementation of a compiler, starting with its shell and adding administrative functions, including recognizing and obeying compiler directives, accessing source files, generating listing and object files.
- Implement lexical analysis for a given programming language and add it to the compiler.
- Implement syntax analysis for a given programming language and add it to the compiler in the form of a top-down parser.
- Enhance the parser so that it provides adequate error messages adequate error messages and so that it adequately recovers from syntax errors in a source program.
- Enhance the parser so that it provides adequate error messages for violations of scope rules in a source program.
- Enhance the parser so that it provides adequate error messages for violations of type rules in a source program.
- Enhance the parser so that it translates the source program to a given machine code.
Closed laboratories (completed in a two-hour supervised laboratory period)
- Design regular expressions and a finite state automaton (FSA) to recognize the vocabulary of a given programming language.
- Use a lexical analyzer generator (e.g. LEX) to construct a lexical analyzer from a regular expression.
- Design a bottom-up grammar for a given programming language.
- Use a parser generator (e.g. YACC) to construct a parser from a grammar.
- Alter the search strategy used in the symbol table management routines to gain an understanding as to how the table organization and search strategy can affect the efficiency of the compiler.
- Design a top-down grammar for a given programming language.
- Implement a program that computes the first and follow sets for a given grammar and determines whether or not the grammar is LL(l).