software
Stork, An Example Programming Language, Lesson 4: Variables
Welcome back!
For those of you just joining, Stork is an example programming language “course” designed to demonstrate the principles of programming language implementation in 10 “lessons.” This is Lesson 4 in a series of 10, so if you’re just joining now, you may want to take a peek at lessons 1, 2, and 3 to gear up a bit for this post.
Lesson 4 adds variables to Stork, which involves adding statements in addition to the expressions already in the language. The addition of variables provides fodder for some additional (and more interesting) static analysis as well. At the end of this lesson, Stork will be a working interpreter for simple numerical expressions with support for variables. (The variables will become much more interesting over the course of the next couple of lessons, which will add support for functions and control structures.)
The code for this lesson is available on github under the tag lesson4, and you can follow the discussion about this lesson on reddit. As a quick preview, though, Stork is getting cool:
$ java com.sigpwned.stork.Stork
>>> var x:Int
>>> x
ERROR: Variable may not have been initialized: x
>>> x = 1+2*(3+4)
15
>>> var y:Float
>>> y = x
15.0
>>> x = y
ERROR: Will not coerce to less precise type: Float -> Int
>>> x = (cast Int) y
15
>>> x+y
30.0
>>> ^D
$


