In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance and encapsulation. By design, it has many similarities with C/C++/Java, so you should find it fairly easy to pick up. Keep in mind it is not an exact match to any of those languages. The feature set has been trimmed down and simplified to keep the programming projects manageable. Even so, you’ll still find the language expressive enough to build all sorts of nifty object-oriented programs.
This document is designed to give the specification for the language syntax and semantics, which you will
need to refer to when implementing the course projects.
1 Lexical considerations
The following are keywords. They are all reserved, which means they cannot be used as identifiers or
An identifier is a sequence of letters, digits, and underscores, starting with a letter. Decaf is case-sensitive,
e.g., if is a keyword, but IF is an identifier; binky and Binky are two distinct identifiers. Identifiers can
be at most 31 characters long.
Whitespace (i.e. spaces, tabs, and newlines) serves to separate tokens, but is otherwise ignored. Keywords and identifiers must be separated by whitespace or a token that is neither a keyword nor an identifier.
ifintthis is a single identifier, not three keywords. if(23this scans as four tokens.