CS164: Hack Your Language!
Ras Bodik with
Mangpo Phitchaya Phothilimthana and
Ali Sinan Koksal
Spring 2013, 306 Soda Hall, TT 9:30-11
Below are lectures from the latest instance of the course on programming languages and their implementations. Learn more about the course or visit the main page for the latest instance of the course.
Links: cs164 sp13 Piazza
Lectures
1 Why hack your language?
What is a programming language and why you will write a few in your life. Plus an overview of how you will learn language design in cs164.
Topics: A broad view of what is a language. The cs164 project.
Slides: pptx pdf Date: January 22, 2013
Homework: HW1: A data visualization DSL and Meta-programming
2 Spark: processing big data with small programs
Guest lecture by Matei Zaharia. Spark is a DSL embedded in Scala designed for parallel data procesing. The lecture illustrates benefits of DSLs (small programs can express complex computations) and shows how to use call chaining and operator overloading to implement a DSL by embedding it in a moderm language like Scala.
Topics: DSLs, techniques for embedding a DSL.
x Introduction to interpeters with a unit conversion calculator
Using a unit-conversion calculator inspired by the google search bar calculator, this supplementary lecture gradually grows a calculator language, starting with simple expressions and ending with a clever capability to define custom units. Go over these slides and play with the supplied code if you need a refresher on recursive interpreters.
Topics: Introduction to expressions, values, and types, their representation and the architecture of interpreters.
Slides: pptx pdf Date: January 24, 2013
Homework: HW2: Desugaring (optional but recommended before desugaring in PA1)
3 Creating language constructs with desugaring and lexical scoping
We first overview the architecture of an interpreter and show that a compiler is just a somewhat non-standard interpreter. Next we compare dynamic and lexical scoping, pointing out the limitations of the former. We show that lexical scoping is our first language construct that enables defining new language constructs, namely iterators such as jQuery.each(f), which accepts a function f. We also show how desugaring and lexical scoping allows defining while and if on top of a language with just functions.
Topics: Architecture of an interpreter and compiler. Dynamic and lexical scoping. Environments. Desugaring.
Slides: pptx pdf Date: January 29, 2013
Project: PA 1: Writing an Interpreter
4 Building advanced control abstractions with coroutines
More advanced control constructs, such as lazy iterators, require coroutines, which allow suspending a computation and resumining it later. We introduce Lua-style coroutines and show how to turn a recursive array permutation algorithm into a lazy iterator, and how to elegantly merge two search trees with lazy tree iterators.
Topics: Environments and name binding. Syntactic desugaring of IF and WHILE by delaying evaluation with lambdas.
Slides: pptx pdf Date: January 31, 2013
Reading: Coroutines in Lua, Chapter 9 (required reading), More uses of coroutines (Sec 3), Revisiting Coroutines
Homework: HW3: Use coroutines to build new abstractions (optional but recommended before PA2)
5 Implementing coroutines with a bytecode interpreter.
As a refresher to corutines, we show that coroutines allow a beautiful implementation of regex matching because they are good at expressing backtracking. We go over language design issues in coroutines and compare Lua's asymmetric coroutines with symmetric ones. After explaining why the recursive interpreter cannot easily support coroutines, we introduce an AST-to-bytecode compiler that flattens the AST and we show how the resulting flat bytecode is interpreted, and how resume and yield can now be easily supported.
Topics: Implementing backtracking regexes using coroutines. Coroutine language design issues. AST-to-Bytecode compiler. Bytecode interpreter.
Slides: pptx pdf Date: February 05, 2013
Project: PA 2: Implement coroutines with a bytecode interpreter
6 Logic Programming
We give a short introduction to logic programming. We show how recursive "database" queries can be asked with Prolog, and how to work with lists.
Topics: Logic programming. Facts and rules. Unification, lists.
7 Implementing Prolog
While previous lectures extended the host language, with iterators and regexe using closures and coroutines, respectively, we now move to implement a standalone language with a different programming model based on logic programming. We first delve into unification and substitution and then develop interpreters for larger and larger subsets of Prolog, with the goal of introducing one concept at a time. We will end with an interpreter that handles almost the full prolog. The interpeter is based on the Lua coroutines you implemented in PA2.
Topics: Interpreters for subsets of Prolog. Bactracking with coroutines. Resolvent. Most general unfiers. Substitution.
8 Grammar and a Recursive Descent Parser in Prolog
Language is a set of strings and a grammar is a description of this language. Some grammars are left-recursive, which causes problems for recursive descent parsers. String derivation. The parsing problem. Parse trees. From a String Generater via an Oracle Parser to a Prolog Parser. Reconstructing the Parse Tree and building the AST with the Prolog parser.
Topics: Grammars, String Derivation, Parse Trees, From a String Generater via an Oracle Parser to a Prolog Parser.
9 Datalog and bottom-up parsers
Datalog is a subset of Prolog with nice properties such as all programs terminate and polynomial-time evaluation. We will rewrite the Prolog recursive descent parser to Datalog, automatically obtaining the historical CYK parser. We then optimize this parser (with a sort-of magic set transformation) and obtain the Earley parser, which is the foundation for all modern bottom-up parsers.
Topics: Datalog, CYK parser, Earley parser.
10 Grammar Disambiguation and Syntax-Directed Translation
Topics:
11 Regular Expressions as a Small Langauge
Topics:
12 Implementing Small Languages
Topics:
13 Ideas for Final Projects
Topics:
14 Designing your Own Objects in Lua
Topics:
15 continued
Topics:
Date: March 12, 2013
16 Midterm Review
Topics:
17 Static Types for OO Languages
Topics:
18 Subverting the type system by tampering with hardware
Topics:
19 Flow Analysis
Static analysis reads a program and computes its properties, to be used by clients like compiler optimization or security analysis. We define static analysis and describe five applications of the analysis. We then show that flow analysis covers a range of clients. We define points-to analysis by first describing the approximations it makes to the program and then showing its inference rules in Prolog. As optional material, who show how this analysis can be viewed as CYK parsing a program graph representation.
Topics: Static analysis. Program approximation. Flow analysis. Andresen's algorithm via Prolog deduction.
20 Live Programming (Bret Victor)
In this video "guest" lecture, Bret Victor shows the possibilities of programming interfaces, reminding us that current interfaces changed very little since the days of ASCII terminals.
Topics: Live Programming for animation, games, circuits, sorting.
Date: April 09, 2013
Reading: video, Learnable Programming, Up and Down the Ladded of Abstraction
21 Probabilistic Languages (Church)
Optional material
Topics:
Slides: pptx pdf Date: April 11, 2013
Reading: Church tutorial
22 Reactive Programming I (Rx)
Topics:
Slides: pptx pdf Date: April 16, 2013
Reading: Rx Hands-On Lab
23 Reactive Programming II (Arrowlets)
We describe challenges with event-driven programming in JavaScript, including the inability to reuse or parameterize code. Arrowlets is a library-based DSL that lifts events and functions into composable blocks, called arrows. We show how arrows are used and how they are implemented usign continuation-passing style, and why this style is important in implementing arrows in JavaScript event model.
Topics: Lifting functions and events into composable arrows. Continuation-passing style (CPS). Implementation of Arrowlets with CPS.
Slides: pptx pdf Date: April 18, 2013
Reading: Programming with Arrowlets (required), Arrowlets paper (optional)
24 Bootstrapping and Partial Evaluation (Trusting Trust)
Self-reproducing program. Tombstone diagrams for translator interactions, visually and in Datalog. Bootstrapping a compiler. Injecting a selfprpagating exploit into the compiler.
Topics: Tombstone diagrams. Bootstrapping. Injecting a self-propagating exploit into the compiler.
About
- Contact Information
- Download CV
- Projects
- Students
- Papers
- Talks
- Current and Recent Courses
- Courseware
- Organizing
News
Course on program synthesis
9/2/2012Emina Torlak and I have given an invited tutorial at CAV 2012. The tutorial is being expanded this semester into a graduate course, which you can follow as we add lectures and homeworks. CAV tutorial slides: (ppt, pdf, screencast). The graduate course.
Postdoc position position in synthetic biology
8/13/2012We are looking for postdocs in synthetic biology. We need curious, well-rounded computer scientists with expertise in algorithms, hacking, and with interest in biology.
NSF Expedition in Computing for program synthesis
4/3/2012The multi-university ExCAPE project aims to change computer programming from the tedious task to one in which a programmer and an "automated program synthesis tool" collaborate to generate software that meets its specifications.
Looking for a postdoc position?
4/3/2012We are looking for postdocs in program synthesis and computer-aided programming.
2nd Dagstuhl Seminar in Program Synthesis
4/9/2012Several communities related to synthesis of programs and other computational artifacts will meet again in wine cellars of the castle.