“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
- Free text/grammar: literally what you type
- Lexer/lexical analysis: text to tokens
- Tokens/Lexemes: chunks of your syntax
- Parser: tokens to the 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 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