San Jose State University : Site Name

Navigation

Main Content

Working in Mars Mission Control, JPL

Ronald Mak

Department of Computer Engineering
Department of Computer Science
Department of Applied Data Science
Fall Semester 2020

Office hours: TuTh: 4:30-5:30 PM online via Zoom
Office location: ENG 250 (but working from home)
E-mail: ron.mak@sjsu.edu

CMPE 152: Compiler Design


Section 1: TuTh 3:00 - 4:15 PM online via Zoom


Lab Assignments

# Date Due Assignment
1 Aug 20 Aug 27 Write Simple Pascal Programs

Assignment input file: presidents.txt
Solutions: GoSpartans.pas   ListMerge.pas   Presidents.pas

Sample Pascal program: EmployeeListing.pas
Sample program input file: employees.txt
Sample program output: employees.out.txt
2 Aug 27 Sep 3 Pascal Scanner

Simple Pascal (C++ version): SimpleCpp.zip
Test input files: Newton.txt    ScannerTest.txt
Sample output: ScannerTest.out.txt
Sample solution: Asgn02Cpp.zip
3 Sep 3 Sep 17 Simple Pascal interpreter

Test input files and expected output: TestWhile.txt    TestWhile.out.txt    TestIf.txt    TestIf.out.txt    TestFor.txt    TestFor.out.txt    TestCase.txt    TestCase.out.txt
Sample solution: Asgn03Cpp.zip
4 Sep 17 Sep 28 Pcl interpreter using ANTLR

Executor skeleton: Asgn04Cpp.zip
Sample solution: Pcl4Cpp.zip
5 Oct 8 Oct 19 Pascal to C++ Converter

Partial converter code: Asgn05Cpp.zip
6 Oct 22 Nov 9 Pascal Compiler

Partial compiler code: Asgn06Cpp.zip

Lectures

Week Date Content
1 Aug 20 Zoom recording Password: +k93RSrV
Slides: Goals; course learning outcomes; project teams; grading; postmortem assessment report; overview of the compilation process; compiler as translator; other forms of translation; Pascal tutorials
2 Aug 25 Zoom recording Password: .7I0K*b8
Slides: It's all about translation; conceptual design; major parts of compilers, converters, and interpreters; compilers vs. interpreters; three Java packages; syntax diagrams; how to scan for tokens; basic scanning algorithm; test the scanner; current character vs. next character; consume characters and tokens; Object.h

Sample code: SimpleCpp.zip
Aug 27 Zoom recording Password: %2fuxA?4
Slides: Assignment #2; Pascal statement syntax diagrams; expressions; operator precedence; control statements; REPEAT statement syntax; parse tree design and operations; building a parse tree; test the parser; parse tree nodes; symbol table concepts and operations; who needs a symbol table?
3 Sep 1 Zoom recording Password: y59k7V+R
Slides: Building the parse tree with parser member functions; the symbol table and its entries; a hack; a simple interpreter
Sep 3 Zoom recording Password: n&2?f^GS
Slides: Simple interpreter; "run time"; using the parse tree and symbol table at run time; another hack; visiting parse nodes during run time; REPEAT statement; Assignment #3; WHILE statement; IF statement and the dangling ELSE; FOR statement; CASE statement
4 Sep 8 Zoom recording Password: 83p!hpQ1
Slides: Assignment #3; the dangling ELSE; maximum munch; an executor improvement; syntax and semantics; options for error recovery; top-down recursive descent parsing; accomplishments so far; temporary hacks; a DFA scanner

DFA scanner: SimpleDFAScanner.h    SimpleDFAScanner.cpp    SimpleDFAInput.txt
Sep 10 Zoom recording Password: LV#?8kPA
Slides: BNF; grammars and languages; derivations and productions; EBNF; compiler-compilers; ANTLR 4; ANTLR lexer; ANTLR grammar file; Java main programs; on the command line

ANTLR example: Expr.g4    ExprMain.cpp    input.txt
5 Sep 15 Zoom recording Password: A3eJjWY$
Slides: What does ANTLR do for us?; ANTLR workflow; ANTLR parse trees; syntax error handling; resolving ambiguities; visitor interface; interface ExprVisitor; base visitor class ExprBaseVisitor; labeled production rules; interface ExprLabeledVisitor; base class ExprLabeledBaseVisitor; class Executor; main

ANTLR example: ExprLabeledCpp.zip
Sep 17 Zoom recording Password: ?7CdFVMS
Slides: Pcl4 grammar; package structure; Pcl4 visitor interface; Pcl4 base visitor class; class Executor; Assignment #4; declarations; constant definitions; simple type definitions; array type definitions; record type definitions; variable declarations; declarations and the symbol table; scope and the symbol table stack
6 Sep 22 Zoom recording Password: 9@H#73T!
Slides: Scope and the symbol table stack; nested scopes; scope of record fields; class Symtab; class SymtabStack; class SymtabEntry; Pascal declarations; grammar file Pcl5.g4; declarations and the symbol table; type specification attributes; class Typespec

ANTLR example: Pcl5Cpp.zip
Sep 24 Zoom recording Password: h7ZY+weu
Slides: Multipass compilers; type declaration structures; multidimensional array; predefined scalar types; type checking; Pass 2 visit functions; new fields for parse tree nodes; grammar Pcl4.g4
7 Sep 29 Zoom recording Password: g@FcASJ9
Slides: Pcl6 main; pass2 functions for type definitions; type checking; assignment and comparison compatible; new fields for parse tree nodes; class TypeChecker; type checking expressions; cross-reference listing

