To Implement A Tiny Programming Language, Part 0

(Are you tired of seeing only webdev posts on this site? At least I absolutely am.)

This side project idea has been sitting in my to-do list for way too long. Now that I’ve finished the core of my lexer generator I would like to test it out on something simple, so…

The language

Design By Numbers is an educational programming language designed by MIT professor John Maeda in the late 1990s which later spawned the much more famous Processing. Unlike Processing, the source of Design By Numbers was never officially released to the public. I don’t have the book by Prof. Maeda so I am forced to have some speculation on the actual language design I guess…

The plan

If you guys have any interest in anything other than merely webdev then chances are you know that Processing (and DBN) are in Java. Back in the late 1990s Java is just as prominent as JavaScript (if not more so) – and yes you can embed them in webpages so it was the obvious choice, but of course nowadays if I actually want anyone to use my implementation to display their DBN programs I definitely will have to base everything on browser JS.

I spent a little time figuring out the plan:

  • I’ll try to figure out – and decide, if need be – what exactly is the language’s syntax, grammar and semantics.
  • I’ll write an interpreter for the DBN language, pretending I’ve already implemented all the actual drawing subroutines. To test things out I’ll have placeholders, e.g. instead of actually drawing a line I’ll have it print out DrawLine <x1> <y1> <x2> <y2> in the console.
  • Then I’ll actually implement all the drawing subroutines using the Canvas API.
  • And maybe I’ll write about the process idk.

About the lexer generator I’ve mentioned in the beginning

I wrote it as a part of my toolset because I can’t quite figure out how to fit other tools like ANTLR into my workflow (and my mind does not like reading other people’s code & configurations)

The core idea of the lexer generator is:

  • Most programming languages’s lexical structures can be described with a bunch of regexps.
  • You can “compile” this bunch of regexps into a nondeterministic finite automaton (NFA) using some construction algorithms.
    • AFAIK this is probably how (at least some) regexp engine actually works; the NFA structure might not be explicit but the spirit will be there.
  • The NFA:
    • can be further generated into something like this.
    • can be directly executed with some automata traversing algorithm.
    • or bundled with the actual code of the traversing algorithm.

Combine these facts together and voila you have your very own lexer generator. It’s actually not that hard once you understand. No I won’t be releasing it before completing the whole thing… DBN is such a simple language you probably won’t need any sophisticated tool anyway.

I’ve read the introduction but DBN isn’t a real programming language (at least not as “real” as something like Python), then what’s the point?

Well, if you have to put it that way…


Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Stop using loading spinners – DEV Community

Twitter Bootstrap for Django Form