Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lucaslarson/hq9

🍋  an interpreter of the HQ9+ programming language, written in C++20
https://github.com/lucaslarson/hq9

99-bottles-of-beer biffle c89 c895 c895fm cplusplus cplusplus-20 cpp cpp20 entire-language hacktoberfest hello-world hq9 hq9p hq9plus interpreter lucaslarson programming-language quine

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

# HQ9+

[![CodeFactor](https://www.codefactor.io/repository/github/lucaslarson/hq9/badge)](https://www.codefactor.io/repository/github/lucaslarson/hq9)
[![Gitpod: ready to code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/LucasLarson/HQ9)
[![Run on Repl.it](https://web.archive.org/web/0id_/github.com/replit/replit.github.io/raw/8d6b0eaf1c/static/images/repls/run-on-replit.svg)](https://repl.it/github/LucasLarson/HQ9)
[![Google: ready to build](https://img.shields.io/badge/Google%20Cloud%20Shell-build-5391fe?logo=google-cloud&logoColor=fff)](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/LucasLarson/HQ9)
[![Codeac](https://static.codeac.io/badges/2-274529532.svg "Codeac.io")](https://app.codeac.io/github/LucasLarson/HQ9)
[![C++ CI](https://github.com/LucasLarson/HQ9/workflows/C++%20CI/badge.svg)](https://github.com/LucasLarson/HQ9/actions?query=workflow:"C%2B%2B+CI")
[![Super-Linter](https://github.com/LucasLarson/HQ9/workflows/Super-Linter/badge.svg)](https://github.com/LucasLarson/HQ9/actions?query=workflow:"Super-Linter")
[![CodeQL analysis](https://github.com/LucasLarson/HQ9/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/LucasLarson/HQ9/actions/workflows/codeql-analysis.yml)
[![GPLP](https://img.shields.io/badge/license-GPLP-blue "GNU General Public License for Pedants")](https://github.com/LucasLarson/HQ9/blob/main/license.adoc)

- [Build](#build)
- [Background](#background)
- [C](#c)
- [C89](#c89)
- [C89.5](#c895)
- [C++](#c-1)
- [C++20](#c20)
- [Implementation](#implementation)

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

```shell
git clone --verbose --recurse-submodules --progress \
--branch main https://github.com/LucasLarson/HQ9
```

2. move to the newly downloaded content

```shell
cd HQ9 || return 1
```

3. build the executable for your machine

```shell
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
```

4. run the executable

```shell
./HQ9+
```

5. try any combination of input specified in the language. My
favorite’s `9`:

```shell
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](https://github.com/LucasLarson/HQ9/tree/v0.3.1)
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](https://c895.org/donate) 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](https://github.com/LucasLarson/HQ9/tree/v1.0.0)
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.