Crafting a toy language for learning purposes

Hi lads,

I'm considering designing a basic, simple toy language that's able to compile itself, mainly for learning/fun purposes. I'll be targetting something that can be done over weekends as a hobby. One thing I'm particularly interested in, in order to bootstrap, is have clang as backend, and somehow use bindings in the compiler to generate code. Any pointers to tutorials, blogs or even github source code of similar projects (as small as possible for me to actually understand) would be really nice.

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Maru

Ian Piumarta's Maru is a classic.

Lisp in Small Pieces

I know you didn't ask for a book reference and the following contains nothing about clang so I apologise here and now for answering the question I think you should have asked instead.

Get Queinnec's "Lisp in Small Pieces". The book is just under 500 pages of bootstrap. It was written by someone who knows his stuff and knows how to teach it. I guarantee there is at least one thing in that book you didn't even know existed.

ichbins

ichbins is a self-hosting compiler of a Lisp dialect to C in 6 pages of code.

Kahn Academy

Kahn Academy recently released a Computer Science curriculum using a slightly extended JavaScript inspired from Bret Victor's live programming example a while back.

Edit: What exactly do you mean by "a toy language for learning/fun purposes" anyway?

Logo

Logo writer was a decent language for learning, though I've not paid much attention to it over the last twenty years. IIRC, it was as capable as any dynamically scoped Lisp. I'll bet it could compile itself.

A C subset compiler in C

Nils Holms - who did "Scheme9 from Empty Space" which was, I think, mentioned on these pages - has come up with "Practical Compiler Construction". It's available as a book/pdf from Lulu. The source is at http://www.t3x.org/.

At 391 pages it's a densely annotated C listing of a subset of C.

(Usual disclaimers - I'm nothing to do with Nils, Lulu or the product in any way.)