HASSL

From Esolang
Jump to navigation Jump to search
HASSL
Paradigm(s) Imperative
Designed by Ethan T. Stanger
Appeared in 2022
Memory system Stack-Based
Dimensions One-Dimensional
Computational class Unknown
Reference implementation HASSL
File extension(s) .hassl

HASSL (Hexadecimal, ASCII, Symbolic, and Stack-Based Language) is a stack-based esoteric programming language created in 2022 by Ethan T. Stanger with the simple goal of being a hassle (get it?) to write larger programs in.

Language summary

HASSL programs begin by defining a number of states. These states can be any of the single hexadecimal digits (0-9, A-F), and can be written anywhere in the program. Execution starts with the first 0 found in the program, and from there on commands are run one character at a time.

A complete list of the commands in HASSL
Command Action
0-9, A-F Define a state
$ Select the state equal to the value of the currently selected cell
& Go to the next definition of the currently selected state
| Go to the beginning of the program
v Push a value to the stack
^ Pop a value from the stack
s Swap the top two values of the stack
d Duplicate the top value of the stack
i Invert the order of the stack
r Roll the stack once (top to bottom)
+ Push the sum of the top two values of the stack to the stack
- Push the difference of the top two values of the stack to the stack
( Select the left cell
) Select the right cell
* Increment the value of the currently selected cell
. Set the value of the currently selected cell to NULL
~ Set the value of the currently selected cell to a random value
? Continue if the value of the currently selected cell is not 0
! Continue if the value of the currently selected cell is 0
p Print the ASCII character associated with the value of the two cells
n Print the numeric value of the two cells in base-10
g Wait for input from the user and push each character to the stack
# Set the value of both cells to the number of elements in the stack
@ Terminate the program

Aside from these commands, you can also write comments by enclosing a block of text in two percent signs (like " % ... % "), and you can alter the control flow of the program by using "control paths," which you write by enclosing a block of code with either two square brackets (like " [ ... ] ") or with a greater-than and less-than sign (like " > ... < "). If the '[' symbol is read during program execution, the interpreter will skip to the next ']' found in the program. Likewise, when a '<' symbol is read during execution, the interpreter will step backwards through the program until a '>' symbol is hit, at which point execution will continue. In normal execution, ']' and '>' symbols are ignored. All whitespace and the colon ':' symbol are also ignored.

Example programs

This is a basic Hello World implementation in HASSL (the new-lines are added for the sake of formatting and are not necessary for execution):

0:
     ********(****)p*****(******)p************(******)p
     ************(******)p***************(******)p(**)p
     *******(*****)p***************(******)p**(*******)p
     ************(******)p****(******)p*(**)pg@

This is a basic Cat implementation in HASSL. As it is more complex, this rendition includes commenting and more formatting. Aside from demonstrating basing input and output, this program also demonstrates more complex usage of the HASSL states, including definitions for states 0-4:

0:   % put user input on the stack and inverse the stack %
     gi*$.
1:   % check if the right register is not zero, and if so, move to state 3, otherwise move to state 2 %
     **$#?.***$.&
2:   % check if the left register is not zero, and if so, decrement it, and decrement the right register before moving to state 3, else, go to state 4 %
     ****$.(?***************)*$.***************
3:   % print the first thing on the stack and go to state 1 %
     ^p*$.&
4:   % get user input and exit the program %
     g@