For The Worthy

From Esolang
Jump to navigation Jump to search

For The Worthy is an esolang which only interprets the '1' and '0' characters, thus enabling programmers to reach their final "hackerman" form.

Language Overview

Instructions

The language consists of 8 instructions each with a unique 4 bit identifier.

  • 0001 - Declares a variable. The next two bits determine type, "01" boolean, "10" 16 bit integer, "11" character. The next bit determines if a value will be assigned or not with "1" meaning yes and "0" meaning no. Next 8 bits are the name of the variable. Finally, if the value bit was set to "1", the next bits are the starting value of the variable. For booleans this is just one bit, for characters 8 (according to the ASCII table). Integers use 17 bits, the first bit is used to determine wether the number is negative(if the bit is set the rest of the number is multiplied by -1).
  • 0010 - Prints. The next two bits represent what will be printed, "00" hardcoded value, "01" variable, "10" result of an expression. It a hardcoded value was selected the next 8 bits reprsent the length od the statement to be printed in characters, then that many characters follow represented as 8 bits numbers according to the ASCII table. If you want to print the value of a variable then the 8 bit long name of that variable is to be written here. Lastly if the expression was selected, it shall be written here.
  • 0011 - Sets a variable to user input. The next 8 bits are the variable name of the variable that is desired to be written to.
  • 0100 - If statement. If the following expression is true then all instructions up to the "0110" will be executed.
  • 0110 - Else statement. All following instructions will be executed if and only if the "0100" instruction preceeding it returned false.
  • 0101 - EndIf statement. Determines how far instructions stil belong to the "0100" or "0110" statements.
  • 0111 - Goto statement. The following 16 bits are the number of the instuction in the program that it is expected to jump to.
  • 1000 - Assigns a value to a variable. The next 8 bits are the name of the variable. The bit after that represents if it will be given a hardcoded value or the result of an expression, "1" coresponds to the hardcoded value, while "0" means expression. Next the value follows with the number of bits that correspond to the type of variable that is the variable with the name given, or an expression.

Expressions

Expressions are evaluated and return a value to be used in instructions. They consist of the left side argument, right side argument and the operation. Arguments can be expressions themselves. Arguments are written as 3 bits representing the type of the argument, and the corresponding number of bits required of that type. The arguments types are:

  • 000 - The argument is itself an expression. These are evaluated recursively.
  • 001 - The argument is a variable, an 8 bit variable name is expected after this.
  • 010 - Harcoded boolean, the next bit is its value.
  • 011 - Hardcoded integer, the next 17 bits represent its value.
  • 100 - Hardcoded character, the next 8 bits represent its ASCII value.

The operation is written between the arguments and uses 4 bits. There are 14 operations. These are:

  • 0000 - + Adds the arguments together.
  • 0001 - - Subtracts the right argument from the left.
  • 0010 - * Multiplies both arguments together.
  • 0011 - / Divides the left argument by the right .
  • 0100 - % Returns the remainder of the division of the left argument by the right.
  • 0101 - AND Returns 1 if both arguments are not 0.
  • 0110 - OR Returns 1 if either or both of the arguments are not 0.
  • 0111 - XOR Returns 1 if one and only one of the arguments are not 0.
  • 1000 - == Returns 1 if the arguments are equal.
  • 1001 - != Returns 1 if the arguments are not equal.
  • 1010 - > Returns 1 if the left argument is greater than the right.
  • 1011 - < Returns 1 if the left argument is smaller than the right.
  • 1100 - >= Returns 1 if the left arguments is greater or equal to the right.
  • 1101 - >= Returns 1 if the left arguments is smaller or equal to the right.

Comments

Since all characters are ignored by the interpreter aside from '1' and '0', comments can be placed anywhere without special markers. The only limitation is that for them not to influence the program they cannot contain '0' or '1'. For these characters to be used the first character of a line in the text file must be '#' witch makes the interpreter ignore that entire line.

Examples

The following examples use whitespaces and new lines to improve readability of the code. These are not necessary for the interpreter to function.

Hello World program:

0010 00 00001100 01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 00100001

Truth Machine Program:

0001 11 0 00000000
0011 00000000
0100 001 00000000 1000 100 00110000
0010 00 00000001 00110000
0110
0010 00 00000001 00110001
0111 0000000000000110
0101

Simple Calculator program:

0001 10 0 00000000
0001 10 0 00000001
0001 11 0 00000010
0011 00000000
0011 00000010
0011 00000001
0100 001 00000010 1000 100 00101011
0010 10 001 00000000 0000 001 00000001
0101
0100 001 00000010 1000 100 00101101
0010 10 001 00000000 0001 001 00000001
0101
0100 001 00000010 1000 100 00101010
0010 10 001 00000000 0010 001 00000001
0101
0100 001 00000010 1000 100 00101111
0010 10 001 00000000 0011 001 00000001
0101

External Resources