I will teach the concepts of designing compilers and interpreters for programming languages. You will use Java to write your compilers and interpreters. The source language that you will translate initially will be a major subset of Pascal, a simple but powerful procedure-oriented language. Your compiler will generate Jasmin assembly code for the JVM, the Java Virtual Machine. (You will be provided an assembler.)
In the first part of the course, you will learn about the translator front end of compilers and interpreters: the scanner and the parser; and about their middle tier: the symbol table and the intermediate code (parse tree). I will provide Java code for you to understand, modify, integrate, and deploy into a working translator that will read a Pascal program and create the symbol table and the parse tree.
In the middle part of the course, I will again provide Java code for you to implement the back ends of a compiler and an interpreter. You will be able to run your Pascal programs, both interpreted and as executable code compiled for the JVM!
By the last part of the course, you will have a good understanding of the concepts behind compilers and interpreters. We'll then examine JavaCC, the Java Compiler-Compiler. You'll learn how to provide JavaCC with a grammar that defines a source language, and it will automatically generate the Java code that implements a scanner and a parser for that language. Your project will be to use JavaCC and create your own compiler for Pascal or another programming language that you choose — or even invent your own language.
I am currently writing the third edition of my book, Writing Compilers and Interpreters: A Software Engineering Approach. I will provide drafts of chapters from this book to serve as the main text for the course. This has both advantages and disadvantages. You will get chapters from a new book for free. You will help me clarify the text and debug its programs. Students who provide substantial useful feedback will, with their permission, be named in the book's acknowledgments. You will get an instructor who is familiar with the course text. (But be aware that the author of a book hasn't necessarily read the book!)
Being the geek that I am, I am enthusiastic about compiler writing and I hope to convey some of that enthusiasm to you. The field has a substantial body of theory and algorithms, especially in the areas of parsing and optimization. But I want you to learn by doing — by getting code to work. So at least initially, we'll employ relatively simple techniques and algorithms. You'll work together in small teams. Bring your laptops to class so we can try to have some "lab time" and share the excitement of seeing our code in action.
Compilers and interpreters are complex programs! Throughout the course, I will emphasize and insist upon good object-oriented design and software engineering practices. I hope the course will be exciting, fun, and educational.
| Past courses I've taught at SJSU |
|---|
| Spring 2008: CS 160 Software Engineering |