San Jose State University : Site Name

Navigation

Main Content

Working in Mars Mission Control, JPL

Ronald Mak

Department of Computer Science
Fall Semester 2011

Office hours: M: 5:30-6:00 PM and 8:45-9:30 PM
W: 8:45-10:00 PM
Office location: MacQuarrie Hall, room 413
E-mail: ron.mak@sjsu.edu
Website: www.apropos-logic.com
Mission Control, Jet Propulsion Laboratory (JPL)
NASA Mars Exploration Rover Mission

[HOME]

CS 153/SE 153: Concepts of Compiler Design


MW 7:30-8:45 pm MacQuarrie Hall 225 [3 units]

Assignments


# Date Due Assignment
1 Aug 24 Sept 2 Write a Pascal program
Input file: employees.txt
Suggested solution
2 Sept 7 Sept 20 Enhanced Pascal scanner and parser
Input file: input.txt
3 Sept 19 Sept 30 Execute Pascal set expressions and assignments
Input files: sets.txt    seterrors.txt
4 Sept 28 Oct 11 Parse Pascal set type definitions and set variable declarations
Input files: input.txt    errors.txt
5 Oct 19 Oct 28 Generate a Java scanner with JavaCC
Input file: input.txt
6 Oct 24 Nov 2 Generate a parser with JavaCC
7 Oct 31 Nov 11 Generate parse trees with JJTree

Lectures


Date Content
Aug 24 Slides: Introduction; conceptual design; compiler vs. interpreter; Pascal

Sample Pascal programs:
newton.pas   newton.j (Jasmin assembly language object program)
wolfisland.pas   wolfisland.in (Wolf Island input data)
Aug 29 Slides: Framework; initial Pascal components; first test; how to scan
Aug 31 Slides: Pascal tokens; syntax diagrams; Pascal tokenizer; interfaces for the symbol table, symbol table stack, and symbol table entries
Sept 7 Slides: Symbol table implementation; cross-reference listing; parse tree concepts; version control system
Sept 12 Slides: Parse tree implementation; parsing expressions; printing parse trees
Sept 14 Slides: Temporary hacks; executing compound statements, assignment statements, and expressions; parsing REPEAT and WHILE statements; synchronization and error recovery
Sept 19 Slides: Executing REPEAT and WHILE statements; parsing and executing FOR, IF, and CASE statements; top-down recursive descent parsing; syntax and semantics
Sept 21 Slides: Multipass compilers; parsing declarations; syntax diagrams for Pascal declarations; type specification; scope and the symbol table stack; how identifiers are defined; predefined identifiers and types

An article about the FORTRAN compiler for the IBM 1401 computer system. The compiler made 63 passes and ran in 8K of memory, and each pass had at most 300 instructions! Assembly language source code of the compiler. Just read the comments.
Sept 26 Slides: BlockParser; DeclarationsParser; ConstantDefinitionsParser; type definition structures; TypeDefinitionsParser; SimpleTypeParser; SubrangeTypeParser; EnumerationTypeParser; RecordTypeParser; Pascal multidimensional arrays; ArrayTypeParser
Sept 28 Slides: Variable declarations; type checking; variables with subscripts and fields; program header; procedure and function declarations; nested scopes and the symbol table stack
Oct 3 Slides: Parsing programs, procedures, and functions; parsing calls to procedures and functions; formal and actual parameters; parsing calls to the standard routines; compile time vs. run time; runtime memory management; runtime stack; runtime activation records; runtime display
Oct 5 Slides: Allocating and initializing activation records; passing parameters during a call; memory management classes; executing procedure and function calls; runtime error checking; executing entire Pascal programs; interactive source-level debugger
Oct 10 Slides: Review for midterm; Pascal IDE
Oct 17 Slides: Midterm solution; DFA acanner; BNF
SimpleDFAScanner.java    SimpleDFAInput.txt
Oct 19 Slides: Grammars and languages; derivations and productions; Extended BNF (EBNF); compiler-compilers; JavaCC; JavaCC regular expressions; "hello world" examples of .jj files; JavaCC Eclipse plug-in; your compiler project
Sample .jj files: helloworld1.jj helloworld2.jj helloworld3.jj helloworld4.jj helloworld5.jj
Oct 24 Slides: JavaCC parser specification; choice conflicts; left factoring; backtracking and lookahead; left recursion; right recursion; iteration; JJDoc; Assignment #6
Sample .jj files: phone.jj phone_method_param.jj phone_choice.jj phone_left_factored.jj phone_lookahead.jj expression_left_recursion.jj expression_iteration.jj expression_right_recursion.jj
Oct 26 Slides: JJTree; visitor design pattern; Pcl
Sample .jj and .jjt files: calculator_simple.jj calculator_tree.jjt calculator_tree_image.jjt SimpleNode.java calculator_calculating.jjt calculator_visitor.jjt node_name_change.jjt node_void.jjt
Pcl: Pcl.zip
Oct 31 Slides: Syntax error handling with JavaCC; JVM architecture; JVM instructions; Jasmin assembler; local variables
Sample .jj .jjt and .j files: logo_tokenizer.jj logo_skip_chars.jj logo_synchronize.jj logo_tree_recover.jjt hello.j
Nov 2 Slides: Using Java with Jasmin code; code templates; compilation strategy; Jasmin type descriptors; code for a Pascal program, program fields, main program, loading and storing variables, procedures and functions, local variables, expressions; Pcl2 code generator
Pcl2: Pcl2.zip
Nov 7 Slides: Kimera disassembler; Jasmin instructions for comparisons; code templates for relational expressions, assignment statements, if statements, looping statements, and select statements; Jasmin code for procedures and functions
Nov 9 Slides: Code for System.out.println(), String.format(), and scalar arrays and subscripted variables
Nov 14 Slides: Code for non-scalar arrays; code for records and fields
Nov 16 Slides: JavaCC error handling with synchronization; Pascal runtime library; passing parameters by value and by reference; compiling Wolf Island and Hilbert
Pcl with error handling: PclError.zip
Performance tester: hilbert2.pas
Nov 21 Slides: Code generation; instruction selection; register allocation; code optimization; debugging and optimizing compilers; compiling object-oriented languages
Nov 28 Slides: Instruction scheduling; context-free and context-sensitive grammars; shift-reduce bottom-up parser; yacc and lex (bison and flex); LL and LR parsers
Simple calculator: calc.y   calc.l
Nov 30 Slides: Runtime memory management; heap management garbage collection algorithms: reference counting, mark and sweep, stop and copy, generational; aggressive heap management; static and dynamic scoping
Dec 7 Slides: Course review

