The Super Tiny Compiler!

chenge

chenge

Posted on December 1, 2018

The Super Tiny Compiler!

Code is more clear than words. I like short code.

A 100 lines file to explain compiler.

From the code below, We can see compile is the whole process. Parser is a step. Metaprogramming is at transform stage I think. AST is kernel data structure.

Know more compile will help you understand all kinds of languages.

link-->

/**
 * FINALLY! We'll create our `compiler` function. Here we will link together
 * every part of the pipeline.
 *
 *   1. input  => tokenizer   => tokens
 *   2. tokens => parser      => ast
 *   3. ast    => transformer => newAst
 *   4. newAst => generator   => output
 */

function compiler(input) {
  let tokens = tokenizer(input);
  let ast    = parser(tokens);
  let newAst = transformer(ast);
  let output = codeGenerator(newAst);

  // and simply return the output!
  return output;
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
chenge
chenge

Posted on December 1, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

The Super Tiny Compiler!
compiler The Super Tiny Compiler!

December 1, 2018