HARSH

From Esolang
Jump to navigation Jump to search

HARSH is a programming language made in order to test its creator's ability to do memory allocation. It has 13 commands, an accumulator, and a stack.

Language Overview

Command Number Command Name Command Name
1 a Increment accumulator
2 d Double the accumulator
3 o Set accumulator to 0
4 u Push accumulator onto stack (doesn't change the accumulator's value)
5 p Pop from stack into the accumulator
6 r Rotate stack moves the first stack value to the end of the stack
7 h If accumulator is 30, jump ahead a character
8 q Ask the user if the command following should be executed, in the form of a yes or no question. If the user answers yes, run it, otherwise, jump one command
9 b Jump backwards x characters, where x is the value stored in the accumulator. (If the program attempts to jump past the first character, it will simply jump to the first character instead)
10 c Print the accumulator as an ASCII character
11 n Output the accumulator as a number
12 e Exit the program
N/A z Execute the command indicated by the accumulator (i.e. if the accumulator was 9 it would execute 'b', the 9th command)

HARSH is a very simple language. Not necessarily trivial, but there aren't that many moving parts to contend with. In HARSH, like many esolangs before it, each instruction is only one character, and the instruction pointer moves along one step at a time (mostly). For data storage, there's the accumulator, used for working data, and the stack for storing values.

HARSH was designed with two primary design goals in mind: making arithmetic difficult to perform, and making control flow a nightmare to structure. On the arithmetic side of things, HARSH has only two instructions for manipulating the value stored in the accumulator. 'a', which will increase the value of the accumulator by 1, and 'd', which will double the value stored in the accumulator. Performing more complicated math is left up to the user. For control flow, we have five instructions. 'b' is the most useful of the four, allowing the instruction pointer to jump backwards to an arbitrary point in the program. It's only weakness is that when control flow reaches 'b' it can only be sent backwards. If the accumulator happens to be 0, the instruction pointer simply sits at the 'b' until the program is killed. As a way to remedy this, 'q' and 'h' both allow for forwards jumps, but only one character at a time. 'h' will only trigger if the value in the accumulator is 30, and 'q' doubles as the only form of user input, querying the user if the instruction directly following it should be skipped. Rounding out the control flow instructions, we have 'e' and 'z'. 'e' isn't terribly useful most of the time, but can occasionally come in handy for halting a program early in addition to halting it at the end. 'z' is likely the least generally useful of all HARSH instructions, but can serve as a space-efficient alternative to 'h' in some cases, simplifying complex chains of logic. Slightly less annoying are arbitrary variable access and output. For memory manipulation HARSH has four instructions: 'o', 'u', 'p', and 'r'. 'o' simply resets the accumulator to its initial value of 0, very useful to do after a push to the stack with 'p'. 'p' will push the current value stored in the accumulator on the stack, but will also preserve the accumulator while doing so, which can be a useful property. Thus, if the current value of the accumulator is 42, executing 'p' would push a 42 onto the stack and the accumulator would remain 42. Popping with 'u' preserves nothing, however, simply taking the first out value of the stack, storing it in the accumulator and removing it from the stack. Finally, to make accessing values in the middle of the stack without destroying the values before them, 'r' will "rotate" the stack, taking the first out value and putting on the end. thus a stack containing 2, then 3, then 7 would become 3, then 7, then 2. And finally there are two instructions used for output, 'n' and 'c'. Both will simply output the current value of the accumulator to stdout, with 'n' formatting the value as a number and 'c' formatting it as a character.

Example programs

Hello World:

aaaaaaaaadddcoaadddaddacaaaaaaaccaaacoaaddddcdaaaaaaaaaaaaaaaaaaaaaaacoaaaaaaaaadddaaaaaaacaaacoaaaaaaaaadddaaaacoaadddaddce

Simple hello world program.

Hello World 2:

adddddudaaaauauaaauaaaauaaauaaauaaaaaurrrrpcpcrrrrrpucpucrrrrrpucrrrpcpcrpcrrpcpcpce

Smaller hello world program that takes greater advantage of the stack.

Truth-Machine:

auuoqpnaaaaaaddaahepnb

External Resources

Find an Interpreter and some example programs HERE