ANTLR example: Pcl6Cpp.zip
Oct 1 Zoom recording Password: 3t0!ib6?
Slides: Pascal.g4; pass 3 execution; runtime memory management; symbol table stack vs. runtime stack; stack frame; access to nonlocal variables; runtime display; recursive calls; allocate a stack frame; runtime error checking; Pascal interpreter; midterm review
8 Oct 8 Zoom recording Password: GV@7#5KB
Slides: Interpreter features; grammar for a variable; type check a variable; grammar for a procedure or function definition; symbol table entry for a procedure or function; grammar for procedure and function calls; type check a call; backend converter to a different language; convert Pascal's REPEAT statement; Assignment #5
9 Oct 13 Zoom recording Password: W3g.^LEA
Slides: Interpreter, converter, compiler; target machines; Java Virtual Machine (JVM) architecture; JVM runtime stack and stack frame; Jasmin assembler; Jasmin assembly instructions: shortcuts, local variables, load and store, arithmetic, other instructions; code templates; compilation strategy; Jasmin datatype descriptors
Oct 15 Zoom recording Password: VZ++Jrl7
Slides: Program fields; code template for the main method; loading and storing a program variable's value; code for procedures and functions; compiling local variables; generating code for expressions; comparing integer values and other datatypes; What Would James Gosling Do?; Jasper; relational expressions; load and store tips
10 Oct 20 Zoom recording Password: U$VkfC8j
Slides: Code templates: assignment statements, if statements, looping statements; Newton's square root function; FOR statement; select template; CASE statement; procedures and functions; code: main program, function, call a function
Oct 22 Comcast internet down -- no class.
11 Oct 27 Zoom recording Password: 1R#2*A79
Slides: Calling methods on objects; invokestatic vs. invokevirtual; code for println() and printf(); translation recap; Assignment #6; final compiler project
Oct 29 Zoom recording Password: Mf=A0X#O
Slides: Pascal arrays; code generation for arrays and subscripts; allocate memory for scalar arrays; access an element of a 2-D array; subscripted variables; allocate memory for non-scalar arrays; 1-D array of strings; 2-D array of strings; code for records and fields; passing parameters; runtime libraries
12 Nov 3 Zoom recording Password: 5*og.$KY
Slides: Passing parameters: Java and C++; pass by reference: C++, Java hack; runtime libraries; library example; project presentations schedule; example project

Pass-by-reference examples: ReferenceParm.java   ReferenceParm1.cpp   ReferenceParm2.cpp   IWrap.java   ReferenceHack1.java   ReferenceHack2.java
Runtime library example: Multiplier.java   LibraryTest.java   LibraryTest.j
Nov 5 Zoom recording Password: 4wS?WCUY
Slides: Code generation; instruction selection; register allocation; data flow analysis; instruction scheduling; code optimization: safety, profitability, constant folding, constant propagation, strength reduction, dead code elimination, loop unrolling, common subexpression elimination; debugging and optimizing compilers; compiling object-oriented languages
13 Nov 10 Zoom recording Password: 8nh!6tT4
Slides: backend compiler architecture
Nov 12 Zoom recording Password: &ai9UVyU
Slides: Static and dynamic scoping; runtime memory management; Java command-line arguments; heap management; garbage collection algorithms: reference counting, mark and sweep, stop and copy, generational; aggressive heap management; garbage collection research
14 Nov 17 Zoom recording Password: U%r7^$&i
Slides: Interactive source-level debugger; machine-level vs. source-level debugging; simple debugger command-line language; breakpoints; watchpoints; parsing and executing the debugger commands; a GUI-based debugger; integrated development environment (IDE); interprocess communication

Pascal command-line debugger: PascalDebuggerCpp.zip
Nov 19 Zoom recording Password: 7K4xqZ++
Slides: Context-free and context-sensitive grammars; top-down and bottom-up parsers; shift-reduce parsing; yacc and lex

Example grammar: calc.l   calc.y

Goals of the course

This course will concentrate on practical aspects of compiler construction, programming language design, and engineering a large, complex software application.

This is a challenging course that will demand much of your time and effort throughout the semester.

Course Learning Outcomes (CLO)

Prerequisites

Department policy is to enforce
all course prerequisites strictly.

CMPE 102 Assembly language programming grade C- or better
CMPE 126 Algorithms and data structure design grade C- or better

Required book

The Definitive ANTLR 4 Reference, 2nd edition
Terence Parr
Pragmatic Bookshelf, 2012
ISBN: 978-1934356999
http://www.antlr.org/

Recommended book

Writing Compilers and Interpreters, 3rd edition
Ronald Mak
Wiley Publishing, Inc., 2009
ISBN: 978-0-470-17707-5
Source files

Online Pascal tutorials

Pascal Tutorial  looks very good. It has an online Pascal compiler.
Learn Pascal  also looks good, although it doesn't appear to cover set types.

Online Pascal development sites

You can edit, compile, and run Pascal programs online.
http://rextester.com/l/pascal_online_compiler
https://www.tutorialspoint.com/compile_pascal_online.php
https://www.jdoodle.com/execute-pascal-online