Documentation
¶
Overview ¶
Package parser implements a hand-written recursive descent parser for OpenQASM source. Both QASM 2 (qreg/creg, measure q -> c) and QASM 3 (qubit/bit, c = measure q) syntax are supported.
Entry points are Parse (from an io.Reader) and ParseString. The returned ir.Circuit contains all declared qubits, classical bits, gate operations, measurements, barriers, resets, and conditionals.
Use WithStrictMode to reject unknown gate names; the default mode treats them as opaque gates.
Package parser implements a hand-written recursive descent parser for OpenQASM 3.0.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseString ¶
ParseString parses OpenQASM 3.0 source from a string.
Example ¶
package main
import (
"fmt"
"github.com/splch/goqu/qasm/parser"
)
func main() {
src := `OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c = measure q;`
c, err := parser.ParseString(src)
if err != nil {
panic(err)
}
stats := c.Stats()
fmt.Printf("qubits=%d clbits=%d ops=%d depth=%d\n",
c.NumQubits(), c.NumClbits(), stats.GateCount, stats.Depth)
}
Output: qubits=2 clbits=2 ops=4 depth=3
Types ¶
Click to show internal directories.
Click to hide internal directories.