DEV Community

loading...

Live Stream: Writing a Programming Language from Scratch

Seán Kelleher
・2 min read

At 17:00 GMT tomorrow (June 6) I'll be be streaming a coding session from Twitch, where I'll be implementing an interpreter for a custom programming language. This may be interesting to those who want to learn the basics of how programming languages are implemented, or for those who already know but haven't yet implemented one themselves. I'll also be providing commentary and answering any questions that may come up during the session.

Edit: The stream is now available at https://www.twitch.tv/videos/1047868433.

The Target Language

The language I'll be developing will be a custom C-style interpreted language. I intend to use this custom language as a skeleton for playing around with different syntaxes/styles for a further programming language project that I plan to work on.

The language itself will be a fairly typical C-like language consisting of a number of common features from modern languages:

  • Basic types: Booleans, integers and strings
  • Complex types: Lists, objects (maps) and functions/methods
  • Python-like strong, runtime typing, with optional typing in future
  • Python-like string/list access
  • Python-like built-in functions like len, keys, etc.
  • Rust-like control flow syntax (e.g. if true { ... } and for x in xs { ... })
  • Rust/JS-like array/object composition (spreading) and decomposition
  • Go-like error handling

Here are some example snippets:

x = 1
if x < 2 {
    print('T')
} else {
    print('F')
}

# Output:
#
# T
Enter fullscreen mode Exit fullscreen mode
i = 0;
while i < 3 {
    print(i);
    i += 1;
}

# Output:
#
# 0
# 1
# 2
Enter fullscreen mode Exit fullscreen mode
xs = ['b', 'c'];
ys = [xs.., 'a', xs..];
[_, _, ..zs] = ys
for z in zs {
    print(z);
}

# Output:
#
# a
# b
# c
Enter fullscreen mode Exit fullscreen mode
fn half(n) {
    return n / 2
}

fn map(f, xs) {
    for i in 0..len(xs) {
        xs[i] = f(xs[i])
    }
}

print(map(half, [4, 5, 6]))

# Output:
#
# [2, 2, 3]
Enter fullscreen mode Exit fullscreen mode

The Source Language

I'll be writing the interpreter in Rust using LALRPOP. The data structuring and pattern matching capabilities of Rust make it a perfect fit for building and walking ASTs.

Finally

Please feel free to join me and ask questions. Also, please let me know in the comments here if there's anything that you'd like to see and I'll do my best to cover it.

Discussion (0)