back

by peter_d_sherman·10y ago·view on hn ↗
In my opinion, the core function "compiler" -- is absolutely beautifully written (The crowning gem of this well-written compiler).

It's abstract without being too abstract (exactly the right level of abstraction), and it's a model of simplicity, comprehensibility (especially for people new to compilers), and elegance:

function compiler(input) {

  var tokens = tokenizer(input); 
  var ast    = parser(tokens); 
  var newAst = transformer(ast); 
  var output = codeGenerator(newAst);

  // and simply return the output!
  return output;
}

In short, a great starting point (especially for beginners) to conceptualize and subsequently delve into the depths of what goes on in a compiler.

An A+ and Two Thumbs Up for your efforts. The teaching potential of this compiler (which is always what I'm looking for in compilers) is huge!

1 comments
Isn't this exactly what functional programming people have been harping on about for decades now?