Please Reload Every Time You Read This Page!

CSC 124/258: Compiler Construction, Spring 2014

Dr. Chuck C. Liang
Professor of Computer Science, Hofstra University .

Office Address:
201A Adams Hall
Hofstra University
Hempstead, NY 11550
Office Phone: (516 463) 5559

Email: (<- click to send me mail)

Official Office Hours: Monday-Thursday 3:30-4:30pm

The homepage of the previous time that I taught this course is available here

Course Syllabus

Online Resources:

The following are the components of my "jBASIC" sample interpreter. Although it is an interpreter as opposed to a compiler, it contains many of the same basic components as a compiler.

  1. jbl.flex. The lexical scanner specification to be processed by JFLex, for use with my own parser generator. Here's the one to use with Java Cup.
  2. jb.grammar. The grammar specification used by my own LR(1) parser generator. Here is the same grammar in Java Cup syntax (version .10k). The "semantic actions" of this file builds an abstract syntax tree, defined in the next file:
  3. This file contains classes for building abstract syntax trees for jBasic, as well as code that will execute a jBasic program given its abstract syntax representation.
  4. This is the top level file that combines the lexer/parser with the interpreter defined in the above file. If you wish to run it before having completed your own parser generator, you should use the version for java cup.
  5. factorial.jb. Here is a sample jBasic program that computes 5!.
  6. README. Instructions on how to put everything together and run the interpreter (using Java cup).

Lambdascript example: programming with pure lambda terms using Krivine's abstract machine:
java implementation, LR(1) grammar and sample program.

Some sample grammars (in my syntax):

  1. simple LR(0) grammar
  2. slightly more interesting LR(0) grammar
  3. Ambiguous grammar with reduce-reduce conflict,
  4. Grammar for testing Nullible, First and Follow set computations
  5. Ambiguous grammar for online calculator. Must read the attached comments.
  6. Unambiguous SLR(1) grammar for online calculator. Here is the generated parser
  7. LALR(1) but not SLR(1) grammar from the Dragon book
  8. LR(1) but not LALR(1) grammar from the Dragon book
  9. Hacked parser to recognize non-context free language using semantic checks. Read the comments.
  10. Java 1.4 grammar (converted from .cup version). This is the torture test of your parser generator.

Sample hand-coded x86 assembly language programs in gnu syntax:
fibonacci sequence, summing an array
Simple expression trees and code generation. (CORRECTED)

The Truth Lab. (progressive assignment - reload for latest).
Some guidelines, code fragments, are found here.
Parser Generator Stage 1. The content of this assignment will be the subject of your next progress grade. I've added my version of the function to compute the Nuillible set. Reload for latest
Parser Generator Stage 2: Generating the State Machine.
Parser Generator Stage 3: Generating the Parser.
Parser Generator Final.

Visitor Pattern Warmup Assignment (Optional).

MiniJava+ compiler project overview
Lexer and Parser (RELOAD BOTH FILES). Due Tuesday 4/1
Abstract Syntax and Visitor Pattern (now with Translator). Due Thursday 4/10
Symbol Table and Type Checker. Due Thursday 4/17
Additional guidelines for type checking
x86 assembly language assignment
Generating code for intermediate machine, which can then use my 32 bit coder (RELOAD FOR LATEST) to generate a real .s file.

Here's a simple minijava+ program with only main. The following are several versions of compiled assemblies in that uses increasing levels of optimization:

  1. Stack based, no need to worry about register allocation.
  2. Register based, first version. Uses a Sethi-Ullman-like register allocation scheme.
  3. Better use of registers, along with some local optimization.
You should try to compile this program first, but don't try to optimize all at once.

Compiler Final Preparation UPDATED
Example involving objects, methods and arrays: test2.mj and its generated code (non-optimized).
Another example, this time a function returns an array: test3.mj, with generated code, this time more optimized.

More Minijava+ programs to test your compiler on: test.mj, fact.mj, Quicksort.mj, BinaryTree.mj


fact3b.mj program for 5/8 workshop

The scheduled time of the final session is Thursday 5/15 at 6:15pm.

Next progress grade (last one before final) will be given on Tuesday 5/6. You must be able to compile fact3.mj.

Minijava+ program to test type checking

Program to test your assembler: power2.c. Follow instructions in comments.

test cases for parser generator: nonllk.grammar, nonllk.flex
Check List

Nasty grammars for testing stage 2: nasty1, nasty2, nasty3

Read Chapter 2,3,4,5 of textbook.