QuantumC is a C99 compatible programming language designed for quantum computing, accompanied by a compiler that translates C code to OpenQASM. As the International Year of Quantum Science and Technology unfolds, quantum computing and quantum information have seen remarkable breakthroughs. Quantum computers are now more accessible than ever, enabling individuals with programming experience to execute quantum circuits on real quantum hardware and obtain results.
While Python’s straightforward syntax has made it the language of choice for many quantum computing tools (e.g., Qiskit and Cirq), optimal quantum speedup requires efficient post-processing of quantum data. The lightweight nature of the C programming language, combined with its tenacious community, makes it an excellent candidate for circuit construction and classical post-processing. The QuantumC project aims to demonstrate C's clarity as a quantum programming language.
Python is widely used for application development due to its easy learning curve, but its runtime performance can be dawdling, especially for iterative tasks.
As quantum hardware advances, the volume of classical data to process will increase, making performance a critical factor.
OpenQASM, managed by IBM, is an open-source quantum intermediate representation for describing quantum circuits.
Quantum hardware architectures vary, necessitating the compilation of theoretical circuits into machine-specific instructions.
For instance, Hadamard gates
Consider the creation of a Bell state in an 8-qubit system, which demonstrates entanglement of eight qubits: qubit 0, then apply a controlled-NOT gate (qubit 0 as control and qubit 1 as target.
Repeat locating controlled-NOT gates between successive qubits (for example, qubit 1 as a control and qubit 2 as a target) until qubit 7.
Finally, apply a measurement gate to every qubit to convert the quantum data into classical data for post-processing.
After this process, we obtain the following quantum circuit.
#include <inttypes.h>
#include <quantumc.h>
uint8_t eight_qubit_bell_state() {
qubit q[8];
apply_H(q[0]);
for (int i = 0; i < 7; i++) {
apply_CX(q[i], q[i+1]);
}
uint8_t meas = measure(uint8_t, q);
// Expected to return 0b00000000 == 0 in 50% and 0b11111111 == 255 in 50%.
return meas;
}OPENQASM 3;
include "stdgates.inc";
qubit[8] q;
h q[0];
cnot q[0], q[1];
cnot q[1], q[2];
cnot q[2], q[3];
cnot q[3], q[4];
cnot q[4], q[5];
cnot q[5], q[6];
cnot q[6], q[7];
bit[8] meas;
meas = measure q;Documentation for setup and usage will be provided as the project evolves.
compiler/: Contains the source code for the QuantumC compiler.figures/: Contains the figures for the QuantumC documentation.specs/: Contains the specifications for the QuantumC language.tests/: Contains the testing cases for the QuantumC compiler.
This project is built with GCC and make and uses flex and bison to generate the lexer and parser. You will need a POSIX-like environment (Linux or Windows Subsystem for Linux) with the following tools installed:
gcc(C compiler),make(building tool),flex(lexer generator), andbison(parser generator).
- Debian / Ubuntu:
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential flex bisonNote: The package build-essential includes gcc, make, and other basic build tools.
- Fedora / RHEL (DNF):
sudo dnf install -y gcc make flex bison- Windows: use WSL (recommended) or an MSYS2 environment. In WSL (Ubuntu) run the Debian/Ubuntu commands above. If using native Windows toolchains, ensure
flex/bisonare available (MSYS2 packages or binaries).
- Open a terminal in the project root or the frontend directory
compiler/src/fe. - Run
make(the default target produces themainexecutable):
make- To remove generated files and object files:
make clean- If
makefails withbison: command not foundorflex: command not found, install those packages or run the build in WSL/macOS where the tools are available. - If you see undefined reference errors at link time, check whether any required libraries are missing or whether object files failed to compile earlier in the output.
Before making any contributions, please refer to the contributing documentation.
MIT License.

