20 Dec 2017
Tree Walk Interpreter
“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 fews week ago I did research about interpreter for some DSL project. However things happened, and I got crashed away from the project.
This approach called Tree-Walking Interpreter, which is the simplest way to make interpreter
- Free text/grammar: literally what you type
- Lexer/lexical analysis: text to tokens
- Tokens/Lexemes: chunks of your syntaxs
- Parser: tokens to syntax tree
- Syntax Tree/Abstract Syntax Tree or AST: model represented operator with its precedence level and associativity
- Evaluator: running through AST and execute the operation.
For whom looking for more resources to start learn on this subject, I recommend to read Ruslan Blog and Writing An Interpreter In Go