Bloch Runtime Overview
Bloch executes programs with a tree-walking interpreter and an ideal statevector simulator that logs OpenQASM 2.0 operations.
Architecture
- Lexer: Produces tokens with line/column info; skips whitespace and
//
comments. - Parser: Builds the AST following the Grammar.
- Semantic Analysis: Validates scopes,
final
, function contracts, built-in calls,@tracked
, and return rules (see Semantics). - Runtime Evaluator: Interprets statements/expressions, buffers
echo()
output, calls the simulator for gates, and records measurements.
Simulator
QasmSimulator
maintains a statevector and emits a QASM log. Gates update amplitudes; measure
collapses and writes measure q[i] -> c[i];
to the log. reset
sends a qubit to |0>
robustly.
QASM emission
The CLI always writes <file>.qasm
next to your source. Use --emit-qasm
to also print it to stdout.
Key Files
src/bloch/lexer/
– lexical analysissrc/bloch/parser/
– recursive descent parsersrc/bloch/ast/
– AST nodessrc/bloch/semantics/
– semantic analysersrc/bloch/runtime/
– interpreter and simulator