Goals


First goal: You'll learn the concepts of writing compilers and interpreters for high-level programming languages. You'll write your compilers and interpreters in Java.

In the first half of the course, you'll learn about the front end of a compiler or interpreter: the scanner and the parser; and its middle tier: symbol tables and intermediate code (parse trees). You'll also learn how an interpreter executes source programs in its back end. You'll understand and modify the Java code of a working interpreter. The interpreter will execute source programs written in the Pascal programming language.

In the second half of the course, you'll write your own compiler using JavaCC, the Java compiler-compiler. Your compiler will translate programs written in the high-level language of your choice — or perhaps in a language that you invent — first to Jasmin assembly language and then to .class files that will execute directly on the Java Virtual Machine (JVM).

Compilers and interpreters are complex programs, and writing them successfully is hard work. To tackle the complexity, we'll take a strong software engineering approach in this course. We'll use design patterns, Unified Modeling Language (UML) diagrams, XML, and other modern object-oriented design practices to make the code understandable and manageable.

Second goal: You'll learn critical job skills that employers look for in new college hires:

Prerequisites


CS 47 Introduction to Computer Organization grade C- or better
CS 146 Data Structures and Algorithms grade C- or better
CS 154 Formal Languages and Computability grade C- or better
  Department policy is to enforce  
  all course prerequisites strictly,  
  especially for a deep course.  

Required books


Writing Compilers and Interpreters, 3rd edition
Ronald Mak
Wiley Publishing, Inc., 2009
ISBN: 978-0-470-17707-5
Source files from each chapter
Generating Parsers with JavaCC, 2nd edition
Tom Copeland
Centennial Books, 2009
http://generatingparserswithjavacc.com/
ISBN: 0-9762214-3-8

Recommended books


Programming for the Java Virtual Machine
Joshua Engel
Addison-Wesley Professional
ISBN: 0201309726
The Essentials of Pascal I
Gary W. Wester
Research and Education Association
ISBN: 0-87891-694-6
The Essentials of Pascal II
Gary W. Wester
Research and Education Association
ISBN: 0-87891-718-7

Online Pascal tutorials


Learn Pascal Programming Tutorial looks very good. You can ignore Lesson 2 since we won't be doing GUI programming in Pascal.
Learn Pascal also looks good, although it doesn't appear to cover set types.
Here's a decent tutorial on Pascal sets.

Who am I?


As a Research Staff Member at the IBM Almaden Research Center in San Jose, I'm helping to solve the nation's obesity problem. Previously, I was a Senior Scientist at the NASA Ames Research Center, where I designed and led the development of the middleware for a key information management system for NASA's Mars Exploration Rover (MER) mission. I was also the Enterprise Software Strategist at the Lawrence Livermore National Laboratory for a major laser-based fusion energy project, the National Ignition Facility (NIF), where I helped design and develop a scientific workflow system to manage the data generated by the laser firings.

I have degrees in the mathematical sciences and in computer science from Stanford University. I've written books on compiler writing, software engineering, and numerical computation. I find designing and developing software such as compilers and enterprise systems to be fun and challenging. So I'm the kind of geek nobody wants to talk to at parties. My one redeeming feature is that I have two cute cats. No, they're not named Yacc and Lex.