🍋 an interpreter of the HQ9+ programming language, written in C++20
This is an interpreter of the entire HQ9+ programming language, implemented in C++20. The output of
9is Rosetta Stone-compliant and takes a balanced approach to the recursion-versus-readability problem.
This interpreter can be built and tested with almost any C++ compiler built since the 2010s. Testing beyond compilation was completed using Clang 12.0.0 on macOS 11.0 beta and GCC 8.3.0 on Alpine Linux 3.10.0 on iSH 1.0 (73) on iOS 14.0 beta.
git clone --verbose --recurse-submodules --progress \ --branch main https://github.com/LucasLarson/HQ9
cd HQ9 || return 1
clang++ -std=c++2a --verbose -v -Wall -Wextra -pedantic -g -lm -lstdc++ -O0 \ -fcaret-diagnostics -fdiagnostics-fixit-info -fdiagnostics-parseable-fixits \ -fdiagnostics-print-source-range-info -fdiagnostics-show-option -fident \ -fno-builtin -fshow-column -fshow-source-location -fstandalone-debug \ -ftime-report -ftrapv -integrated-as -pthread -save-stats -save-temps \ $(find * -iname '*\.cpp') -o HQ9+ || ./bootstrap.sh
HQ9+ is a programming language written by Cliff L. Biffle in the early 2000s. <!-- oldest extant copy of the specification: web.archive.org/web/20010511232301id_/cliff.biffle.org/esoterica/hq9plus.html -->
C, written by Dennis Ritchie and Ken Thompson in the mid‑1900s, is the more popular successor to the B programming language.
C89 is the functional equivalent of ANSI C and was published in the late 1900s. In 2020, v0.3.1 of this HQ9+ interpreter was published in C89.
There has long been an excellent public radio station in Seattle broadcasting at 89½ MHz. In spoken vernacular, it, too, is often referred to as C89. Please support their important work.
C++ is a grandchild language of the B programming language and a superset of its parent language, C.
The release of the version of the C++ programming language whose features were finalized just prior to a pandemic, but which at release time, had still not been incorporated into an ISO standard. In 2020, v1.0.0 of this HQ9+ interpreter was published in C++20.
Where a specification omits implementation details – where a language’s behavior is undefined – it is the interpreter’s right or responsibility to map conditions to specific behavior where agnosticism fails. That is, unspecified conditions must result in implementation-defined behavior.
For example, the HQ9+ specification implies the machine running it has infinite memory and that the length of input itself have asymptotic similarity to infinity. The devices on which this interpreter was tested had unclear limits, but in all cases, those limits were unambiguously finite, as are the lengths of primitive variable types in C and C++.
Similarly, the specification does not detail how the accumulator’s value is accessed after its initialization at
0. In an abundance of caution, and without drawing conclusions, this implementation is responsive to the ambiguity by tracking the accumulator’s value, but preventing accession to it. Further research must verify whether this is a safer alternative than writing to
/dev/null, which may raise concerns about data loss.