A programming language from scratch: 3 steps to an interpreter
francisstokes.wordpress.com
francisstokes.wordpress.com
http://cs.brown.edu/courses/cs173/2016/index.html
http://cs.brown.edu/courses/cs173/2016/assignments/programmi...
http://cs.brown.edu/courses/cs173/2016/assignments.html
The "interpreter" assignment has a similar end-goal as this tutorial.
Many of the other assignments (the ones prefixed "ML-") are "mystery languages", where you try to tell the difference between two programming languages that have the same syntax but different semantics. It's a fun way to explore the consequences of language design, I think.
Next year we might do a MOOC.
Here are a few that I'm aware of:
* Racket summer school: https://summer-school.racket-lang.org/2017/
* Oregon Programming Languages Summer School: https://www.cs.uoregon.edu/research/summerschool/summer17/
* DeepSpec summer school: https://deepspec.org/event/dsss17/
One of the most enlightening points about interpreters/compilers is that, to a first approximation, the only difference between an interpreter and compiler is what it does when it walks the tree --- an interpreter executes the actions immediately, while a compiler generates code which executes those actions.
An amazing demonstration of this is at https://news.ycombinator.com/item?id=8558822 and https://news.ycombinator.com/item?id=8746054 . It doesn't actually build an AST, but implicitly creates one and walks it since it does recursive-descent parsing.
(Aside: I happened to glance at the URL at the same time as I was reading the Tokenisation section, and thought "Francis Tokes? How appropriate..." before looking more closely at the page title.)
For something else in a similar vein, I've always liked:
http://howistart.org/posts/nim/1/
I suppose implementing brainfuck is more like writing a vm, than a language - but I still think the article is a surprisingly straightforward implementation of a compiler.
Discovering the nature of second and third Futamura projections is left as an exercise to the reader ;)
I read that as "Futurama" at first and was confused trying to figure out how that TV show was related to interpreters and compilers.
I suppose Lisp and FORTH are the most common for these kind of projects, at least that I have seen, because of the simple syntax.
APL has a pretty simple syntax, but I have not seen anyone choose it for one of these build your own language from scratch projects. I wonder why not?
The somewhat more in depth Beautiful Racket, http://beautifulracket.com/
and the significantly more in depth Structure and Interpretation of Computer Programs, https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html...
Anyway, nice article, well illustrated, love to read stuff like this!
S-expressions are very compact and are easy to parse. There was actually some support for using S-expressions over XML and JSON as a serialization language.[1]
Ron Rivest even proposed S-expressions as a standard.[2]
I still prefer JSON over them though. As the old joke goes, LISP stands for "Lots of Irritating Silly Parentheses."
1 - http://eli.thegreenplace.net/2012/03/04/some-thoughts-on-jso...
I usually have a bit of fun mocking out a language I'd like but end up getting into details like type systems. I never really get to expressing as a CFG.
I'm wondering if the best course is to say right, keys now build a small, procedural language or some kind of barely typed C lookalike as the best step up?
But I think the C4 self-hosted C compiler (discussed at [1]) might be another next step in a different direction.
As to type systems, that's a completely different can of worms (One which I do not have much expertise in). Type systems can range from the simple e.g C to the formal study of type systems (e.g. Hindley-Milner). Personally, I don't really know the formal side very well (I can't recall details from memory the same way I can with (say) Lagrangian mechanics), so I can't recommend one particular book.
- Understanding Hindley-Milner http://akgupta.ca/blog/2013/05/14/so-you-still-dont-understa... - Implementing a basic type system http://cs.brown.edu/courses/cs173/2012/book/types.html
I'm gonna check out the next article and return to the first. Deserves a second reading.
That unexpectedly made me LOL.