Ask HN: Guidance on writing a source to source compiler (transpiler)
I would like to learn to write a transpiler from scratch. Where would I get started?
Preferably something that doesn't involve going though big projects to read the source code.
Preferably something that doesn't involve going though big projects to read the source code.
8 comments
[ 6.0 ms ] story [ 28.1 ms ] threadhttps://www.destroyallsoftware.com/screencasts/catalog/a-com...
Really easy to understand, even if Ruby is not your main language. The video is about compiling from a tiny Ruby-like language[1] into real JavaScript.
[1]: It's only a single, simple function, but the concepts are well explained and it should be easy to build on top of that.
https://github.com/jamiebuilds/the-super-tiny-compiler
That converts from lisp-like to javascript. Really though this is a big field, and there are lots of resources out there.
To get started look at your input language; you'll need to lex and parse that. Then massage the parsed structure into the appropriate output.
You can see me convert brainfuck to C, or x86 assembly language here:
https://github.com/skx/bfcc