Nathan's University

Learn by doing! Work on exciting programming projects and create something awesome.

Create Your Own Game

Do you have a burning desire to create video games? Take a look at my latest class (deadline for enrollment is soon!!!)

Create Your Own Game

PL101: Create Your Own Programming Language

The PL101: Create Your Own Programming Language class began on April 4, 2012.

Lesson 0: JavaScript Review - We started with a collection of links to resources related to JavaScript to review and get up to speed. There was also a JavaScript challenge problem to test your skills.

Lesson 1: Whirlwind Tour of Languages - We went on a whirlwind tour of four exciting programming languages, in videos. We covered Scheme, Go, OCaml, and Prolog. I tried to pick something interesting about each one to demonstrate the diversity of programming languages.

Lesson 2: Your First Compiler - We worked through a series of interactive lessons that guide you through building a working compiler for a simple music language. Next, you got started with your class project. We went through setting up GitHub, running JavaScript from the command line, and checking in code. You also extended your compiler to handle more features.

Lesson 3: Parsing - In this lesson we explored parsing and creating grammars for programming languages. You learned how to use PEG.js step-by-step to create a parser. We covered parser actions, repetition and choice, and Scheme syntax. You created a parser for a simplified "Scheem" language. We went over context free grammars, ambiguity, arithmetic and operator precedence, and unit testing. You added features to the Scheem parser and created a parser for your MUS language.

Lesson 4: Scheem Interpreter - In this lesson we worked through lots of features of Scheem. We covered arithmetic, variables, and begin blocks. We worked through quote, then wrote some functions like "cons" and "cdr" to deal with list values, and finished off by implementing the "if" statement. Your homework was to put all the pieces together into a working interpreter and link it with your Scheem parser, with working unit tests. Then you put up a working demo webpage showing off your working Scheem parser and interpreter. This is what the class is all about!

Lesson 5: Functions and all that - You learned how to implement functions in Scheem. You learned about local variable bindings, how function values in Scheem can be implemented using JavaScript function values, interpreting function application forms, the semantics of lambdas, and how to get recursion working in your interpreter. In the homework you added functions to your implementation of Scheem and got them working nicely with all the existing features you've implemented, then added alert and some example programs to show off your implementation.

Lesson 6: Inventing a language for turtle graphics - In this lesson you worked through creating a new language to do turtle graphics. We brought together all the lessons we've learned about parsing, expression evaluation, and functions to make Tortoise. Tortoise is an imperative language that has syntax similar to JavaScript. You learned how to parse and interpret expressions and statements including new imperative forms. We also covered a new type of function definition. Finally we connected our language to a graphics library to make pretty pictures.

Lesson 7: Continuations, first blood - Continuations are a mind-expanding technique that let you implement some advanced features like infinite recursion, exceptions, and coroutines. In Lesson 7 you started playing with continuations. You saw some examples of continuation-passing style and rewrote your old friend factorial into continuation-passing style. You learned how to put some thunks in your code for delaying evaluation. Then you learned how trampolining works and how it can let you transcend the limitations of JavaScript recursion. Bounce!

Lesson 8: Take Control of Continuations - You wrestled continuations to the floor and beat them into submission this lesson. You learned how to make a simple interpreter that is written in continuation-passing style. You extended your interpreter with a step function that can single step the evaluation of expressions. Then you took it to the next level and interpreted multiple expressions at once in a shared environment. Thread fighting is fun! Finally you doubled down on continuations and implemented exception handling in the little language.

Lesson 9: Am I Your Type? - In this episode you'll learn about static typing and how type checking works. You'll learn what currying is all about and practice dealing with higher-order types. You'll work through how to build a simple type checker for TScheem, a typed version of Scheem. If you want types in your language you need to work through this lesson. Types are fun!

Lesson 10: A Need for Speed - Get your engines revved by compiling instead of interpreting. In this final lesson you'll learn how to write a compiler that translates Tortoise into JavaScript. You'll learn about eval, compiling expressions, function calls, and statements. You'll write functions to compile statement bodies, define new functions, do conditions, and repeats. All the cool kids are compiling to JavaScript.