Sloop

From Esolang
Jump to navigation Jump to search

Sloop is an esoteric programming language by TheJonyMyster. It features variables, looping, and not much else.

Structure and Syntax

A syntactically valid program is a list of variable names, each followed by a list of commands and loops. All whitespace is ignored and stripped from the program, so it's as if it were never there to begin with.

Variables

A valid variable name is a string of consecutive characters that are non-whitespace and not in the following list:

[]()<>{}+-0123456789

A valid implementation is allowed to limit valid characters further, but there should always be at least one character reserved for naming variables.

Commands and loops

Immediately after the variable name comes a list of commands and loop structures.

A valid command is a non-empty string consisting of either zero or one of these characters:

+-

Followed by zero or more digit characters:

0123456789

Do note that commands are parsed greedily, so

+0001

will always parse as a single command

A valid loop structure is a string beginning with any member of this list:

[(<{

Followed by any amount of syntactically valid code, and terminating with any member of this list:

])>}

Do note that brace types do not need to match for your code to be valid. If you don't understand why, don't even trip. It's all in good hands, baby.

Examples

The following examples are invalid:

+abc
{abc+}def

The above programs do not start with a variable

abc{+def}
abc{{abc+}def}

The above programs both contain a loop containing syntactically invalid code, because the loop does not start with a variable.

abc{def
abc{def{}
abc}

The above programs all contain mismatched / unmatched brackets, but honestly if your parser can make sense of it and discard excess... we can just call this "undefined behavior" and move on with our lives.

The following example is VALID:

abc+-def10ghi( a b@#$""" c + - d 
         E f 1 0 g h i { a + - ]
{} + - >10+10

Tokenized (approximately) like this:

Variable: abc, Command: +, Command: -;
Variable: def, Command: 10;
Variable: ghi, Loop: {
     Variable: ab@#$"""c, Command: +, Command: -;
     Variable: dEf, Command: 10;
     Variable: ghi, Loop: {
          Variable: a, Command: +, Command: -;
     }, Command: +, Command: -, Loop: {};
}, Command: 10, Command: +10;

Execution

Variables contain an integer value initialized at 0. The commands and loops following each variable "refer" to them, and their actions depend on or modify that variable, clarified below. Commands and loops are executed sequentially.

Commands

Any command not starting with a - will increase the variable being referred to by the specified amount in decimal base, or by just 1 if only a + exists and no digits are included.

Conversely, a command starting with a - will decrease the variable being referred to by the specified amount in decimal base, or by just 1 if only a - exists and no digits are included.

Non comprehensive examples:

A+ B2 C+++ D+3+ E+005 F3-5+++++--- G- H-1 I--1 J-2-1 K0 L-0 M+00000000000 N+-1

This program will leave the variables with the following values:

A:  1
B:  2
C:  3
D:  4
E:  5
F:  0
G: -1
H: -2
J: -3
K:  0
L:  0
M:  0
N:  0

Loops

Loops are tied to the variable they refer to, and are of the "While" variety. Specifically, when a loop is initiated, the variable being referred to will have its value checked. If the value is 0, the loop will be skipped. If the value is nonzero, execution will continue into the loop, and all code within the braces/bounds of the loop will be executed sequentially.

At the end of the loop, if the referred to variable has a value of 0, execution will exit the loop. If the value is nonzero, execution will return to the beginning of the loop, and all code within the loop will be executed again, etc. etc. etc.

Non comprehensive examples:

A {A1 } 3 {A- B-5 } B {C2 B+} {B+}

In this program, a loop is initiated on variable A which immediately ends as A's value is 0.

Then, A's value increases by 3, and another loop is initiated. This time, the loop runs three times, and A is lowered back to 0 while B is reduced to -15.

Finally, a loop is initiated on variable B which runs 15 times as B's value is raised back to 0, and C is raised to 30. Another loop on B is initiated, but again immediately ends as B is already 0.

A13 {B+ C- A-2}

This program does not halt, as once the loop on A is entered, A never reaches 0.

I/O

By default, there is no input or output to this language, though a good implementation should include a debug flag or something to allow you to at least view the variable values at the end of computation (or possibly even during).

I/O extensions

A few potential non-invasive extensions could be to add additional commands which take input / output on the variable being referred to per ASCII character code. For example, we could borrow from brainfuck:

,.

For input and output respectively.

You might then, for example, consider this to be a valid Hello User program:

h072. e101. l108.. o111. c044. s032. U,[U.,]

Implementation

This language is currently not (properly) implemented anywhere because TheJonyMyster is bad at programming !! (I'll figure it out eventually...)