Syllabus
CSCI 4627
Procedural Languages and Compilers
Spring 2018

Class meeting TBA
Instructor Karl Abrahamson
Office Sci&Tech C-113
Office hours MThF 11:00–12:00, MW 4:00–5:00
Phone 328-9689
Email abrahamsonk@ecu.edu
Course web page www.cs.ecu.edu/~karl/4627/spr18/
My web page www.cs.ecu.edu/~karl/
Text Compilers: Principles, Techniques & Tools by A. V. Aho, M. S. Lam, R. Sethi and J. D. Ullman
Notes Notes for CSCI 4627
Notes on C Notes on C

Contents

  1. Prerequisites
  2. Introduction
  3. Course objectives
  4. Topics and competencies
  5. Incompletes
  6. Grading
  7. Additional information

Prerequisites

You should have a good understanding of programming and be able to write well structured and well organized programs in C, C++, Java or a similar programming language. We will write programs in C.


Introduction

A compiler translates a program from one language to another or from one form to another. Some compilers generate machine language, some generate assembly language, some generate more portable code such as C code, some create abstract machine code, and some just generate data structures that are used by other parts of a program.

The first compilers were written in the 1950s. Compiler developers had a poor understanding of what they were doing, and did everything in an ad-hoc way. The popular wisdom was that it took 30 person-years to write a compiler, even for a very simple programming language such as early versions of Fortran.

(Considering the state of the art at the time, the compiler developers did a remarkably good job. Their code optimizers produced excellent machine code. That was really important because if the compilers produced poor machine code, programmers would have been much slower to adopt Fortran.)

There is probably no aspect of software development that has benefited from developments of the last 50 years more than the construction of compilers. Developments in the theory of computing have led directly to very powerful tools that not only make compiler writing much easier than it once was, but are also useful for other kinds of software. It is now feasible to write a compiler for a small programming language as a course project.

It is useful for a computer scientist to study compiler design for several reasons.

  1. Anyone who does any software development needs to use a compiler. It is a good idea to understand what is going on inside the tools that you use, in order to have a better understanding of their capabilities and their limitations.

  2. Compilers are sophisticated text processors. Most programs need to do some text processing, even if only to read in the contents of a configuration file. Techniques that were developed for writing compilers are useful in a variety of other software.

  3. A useful software design technique for large projects is to develop a special-purpose language that makes the project easy to implement. It can take less time and effort, and lead to a higher quality product, to spend the time to develop and implement a small special purpose language and to write the software in that language than to write the software in a general purpose language.

    One example is the language Erlang, which was designed for writing software to control data switches. Erikson created a data switch all of whose software was written in Erlang. They claim downtime due to software bugs per switch in the range of milliseconds per year.

    There has been growth in the development of domain-specific languages. Studying compilers enables you to design and implement your own domain-specific language.

  4. Compilers benefit tremendously from careful analysis of a problem, and from tools for performing that analysis. A study of compiler design gives a good feeling for how a large problem can be broken down and solved in a manner that is not ad-hoc.

  5. Compiler design makes use of formal methods that are rarely seen elsewhere except when quite difficult formal methods are used for general purpose software design. The study of compilers provides a gentle introduction to formal methods.

  6. A course in compilers offers a good opportunity to get experience with development of a larger piece of software.


Course objectives

After completing this course, the student should understand the theory and practice of compiler design, should be able to describe the components of a compiler and how they relate to one another, and should be able to apply that knowledge to implement a complete compiler for a small programming language.


Topics and competencies

Topics will be as follows.

  1. Overview of compilers. The compilation process and the anatomy of a compiler.

  2. Lexical analysis. The role of the lexical analyzer. Finite state machines. Regular expressions. Lexical analysis tools and lexer generators.

  3. Context-free grammars. Writing grammars for programming languages.

  4. Parsing. Top-down predictive parsing and LL(1) grammars. Table-driven parsers. Transformations on grammars. Bottom-up parsing, SLR(1), LR(1) and LALR(1) parsers. Parser generators.

  5. Syntax-directed translation. Attribute grammars. Construction of abstract syntax trees. Translation based on abstract syntax trees.

  6. Table management. The symbol table.

  7. Direct evaluation of syntax trees by an interpreter.

  8. Additional topics might include: Target languages. Intermediate code and abstract machines. Semantic analysis. Code optimization.

After taking this course, the student should be able to do the following.

  1. Define terminology relevant to compilers.

  2. Build a lexical analyzer using Flex.

  3. Produce context-free grammars for given languages.

  4. Derive properties of context-free grammars, such as FIRST and FOLLOW sets.

  5. Produce an SLR(1) parser table for a given context-free grammar.

  6. Describe more general LR parsers, including LR(1) and LALR(1) parsers.

  7. Build a parser for a given language using Bison.

  8. Describe and implement symbol tables.

  9. Explain how a parser can perform syntax-directed translation.

  10. Write an interpreter that performs tree manipulations.


Incompletes

No incompletes will be issued in this course except for extraordinary circumstances, and even then only if you are nearly done already, and have done work of acceptable quality that it is realistic that you can pass the course.


Grading

Grading will be based on three midterm exams, a final exam, and a programming project.


Additional information

For information about

please see the auxiliary information at syllabus-aux.html.