Skip to content

An esoteric programming language to play around and create boolean functions while being strictly limited to operations involving NAND gates.

License

Notifications You must be signed in to change notification settings

rreemmii-dev/NAND-Language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAND programming language

An esoteric programming language to play around and create boolean functions while being strictly limited to operations involving NAND gates.

The NAND gate is functionally complete. Thus, any boolean function ($\set{0, 1}^n \to \set{0, 1}^m$) can be implemented using only combinations of NAND gates.

Still, it is not a Turing-complete language. For example, while loops are not allowed.

a screenshot of the NAND programming language

Installation and Use

Build the interpreter

To build the interpreter, you need to have dune installed.

cd src
dune build
cd ..
mv src/interpreter.exe .

Run the interpreter

After building the interpreter, you can execute it on your .nand source file.

./interpreter.exe file.nand

Syntax and Features

Variables

As a convention, lowercase names are used for booleans, and uppercase names for arrays.

x = 1;  /* Defines x as the boolean value 1 (true) */
x = 0;  /* Changes the value of x to 0 (false) */

X{8} = 0;  /* Defines X as an array of lenght 8 filled with 0 (false) */
X[2] = 1;  /* Changes the value of X[2] to 1 (true) */

Functions

Using the same convention as for variables, lowercase names are used for functions returning booleans, and uppercase names for functions returning arrays.

fun not(x) {
    return nand(x, x);  /* nand is the only already-defined function */
}

For loops

For loops can only iterate over a range of indices (inclusive).

for i = 0 to 3 {
    X[i] = not(X[i]);
}

Debugging

There are two debugging tools: debug print and debug [int32 | int16 | int8]

debug print X;  /* Prints X as a human-readable value */
debug int8 X;  /* Prints the 8-bit signed integer representation of X */

Example code

Simple example

Here is a simple example:

fun not(x) {
    return nand(x, x);
}

fun main() {
    X{8} = 0;
    X[2] = 1;

    debug print X;  /* Output: Array {  Bool false  Bool false  Bool true  Bool false  Bool false  Bool false  Bool false  Bool false    } */

    for i = 0 to 3 {
        X[i] = not(X[i]);
    }

    debug print X;  /* Output: Array {  Bool true  Bool true  Bool false  Bool true  Bool false  Bool false  Bool false  Bool false    } */
    debug int8 X;  /* Output: Int8 11 */
}

Larger example code

A larger example code providing an implementation of 16-bits signed integers can be found in file.nand

License

Distributed under the MIT License. See LICENSE.md

About

An esoteric programming language to play around and create boolean functions while being strictly limited to operations involving NAND gates.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published