Skip to content

🍋  an interpreter of the HQ9+ programming language, written in C++20

License

Notifications You must be signed in to change notification settings

LucasLarson/HQ9

Repository files navigation

HQ9+

CodeFactor Gitpod: ready to code Run on Repl.it Google: ready to build Codeac C++ CI Super-Linter CodeQL analysis GPLP

This is an interpreter of the entire HQ9+ programming language, implemented in C++20. The output of 9 is Rosetta Stone-compliant and takes a balanced approach to the recursion-versus-readability problem.

Build

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.

  1. Open a terminal and get the code
git clone --verbose --recurse-submodules --progress \
  --branch main https://github.com/LucasLarson/HQ9
  1. move to the newly downloaded content
cd HQ9 || return 1
  1. build the executable for your machine
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 \
  ./*.cpp -o HQ9+ || ./bootstrap.sh
  1. run the executable
./HQ9+
  1. try any combination of input specified in the language. My favorite’s 9:
9

Background

HQ9+ is a programming language written by Cliff L. Biffle in the early 2000s.

C

C, written by Dennis Ritchie and Ken Thompson in the mid‑1900s, is the more popular successor to the B programming language.

C89

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.

C89.5

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++

C++ is a grandchild language of the B programming language and a superset of its parent language, C.

C++20

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.


Implementation

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.