Skip to content

How It Works

Tamarin includes an interpreter written in Go and uses an approach called Pratt Parsing to parse expressions. The excellent book Writing an Interpreter in Go was the inspiration for the project.

The Internals

As with many other interpreted languages, Tamarin includes:

  • A lexer which takes source code as input and produces a stream of tokens as output.
  • A parser which takes tokens as an input and produces an abstract syntax tree (AST).
  • An evaluator which executes an AST as a program.
  • Built-in types available to all programs.
  • Built-in functions that are accesible by default.

Controlling Execution

The exec package offers a user-friendly API to use Tamarin as a library. The provided context.Context is used to cancel execution or limit execution with a timeout. Internally Tamarin passes this context to all operations to guarantee that execution quickly stops when the context is canceled.


A single Tamarin execution operates within a single goroutine. Multiple Tamarin executions may happen concurrently and these are entirely independent. Tamarin avoids all use of global state.

Providing Input

When running Tamarin as a library, you can provide input data to the scripts by passing in a scope that has been pre-populated with some variables. The scope can be passed via the exec.Opts struct that is passed to an execution.