Week | Date | Content |
---|---|---|
1 | Aug 22 |
Slides:
Goals; course learning outcomes; project teams; grading;
postmortem assessment report; overview of the compilation
process; compiler as translator; other forms of translation;
translation demos; Pascal tutorials
Example Pascal program: SquareRootTable.pas Example object code (Jasmin): SquareRootTable.j Example language conversion (Pascal to Java): SquareRootTable.java |
2 | Aug 27 |
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
Example Pascal programs: HelloWorld.pas Newton.pas Hilbert.pas Hilbert10000.pas Simple scanner, parser, and interpreter: Simple.zip |
Aug 29 | 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; printing parse trees | |
3 | Sep 3 |
Slides:
Building the parse tree with parser methods; handling
syntax errors; the symbol table and its entries; a hack;
a simple interpreter; what is "run time"; using the
parse tree and symbol table at run time; another hack;
parse tree visit methods
Sample erroneous code: HelloErrors-1.txt HelloErrors-2.txt |
Sep 5 | Slides: Simple interpreter; visiting parse nodes during run time; REPEAT statement; LOOP subtree; evaluating expressions; Assignment #3; WHILE statement; IF statement and the dangling ELSE; FOR statement; CASE statement | |
4 | Sep 10 |
Slides:
Assignment #3; 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.java SimpleDFAInput.txt |
Sep 12 |
Slides:
Language hierarchy; regular expressions and tokens;
BNF; grammars and languages; derivations and productions;
ANTLR's BNF; compiler-compilers; ANTLR 4; ANTLR lexer;
ANTLR grammar file; Java main programs; on the command
line; Eclipse ANTLR plug-in
ANTLR example: Expr.g4 ExprMain.java input.txt error.txt |
|
5 | Sep 17 |
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
ANTLR example: ExprLabeled.zip |
Sep 19 | 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 24 |
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: Pcl5.zip |
Sep 26 |
Slides:
Syntax and semantics; multipass compilers; software
engineering; type declaration structures;
multidimensional array; cross-reference listing;
predefined scalar types; type checking; assignment and
comparison compatible; type checking expressions;
class TypeChecker; visit methods for type definitions;
new fields for parse tree nodes; Pcl6
ANTLR example: Pcl6.zip |
|
7 | Oct 1 | Slides: Type checking; pass 3 uses node info from pass 2; 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.g4; Pascal interpreter |
Oct 3 |
Slides:
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;
source-level debugger; debugger command language;
review for the midterm
Midterm review questions |
|
8 | Oct 8 | Midterm |
Oct 10 | slides Interpreter, converter, compiler; converting Pascal to Java; target machines for compilation; Java Virtual Machine (JVM) architecture; JVM runtime stack and stack frame; Jasmin assembler; Jasmin assembly instructions; shortcut instructions | |
9 | Oct 15 |
Slides:
Example conversion of Pascal to Java;
local variables, load and store, arithmetic, other
instructions; code templates; compilation strategy;
Jasmin datatype descriptors;
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
Midterm solutions |
Oct 17 | Slides: Jasmin code for assignment statements; load and store tips; What Would James Gosling Do?; Jasper; relational expressions; code templates for IF statements and looping statements; code for Newton's square root function; code for FOR and CASE statements; code for procedures and functions and calls; code for the main program | |
10 | Oct 22 | Slides: Calling methods on objects; invokestatic vs. invokevirtual; code for println() and printf(); final compiler project details |
Oct 24 | Slides: Resource acquisition is initialization (RAII); 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 | |
11 | Oct 29 | Slides: backend compiler architecture; compiler projects |
Oct 31 | 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 | |
12 | Nov 5 |
Slides:
Passing parameters: Java and C++;
Java hack; runtime libraries; library example; code
generation for WHILE, IF, FOR, CASE, and procedure call;
static and dynamic scoping
Pass-by-reference examples: ScalarRef.pas ScalarRef.cpp ObjectRef.cpp Thing.java ObjectRef.java IWrap.java ReferenceHack1.java ReferenceHack2.java Runtime library example: Multiplier.java LibraryTest.java LibraryTest.j |
Nov 7 | Slides: runtime memory management; heap management; garbage collection algorithms: reference counting, mark and sweep, stop and copy, generational; aggressive heap management; change Java's heap size; garbage collection research | |
13 | Nov 12 | Slides: On writing compilers; compilation challenges; speed comparisons; stack machine vs. register machine; CISC vs. RISC; a GUI-based debugger; integrated development environment (IDE); interprocess communication |
Nov 14 |
Slides:
Regular grammar for tokens; encoding a DFA transition matrix;
context-free and context-sensitive grammars; top-down and
bottom-up parsers; shift-reduce parsing; yacc and lex
Simple switch DFA scanner: SimpleSwitchDFAScanner.java Example yacc/lex grammar: calc.l calc.y |
|
14 | Nov 19 | Slides: Syntax-directed translation; attribute grammars; LL(1) and LR(0) parsers; FIRST and FOLLOW sets; three-address code; data-flow analysis |
Nov 21 | Slides: Next few weeks; team compiler project surveys; recap; GUI-based debugger; compiler case study |
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.
Department policy is to enforce
all course prerequisites strictly
CS 47 Introduction to Computer Systems or CMPE 102 Assembly Language Programming |
grade C- or better |
CS 146 Data Structures and Algorithms | grade C- or better |
CS 154 Formal Languages and Computability | grade C- or better |
The Definitive ANTLR 4 Reference, 2nd edition Terence Parr Pragmatic Bookshelf, 2012 ISBN: 978-1934356999 http://www.antlr.org/ |
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. |
http://rextester.com/l/pascal_online_compiler |
https://www.tutorialspoint.com/compile_pascal_online.php |
https://www.jdoodle.com/execute-pascal-online |
Install the ANTLR 4 plug-in for Eclipse, etc. |
The Java Virtual Machine Instruction Set |