Nybblang

From Esolang
Jump to navigation Jump to search

Nybblang is an esolang created by User:PythonshellDebugwindow. Its name is a portmanteau of 'nybble' (4 bits) and 'esolang'.

Program structure

A Nybblang program is composed of four bits—a nybble. Each command is two bits long, therefore a program has two instructions.

Memory

Nybblang uses a stack of nybbles. When a digit is pushed to it, it first goes into a temporary variable, which will also hold the next two digits pushed. When it reaches four digits—a nybble—that nybble will be pushed to the stack and the temporary variable set to 0 (0000).

The bits composing this buffered nybble are assembled from the least significant bit (LSB) position towards the most significant one (MSB), that is, each newly inserted bit contributes a strictly higher value than its predecessor in the buffer.

Program import

The interpreter should be given these command-line arguments: main *others, where main is the filename of the first program to be run and others are the programs in the sequence. Alternatively, a directory may be supplied with the programs in it as these files, e.g. nybblang my/directory

Program import sequence

If the interpreter is run with nybblang main.nyb sub1.nyb sub2.nyb, then main.nyb is run first, and the running sequence (for the 11 command) is main.nyb, sub1.nyb, sub2.nyb, main.nyb, sub1.nyb, sub2.nyb, main.nyb, ..., wrapping and repeating forever.

Character Set

A corollary of the restriction of the data types to nybbles, merely 16 different integral values, commorant in the closed interval [0, 15], remain available for the output facility's character encoding. The following tabulation shall elucidate this membership:

Code Character
0 E
1 T
2 A
3 O
4 I
5 N
6 S
7 R
8 H
9 D
10 L
11 space
12 W
13 U
14 .
15 newline

Commands

Command Meaning
00 Push 0 to the memory
01 Push 1 to the memory
10 Output the Nth character of the sequence ETAOINSRHDLspaceWU.newline, where N is (POP stack)
11 Import the next program in the sequence (wrapping)

Any non-0-or-1 characters in the source code raise an error.

Examples

Each file in the sequence is on a different line; these files are arranged in sequential order.

"HELLO"

0011
0011
0011
0111
1011
0011
0011
0011
0011
1011
0011
0111
0011
0111
1011
0011
0111
0011
0111
1011
0111
0111
0011
0010

Computational class

Nybblang is incapable of performing computations without modification. In effect, it has 4 operations; push 0, push 1, pop-output, next-source. The first three commands can be used to fill the stack arbitrarily and output any of the characters in the alphabet. If working with a single source file, the next-source (11) command can be used to have an infinite loop. Since programs of any length can be decomposed into a series of nibbles by separating each instruction in its own file and adding 11 as the second command, Nybblang is able to represent programs which infinitely loop, or don't loop at all, which push arbitrary values to the stack, and pop to output. Unfortunately, there are no ways of having the stack affect the behavior of the program, meaning that Nybblang can perform no computations.

Modification

If a Nybblang program could be of arbitrary length, then imports would be unnecessary, so the command 11 could be turned into a (1-index-based) conditional jump: IF stack.bottom > 0 THEN GOTO instruction n where n is the item directly on top of the bottom of the stack (or the bottom of the stack if the stacks has only 1 item), and if n is 0 or greater than the program’s length then the program should exit. Here's a truth-machine in this version of the language that outputs E or T instead of 0 or 1:

0x0000000x0000001011

Replace both of the xs with 0 for input 0 or 1 for input 1. If you use 1, the stack would infinitely grow larger as there are two PUSH operations but only one POP.

The computational class of this modified version is not immediately obvious. Some notable points are that the conditional jump instruction can only ever index the first 15 instructions of the program, and it can only read memory using said instruction, and only memory at the bottom of the stack. It certainly allows for some level of computation, meaning that the only thing missing for the basic requirements of Turing completeness is access to infinite bidirectional memory. The stack is infinite, it can store an indefinite amount of nibbles. However, it works somewhat like a queue. Modifications to the stack happen only on one end, while reads happen on the other. This means that the stack only has 2 nibbles of effective storage, as any conditional behavior requires the stack to be cleared for the conditionally important values to be put at the bottom. Do note that in addition to the stack, there is a temporary register which is used to push nibbles onto the stack when it becomes full, which adds 3 extra bits which can be preserved across conditional jumps. Therefore, this modification only increases the computational class to that of finite state machines, as it only has access to 11 bits of state.

A transfinite program written in Nybblang may be more powerful, but transfinite programs are not part of the typical hierarchy.

Interpreter

  • Common Lisp implementation of the Nybblang programming language. The interpreter fails anent one aspect of the Nybblang language's compliance in its incapacity to furnish a command line interface; in lieu of such several modes of its Nybblang programs' provision, including the specification of single files or directories, encompass the proffered services.