Tree Walk Interpreter

Iman Tung
May 16, 2021

“If you don’t know how compilers work, then you don’t know how computers work. If you’re not 100% sure whether you know how compilers work, then you don’t know how they work.” — Steve Yegge

Like a few weeks ago I did research about interpreters for a DSL-related project.

This approach called Tree-Walking Interpreter is the simplest way to make an interpreter

  1. Free text/grammar: literally what you type
  2. Lexer/lexical analysis: text to tokens
  3. Tokens/Lexemes: chunks of your syntax
  4. Parser: tokens to the syntax tree
  5. Syntax Tree/Abstract Syntax Tree or AST: model represented operator with its precedence level and associativity
  6. Evaluator: running through AST and execute the operation.

For those who looking for more resources to start learning on this subject, I recommend Ruslan Blog and Writing An Interpreter In Go

Previously published in https://imantung.github.io at 20 Dec 2017

--

--

Iman Tung

Technology to write, life to grateful. Overthinking is good, only if it has the output. Fundamental is the main concern.