Compilers
Spring 2008

Class # 0203-414-01

Time: MWF  1:30 p.m. - 2:35 p.m.

Location:
CO 326

Professor: David Galles
Office: HR 542
Office Hours:   T 10-12, R 2-3 or by appointment
                        Though these are my stated office hours, I am in my offices most of the day.
                        If my door is open (and it usually is), I am happy to talk with students.
                   

Phone: 422-5951
Email:
galles@usfca.edu


Textbook:  Modern Compiler Design D. Galles

Prerequisites:
Computer Science 245, Data Structures and Algorithms
Computer Science 210, Assembly Language
Computer Science 411, Automata Theory  (recommended)

Test Dates:

Test Weight Test Date
Projects
40%
Various
Midterm #1 15% 3/12/2008
Midterm #2 15% 4/18/2008
Final: 30% 5/15/2008 (Thursday) 8:00 a.m.

Finals and Midterms:
Both midterms and the final will be closed notes.

Projects:
You must turn in hardcopy printouts of the source files as described in the README file for each project, at the beginning of class on the due date. In addition, you must submit an electronic version of your source code using your submit directory. NOTE -- To pass the class, your final project needs to meet the minumum requirements in the Grading section

Late Policy:
Late projects will be accepted on the next class meeting after the due date for up to 75% credit. Projects will not be accepted later than one class meeting after the deadline. After 1:30 p.m. is considered late (In other words, do not skip class to finish an assignment.)

Grading:
Grades will be assigned on a straight scale, with Approximately

90-100% A
80-89% B
65-79% C
55-64% D
0-54% F

In addition to the above percentages, your final compiler must correctly compile the following code to obtain a C in the class (thus if your program cannot compile this file, you will get less than a C, and this class will not count towards the CS major):

void main() {
int inputVar;

inputVar = read();
inputVar = inputVar + 1;
print(inputVar);
}

In addition to the above percentages, your final compiler must correctly compile the following code to obtain an A in the class:

void PrintBoard(int board[], int size);
int Abs(int x);
boolean Legal(int numcols, int board[]);
void Solve(int numcols, int board[], int size);

void main() {
int size;
int board[];

size = Read();
board = new int[size];

Solve(1, board,size);
}

void PrintBoard(int board[], int size) {

int i;
int j;

for (i=0; i<size; i++) {
for (j=0; j<board[i]; j++)
print(0);
print(1);
for(j=board[i]+1; j<size; j++)
print(0);
println();
}
println();
}


int Abs(int x) {
if (x >= 0)
return x;
else
return 0-x;
}

boolean Legal(int numcols, int board[]) {
int i;
int j;
boolean legal;

legal = true;

for (i=0; i < numcols; i++) {
for (j=i+1; j<numcols; j++) {
if ((board[i] == board[j]) ||
(Abs(i-j) == Abs(board[i]-board[j])))
legal = false;
}
}
return legal;
}

void Solve(int numcols, int board[], int size) {
int i;

if (numcols > size) {
PrintBoard(board,size);
println();
}
else
for (i=0; i < size; i++) {
board[numcols-1] = i;
if (Legal(numcols, board)) {
Solve(numcols+1, board, size);
}
}
}

Finally, to get an A+ in the class, in addition to the above percentages, your compiler must correctly compile both of the above programs, as well as the following program:

class Point {
int x;
int y;

Point(int xval, int yval) {
x = xval;
y = yval;
}

void setX(int xval) {
x = xval;
}

void setY(int yval) {
y = yval;
}

int getX() {
return x;
}

int getY() {
return y;
}

void Print() {
print(x);
print(y);
println();
}
}

void main() {
int x = read();
int y = read();

Point p1 = new Point(x,y);
p1.Print();
p1.setX(y);
p1.setY(x);
p1.Print();
}

Attendance:
Students are expected to attend class. Topics that are discussed in class but are not in the text are fair game for the midterms and final.  While I will make an effort to make as much of the class material as possible available online, there will likely be some information that you will only be able receive by attending class.


Learning Outcomes:

Students who complete this course will be able to:

  1. Use regular expressions
  2. Design an EBNF for a language, given an informal description of the language
  3. Build a simple top-down (LL(1)) parser by hand for a simple language 
  4. Build a simple bottom-up (LR(1), SLR(1)) parser by hand for a simple language
  5. Understand the complete compilaion process, including lexical analysis, parsing, semantic analysis, and code generation
  6. Build a complete compiler using parser generator tools (javacc)