Stork: An Example Programming Language in 10 Steps

  • strict warning: Non-static method view::load() should not be called statically in /home/sigpboo7/public_html/modules/views/views.module on line 842.
  • strict warning: Declaration of views_handler_field_comment::init() should be compatible with views_handler_field::init(&$view, $options) in /home/sigpboo7/public_html/modules/views/modules/comment/views_handler_field_comment.inc on line 50.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/sigpboo7/public_html/modules/views/plugins/views_plugin_row.inc on line 135.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/sigpboo7/public_html/modules/views/plugins/views_plugin_row.inc on line 135.

There are several questions every developer gets asked sooner or later:

  • How do you learn to program?
  • Should I learn to program?
  • What is a program?
  • Where do programs come from?
  • What is a programming language?
  • Where do programming languages come from?

Most of these questions already have excellent answers online. But while the question of where programming languages come from is the topic of some excellent books, I’ve never been able to find a simple, straightforward, free answer online.

I’m happy/sad this Michael Scott is not the author of that book.

Stork is a simple, free programming language I’m writing in ten steps and documenting in writing, code, and Reddit threads. I think Stork fills that hole, and I hope that you, gentle reader, think that it does, too.

What Stork is, and what Stork is not

Stork is designed to be a simple, useful, lesson-by-example of how to build a programming language, implemented in Java. It assumes a basic profiency in the Java programming language, but does not assume any familiarity with programming language implementation or any libraries. For simplicity’s sake, it will be implemented as an interpreter wrapped around a two-phase compiler (front end only), and is currently planned to be strongly-typed (as opposed to weakly-typed) and imperative (as opposed to object-oriented or functional). Stork will have control structures (e.g., if, while), functions, variables, arrays, and structs, but I’m not planning to cover classes and how to implement polymorphism and inheritance unless I get a lot of requests for it. Because it’s a personal point of interest, I’ll also cover simple kinds of static analysis, like init analysis in the presence of control structures, but I promise not to totally geek out.

Stork is not a history lesson about programming languages, nor is it a course on how to program. Because Stork is intended as an example language, it will not be highly optimized, or necessarily incorporate modern “best practices” in order to keep things as simple and straightforward as possible. (For example, I’ll be building Stork’s tokenizer and parser by hand using recursive descent rather than using a parser generator.) Also, Stork will not cover topics like how to compile a language down to machine code, but will go into some detail about how that could be done if one wanted to.

Lesson Format

I plan to organize Stork as a “course” organized as a series of ten “lessons,” with a new lesson published every week or two starting this week. Most lessons will probably go out on the weekend, just because that’s when I’ll have the most time to spend on Stork. I’ll be sure to include all of the following elements in each lesson:

  • A link to the lesson’s Reddit thread (like this one)
  • A link back to this post to make sure people joining in a later lesson can always find the beginning of the “course”
  • A recap and link back to the previous lesson
  • A link to the Stork github project and the relevant tag for the lesson, which can always be pulled and compiled and run as a simple REPL to demonstrate the new functionality from the lesson
  • A discussion of the features being added that lesson and references to the relevant code
  • Interesting questions to think about after having read through the lesson

Lesson Plan

And, just to give you a taste of what’s next, here’s the current lesson plan for Stork:

  1. Tokenization — Teasing out the “words” of a programming language
  2. Parsing — Organizing tokens into trees representing syntactic constructs
  3. Expressions — Using parse trees as units of executable code
  4. Variables — Associating names with types and values
  5. Functions — Functions as a weird kind of value, and why we’re using two-phase compilation
  6. Control Structuresif, while, and friends, and how they affect things like variable assignment
  7. Strings — Strings and the concept of the Abstract Data Type (ADT)
  8. Arrays — Another ADT, and the importance of runtime checking
  9. Structs — Demonstrating an important advantage of static typing
  10. Resources — Introducing extensibility into your language in a structured way

And now, with all this explanatory stuff out of the way, I hope you’ll join me soon for the first lesson!