HEX

From Esolang
Jump to navigation Jump to search

HEX is a language created by User:Barrucadu based on the HEX machine from the Discworld books. As stated in the books, anything is possible if you get enough bugs in the system. If any discworld-enthusiasts want to help me with this, send me an email! The current specification is Hex Version 2.2

Commands

Command Description
# Comment
Bug("name", "value") Create a variable.
Scuttle("bug") Push bug to stack if not alread there, Pop it if it is.
Write Print the values of the bugs in the stack.
Listen("bug") Take 1 character of input and make it the value of <bug>.
GBL Pull the Great Big Lever (start the program).
Return Pop all bugs from the stack.
Fork("bug1" operator "bug2") If bug1 (operator) bug2, where operator is ==, !=, >=, <=, >, <. If using anything other than "==" or "!=", bug must be numeric. Next line will be treated as a comment if false.
EndFork End the current FORK.
SetTrack ("bug") Set the track to "bug".
Track ("track") If the track is equal to "track", execute the following code (Up to the relevant EndTrack).
EndTrack End the current TRACK.
Breed("bug1" operator "bug2") Perform an action on bug1, using the operator and bug2 as an argument. Operator can be +, -, /, * or =. Bug1 contains the value and Bug2 is unchanged. Bugs must be numeric for -, / and *. If using + with non-numeric bugs, the values will be concacted together.
:name Defines a label
Goto name Jumps to a label. The label can be anywhere in the code.
End Terminates the program. It is not needed to make the code valid.
Chr("bug") Convert the bugs value to an ASCII character. Bug must be numeric.
Asc("bug") Convert the bug to its ASCII numeric value. Bug must be one character long.
Quine Print the programs source, after it has finished executing.

Error Messages

Error Message Meaning
"+++ Out of Cheese Error. Redo From Start. +++" Bug or label does not exist.
"+++ Melon melon melon +++" Tried to perform an action with invalid parameters.
"+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++" Unknown command. Anything other than a comment or whitespace before the GBL is considered an unknown command.

Notes

  1. Semicolons are interpreted as command terminators.
  2. Whitespace is ignored.
  3. The interpreter stops reading a line after it gets to a valid command, so "GBLhuyt" would still be valid, as it reaches "GBL" before "huyt".
  4. Strings cannot contain ", ' or ;. Escape these characters.
  5. The interpreter has been broken from one big function into several smaller ones.
  6. There is a syntax change in FORK and BREED. Look at the commands to find the new syntax.

Examples

Basic Hello World

GBL;
Bug("1", "Hello, World!");
Scuttle("1");
Write;

CAT Program

GBL;

Bug("1", "");
Bug("2", "");
Bug("3", "");

:CAT_Loop
Listen("2");

Fork("2" == "3");
     Scuttle("1");
     Write;
     End;
EndFork;

Breed("1" + "2");
Goto CAT_Loop;

Most Simple Quine Possible

GBL;
Quine;

99 Bottles of Winkles Old Peculiar

GBL;

Bug("1", "99");
Bug("2", "0");
Bug("3", "0.5");
Bug("4", "There are ");
Bug("5", " bottles of Winkles Old Peculiar, sitting on a wall.");
Bug("6", " bottles of Winkles Old Peculiar.");
Bug("7", "Take one down, pass it to Vimes,");

:Loop

Bug("Line_1", "");
Breed("Line_1" + "4");
Breed("Line_1" + "1");
Breed("Line_1" + "5");

Bug("Line_2", "");
Breed("Line_2" + "1");
Breed("Line_2" + "6");

Bug("Line_3", "");
Breed("Line_3" + "7");

Scuttle("Line_1");
Write;
Return;

Scuttle("Line_2");
Write;
Return;

Scuttle("Line_3");
Write;
Return;

# This statement is executed twice for some reason, thats why Bug 3 is set to 0.5, instead of 1.
# If you can find the problem, and tell me, i'll be happy.
Breed("1" - "3");

Fork("1" < "2"):
     End;
EndFork;

Goto Loop;

External resources

Interpreter

Specifications