Here is a timeline of events that happen when a user invokes the Varphi Interpreter (vpi
) on a Varphi file:
The Varphi Interpreter executable, through Python's argparse, parses the arguments supplied to the executable. It extract's the user's Varphi source code file path, and determines what the compilation target will be (either a command-line program, command-line program with debugging, or debug adapter).
The user's Varphi source code file is opened for reading, and it's contents are passed through a lexer. The lexer tokenizes the code and catches specific syntax errors at this stage (specifically, a syntax error is thrown by the lexer only if a line element does not fit the criteria to be a state name, tally, blank, or head direction).
Once every line has been stepped through by the translator, a string containing the compiled Python code is sent to the interpreter. A call to Python's exec
is made on the compiled Python code, which opens a session that the user can pass the input tape to and receive output from.
The Varphi codebase consists of two parts:
The Varphi-to-Python Compiler
The Varphi Interpreter
The Varphi-to-Python Compiler is a (non-published) Python package and is located under the varphi
directory in the source code directory.
The three components of the Varphi-to-Python Compiler are:
The lexer and parser
The translators (Compilers)
The Varphi Runtime Library
The lexer and parser are generated from a grammar file (Varphi.g4
) and are not included in the source code. When Varphi is built, they are located under varphi/parsing/VarphiLexer.py
and varphi/parsing/VarphiParser.py
, respectively.
Varphi includes a translator, or compiler, for every possible target (command-line program, debug adapter, etc.). These are located under varphi/compilation/varphi_translator.py
.
The Varphi Runtime Library is a set of utilities used by the Python code which Varphi programs are compiled to. This library is located under varphi/runtime
.