How It Works
Risor follows standard patterns for implementing a scripting language. This includes parsing source code into an Abstract Syntax Tree (AST), compiling the AST into bytecode, and then executing the bytecode on a lightweight virtual machine.
The excellent book Writing an Interpreter in Go (opens in a new tab) was the original inspiration for the project.
The Internals
Risor includes the following internal components:
- A lexer (opens in a new tab) which takes source code as input and produces a stream of tokens as output.
- A parser (opens in a new tab) which takes tokens as an input and produces an abstract syntax tree (AST).
- A compiler (opens in a new tab) which compiles the AST into Risor bytecode instructions.
- A virtual machine (opens in a new tab) which executes the program bytecode.
- Built-in types (opens in a new tab) available to all programs.
- Built-in functions (opens in a new tab) that are accesible by default.