OpenQASM is the assembly language quantum hardware speaks - the format qiskit emits and QuantumFramework imports. It is the parser zoo's full-fledged tier: a real DSL with two dialects, a statement grammar, parametrized and modified gates, custom gate definitions, and angle expressions. This note builds up the language a construct at a time, parsing it with
Each gate is a record carrying its name, evaluated parameters, modifiers, and a list of qubit references. A qubit reference is itself a small Association:
<|"Register"->"q","Index"->0|>
for
q[0]
,
<|"Register"->"q"|>
for a bare register,
<|"Physical"->0|>
for the hardware qubit
$0
.
One grammar, two dialects
OpenQASM 2.0 and 3.0 differ mostly in how they spell register declarations and measurement, so a single grammar handles both and lowers them to the same IR. A declaration production is just an ordered choice over the four spellings:
- both normalize to one record naming the measured qubit and the classical target. And a construct outside the circuit-level subset (classical control flow, timing,
def
) is recognized by its leading keyword and captured as an
"Unsupported"
record instead of failing the whole read, so a mostly-importable file still yields its importable part:
The IR is intentionally neutral: it validates syntax, not semantics. It does not check gate arities, resolve register offsets to absolute wires, or know that
cx
is a controlled
X
- those are an importer's job. That separation is the point: QuantumFramework's importer can map this IR's
"Statements"
to QuantumOperator elements and assemble a QuantumCircuitOperator, replacing the hand-rolled regex scanner it used before with a real grammar - while the parser itself stays a dependency-free part of the zoo. See the parser zoo guide for the other languages and the shared design.