Last update: May 6, 2021
- PA4 deadline is extended by two days to Fri Apr 23, 11:59 PM
- We will use Piazza for offline discussions. You should have received an invitation via
email to join our Piazza site: https://piazza.com/unc/spring2021/comp520/home
- Written assignments should be submitted using gradescope.
- (for Thu Jan 21) PLPJ Skim Chapter 1 - Introduction (pp 1 - 25).
- (for Tue Jan 26)
PLPJ Skim PLPJ Chapter 3 (pp 55 – 70). Study PLPJ Chapter 4 Secns 4.1, 4.2 (pp 73 – 83).
- (for Thu Jan 28, Tue Feb 2)
- Parsing, Secn 4.3 (pp 83 - 84)
- Top-down parsing, Secn 4.3.2, (pp 87 - 89)
- Recursive descent parsing, Secn 4.3.3 (pp 89 - 93)
- Systematic development of recursive-descent parsers, Secn 4.3.4 (pp 93 - 109)
- (for Thu Feb 4) PLPJ Scanner construction, Secn 4.5 (pp 118 - 124)
- (for Tue Feb 9) PLPJ Abstract Syntax Trees, Secn 4.4 (pp 109 - 118)
- (for Thu Feb 18) PLPJ AST construction in Triangle (pp 124 - 128)
- (for Thu Mar 4) PLPJ Contextual Analysis - Identification (pp 136 - 149)
- (for Tue Mar 9) PLPJ Contextual Analysis - secn 5.2 Type checking (pp 151-153)
- (for Tue Mar 16) midterm exam
- (for Thu Mar 18) PLPJ Contextual Analysis implementation using the visitor pattern (pp 154 - 163)
- (for Tue Mar 30) PLPJ Runtime organization
(skim pp 173-229, read secn 7.6 pp 230 - 236 secn 6.7 on OO language runtime organization)
- (for Tue/Thu Apr 6,8)
PLPJ Code Generation Chap 7 - skim through the chapter for aspects of Triangle/TAM that apply to miniJava/mJAM
Here are small examples implementing scanning, parsing, and AST construction for simple arithmetic expressions
that correspond roughly to checkpoints PA1 and PA2 in our miniJava project. A third example demonstrates the
generation and execution of mJAM code, corresponding to PA4 in the project.
- Download the zip file
- in Eclipse: File / Import Existing Projects into Workspace / Next
- choose "Select Archive File" radio button, browse to zip file and Open / Finish
- Scanner and Parser: download
- Illustrates the package structure and classes for a scanner and parser (mostly following the text), and implements
a scanner and parser that recognize (valid/invalid) simple arithmetic expressions using numbers, operators (+,-), and
- The top-level package is miniArith. It contains the Recognizer mainclass that parses input entered
from the keyboard and judges whether it consitutes a valid arithmetic expression.
The parse procedures corresponding to nonterminals in the grammar are traced to illustrate
how the input was parsed.
- The subpackage miniArith.SyntacticAnalyzer contains the Scanner, Parser, Token classes and the TokenKind enumeration.
- AST construction: download
- Illustrates construction of an AST using the node definitions in the miniArith.AbstractSyntaxTrees subpackage.
The first traversal displays the input arithmetic expression in fully parenthesized form, reflecting precedence and
associativity rules. The second traversal evaluates the expression and displays the result. The two traversals are implemented
using a single implementation of the Visitor design pattern.
- Code Generation and Execution using mJAM :
- This example generates a sequence of mJAM instructions as might be emitted by your code generator when applied to the
example miniJava Counter class:
- It generates a preamble in the code store starting at location 0 that calls public static main(String  args)
in class Counter with an empty array of String.
- It generates the code for the Counter class. The main method constructs an instance of the Counter class
called counter, applies the increase method to counter class with argument value 3,
and prints the value of Counter.count.
- The generated code is executed using the miniJava abstract machine mJAM in debug mode, starting with the call to main,
so you can single step through the execution and examine the mJAM state throughout execution.
This upper-level undergraduate class (also available for graduate credit) extends and
integrates material from prerequisite courses to build a compiler for a non-trivial subset of the Java
programming language. Java is also the implementation language for the compiler.
Upon completion of this course, you should:
- Understand the theory and practice of compilers, linkers, debuggers, and program execution by
hardware or abstract machines.
- Appreciate the effect of trade-offs in programming language design and computer architecture
on program compilation and the run-time support system.
- Have gained additional experience with the design and implementation of a large and complex
program using Java.
- Be prepared for advanced study in programming languages and optimizing compilers.
Administrative details, such as prerequisites, exam dates, honor code,
and the sequence of topics covered in the course can be found in the
Programming Language Processors in Java: Compilers and Interpreters,
by David Watt and Deryck Brown, Prentice Hall, 2000 (ISBN 0-130-25786-9).
Watt & Brown, Programming Language Processors in Java
This page is maintained by
Send mail if you find problems.