Class Description
An introduction to compiler design and construction. This is a hands-on compiler construction course in which each student will work independently to construct a compiler that actually compiles a rather complex C like language including recursive functions and arrays. The student will be carefully guided toward a successful completion by working on incremental development and testing of the compiler. On line testing tools will be available for constructing your compiler.
Time: 2:30-3:30 Pacific Time MTWTh(F) (Friday is optional Q/A day)
Location: Live at the time above via Zoom (no face to face class only "take-home" tests).
See BBLearn for class for Zoom id. Yes, you can take this course anywhere in the world.
Tests: There will be two take-home tests.
Final: None! Just the big compiler project.
Coding: *Lots* of C++, plus UNIX skills.
Goals:
- Understand the basic theory of languages and techniques for simple language translation.
- Understand the features of compilers and interpreters.
- Understand why compilers behave as they do and why languages may be designed the way they are in response to compiler constraints.
- Understand the basic components and layered design of a compiler and the rationale for their use.
- Each student will be responsible for INDEPENDENTLY building a simple compiler for a virtual machine. The compiler will handle typing, procedure invocation, arrays, recursion, optimization, global and local scope, arrays, etc. The instructor will help the student to achieve this goal over a series of assignments, but it is up to the student to keep up with the assignments and complete each on time.
It is highly recommended that students be proficient in C or
C++ and have good data structures skills. The students will be
expected to write a program that has from 2000 to 5000 lines of
code depending on how they solve the problems presented. A tiny sample compiler
will be provided and some example pieces of code and support libraries provided. Since this
is a phased development, completing each assignment in sequence
and having good time management skills is critical.
You must successfully complete each phase in order.
These are skills that employers are looking for. In fact our industrial
advisory board particularly likes the compiler course as a test of the skills
of applicants.
A partial list of necessary skills to be successful at compilers
![]()
|
Recommended Textbook:
Compiler Construction: Principles and Practice by Kenneth Louden, ISBN: 0534939724, Cengage Learning I intentionally use this book a lot so you can use it for support. It is no longer published by the publisher. Why use it? It is really good for a practical coverage without getting overly involved with optimization and theory. It is available used on line and perhaps other means. Students who buy a copy have found copies to be under $60. I will cover in class all you need to know but the book is great for review. |
![]() |
Estimated Syllabus (WARNING: This is an approximation)
This syllabus is an estimate of what we might cover this semester. The class varies from semester to semester to reflect new and interesting topics.
Wk# | Monday |
Topics/Links | Assignments | Comments |
---|---|---|---|---|
1 | Jan 11 | Introduction to the class, what we plan on doing, how the class works, where to find stuff. How is a compiler organized. | assignment | NO CLASS MONDAY |
2 | Jan 18 | Scanners and how they are defined, grammars, intro to flex and bison. | Read Chapter 1, assignment 1 | NO CLASS MONDAY - MLK/Human Rights Day |
3 | Jan 25 | more on scanners, UNIX tools for homework submission, syntactic analysis | Read Chapter 2, calculator demo code from this week | |
4 | Feb 1 | Context Free Grammar review, Study: A Tutorial on Grammars, | Read Chapter 3 | |
5 | Feb 8 | First and Follow sets, formal LL(1) development | Read Chapter 4, assignment 2 | |
6 | Feb 15 | various LR parsings and getting bison to build your syntax tree | Read Chapter 5 | NO CLASS MONDAY. President's Day |
7 | Feb 22 | Symbol tables, type checking, and discuss what you need to know to do assignment 3 | Read chapter 6 | Assignment 3 |
8 | Mar 1 | more attribute grammar stuff and answer questions on assignment 3 | ||
9 | Mar 8 | Attribute grammars and how to finish out our syntax tree | Assignment 4 | |
10 | Mar 15 | NO CLASS THIS WEEK! SPRING BREAK | ||
11 | Mar 22 | Using the error token in Bison, start looking at the Tiny Virtual Machine | Assignment 5 | |
12 | Mar 29 | Discuss assignment 4. Study the Tiny machine and memory allocation | Assignment 6 | |
13 | Apr 5 | More on the virtual machine and assignment 4 | Read Chapter 7 | |
14 | Apr 12 | Memory allocation and code generation, extensions to C- that are common in many languages but that we won't actually include. | ||
15 | Apr 19 | Examples of code generation | Assignment 7 | |
16 | Apr 26 | Some on record types, object oriented languages, Optimizations in general, local optimizations, code selection, register allocation | ||
17 | May 3 | |||
17 | May 10 | FINALS WEEK (NO FINAL FOR US) | Final: None |
References and Resources
- The "whiteboards" from all the lectures tagged by date
- The Grammar for the Tiny Language
- The Grammar for the C- Language
- Basic UNIX command information including stuff about sdiff
- A Regular Expression Reference
- A Flex Primer
- A Make Primer
- A Tutorial on Grammars
- A Bison Primer
- The Bison Manual (1992 version of the book) for version 1.20
- The Bison Manual (2002 version of the book) for version 1.35
- The Bison Manual (2010 version of the book) for version 2.4.3
- Building LL parser using first and follow sets
- A list of Bottom up Parser Algorithms
- A discussion of the difference between SLR and LR parsers using an example
- Examples of Bison Parser Errors and Fixes
- The getopt man page
- A getopt example program
- The getopt header file
- A getopt replacement that does what gnu getopt does but you can compile anywhere.
- A detailed discussion of the dangling else problem
- Using the error token in Bison
- Dr. Jeffery's Lecture on Bison error handling and the Merr tool
- Debugging Seg Faults is a useful handout. Conquer your fear of seg faults.
- A gdb (Gnu Debugger) Primer
- The Tiny machine (TM) description
- A possible template for the files for assignment 2. This is just a suggested layout you can compare against your own. Comments are included why somethings are where they are.
Code and Coding References
- files for a logic calculator
- files for a numeric calculator
- Parser code reading
- A tar of the code for the Tiny compiler
- A tar of C++ symbol table code that includes debugging
- emitcode.cpp and emitcode.h to emit tm instructions.
- The layout of many popular control statements
- The TM 4.5 (Tiny Machine) machine is tm.c
tmDescription.pdf a description of the tm machine. - An example of the I/O Library in tm code.
Services
-
Homework submission page. This our homework submission page. This
is not to be confused with any other submission tools used in
the CS department. This is How Testing Works
- Submitting homework
without a browser
- Computer
Science IT FAQ including information on logging onto class
machines.
- The CS445 student machine is called cs-445.cs.uidaho.edu. If you
are off campus you can access this machine only by first "coming on
campus" with VPN. For details see CS IT FAQ The
compile command I run on that machine is:
scl enable devtoolset-7 "make"
to get the same compiler and options. The devtoolset-7 command is an annoying command prefix you have to use to access to g++ 7.3.1 which gives you most if not all of C++17. This arcana is a consequence of the Linux distribution we are using.If you log onto the CS445 student machine, I recommend the first thing you do is type:
scl enable devtoolset-7 "bash"
to open up a new shell inside the advanced tool set. Then compile as normal and you will have the more advanced compiler. You'll have to exit twice to leave.
Policies and Processes
Cool Links
These links are provided to entertaining and informative. You don't need to study them unless it is suggested that you do so. These links are not guaranteed to accurate, contain information that is safe to download, or not offend your morals, good sense or good taste, or to give sound financial advice. Some small parts may pose a choking hazard for children...- Jflex a java version of flex. It has links to Java based parser generators.
- Cygwin in case you want that comfortable UNIX feel on your Windows box. This will give you a command shell and numerous UNIX tools for Windows.
- LCC a retargetable free C compiler with lots of goodies.
- A list of over 2500 computer languages
- Zebu A parser generator for generating Common Lisp code
- ANTLR A popular LL parser generator
- A Python lex and yacc