Surtic

From Esolang
Jump to: navigation, search

Surtic (pronounced either "sour tick" or just "sertik") is an esoteric programming language created by User:Digital Hunter.

Originally based off of Brainfuck, with some major ideas contributed by User:Galaxtone, along with a "rebirth" of Surtic to be "easier."

Feel free to provide feedback or suggestions on the talk page.

Beware that the language can change at any minute, so people writing interpreters should update every so often.

The Language

There are three variable groups for holding information (Group C, S or B)

Whitespace is ignored for instructions, but must be preserved within strings.

If an invalid instruction sequence is encountered, then an error is thrown at your face through the screen.

Instruction Syntax

All letters are case-insensitive.

# refers to any whole number.

{...} refers to one or more of something.

<ref> refers to R# for referencing a variable in any of the four variable groups, # must be greater than zero.

<cell> refers to C# for referencing a number variable or C<ref> for referencing a cell variable using another cell variable, # must be greater than zero.

<bool> is the same as <cell> except for boolean variables (1s and 0s).

<str> is the same as <cell> except for string variables ('word's and 'bird's).

<equality> refers to == for equal to or != for not equal to.

<comparison> refers to < for less than, > for greater than, <= for less than or equal to, >= for greater than or equal to, or <equality>.

<bool comparison> refers to & for AND (If both booleans are true), | for OR (If either boolean is true), ^ for XOR (If both booleans aren't true or false).

"..." or '...' refers to an ASCII string value, containing any characters, using \ to escape characters, you cannot have have a string across multiple lines, newlines must be escaped using \n.

Escape Sequences

Sequence Value
\" "
\' '
\\ \
\n The ASCII character for newline. (10)

Variable Groups

C

Cell variable group, Each variable contains an unbounded integer, with the default value of zero.

An error should be thrown if a cell is used as a reference with a value less than one.

Instruction Description
<cell>{+} Increment the referenced cell variable by the number of plus symbols.
<cell>{-} Decrement the referenced cell variable by the number of hyphen symbols.
I<cell> Take a UTF-8 character from input and store in the referenced cell variable as a number. (Only the character shall be written to standard output followed by newline.)
O<cell> Take the number in the referenced cell variable (Mod 65536) and output it as a character. (Only the character shall be written to standard output.)
NI<cell> Take a number from input and store in the referenced cell variable. (Input shall be written to standard output as numbers are typed and deleted, followed by a newline.)
NO<cell> Take the number in the referenced cell variable and output it. (Only the number shall be written to standard output.)
R<cell>(#:#) Generate a random number between the minimum of the two numbers and the maximum of the two numbers (inclusive) and store it in the referenced cell.
J<cell> Take the number in the referenced cell variable and jump execution ahead by that number of statements. (Program will halt if you jump outside of the program.)

B

Boolean variable group, Each variable contains a boolean value (either true or false), with the default value of false.

Instruction Description
!<bool> Invert the referenced boolean variable.
?<bool>(<cell><comparison><cell>) Compare the 1st referenced cell variable and 2nd referneced cell variable and store the result in the referenced boolean variable.
?<bool>(<str><equality><str>) Compare the 1st referenced string variable and 2nd referenced string variable and store the result in the referenced boolean variable.
?<bool>(<bool><bool comparison><bool>) Compare the 2nd referenced boolean variable and 3rd referenced boolean variable and store the result in the 1st referenced boolean variable.

S

String variable group, Each variable contains a UTF-8 string value, with the default value of an empty string.

Instruction Description
K<str>:<str> Concatenate the 2nd referenced string variable to the end of the 1st referenced string variable and store it in the 1st referenced string variable.
<str>"..." Stores the string value within the referenced string variable.
I<str> Take in a string value from input and store it in the referenced string variable. (Input shall be written to standard output followed the rules for displaying unicode characters as shown in "..." as characters are typed and deleted, followed by a newline afterwards.)
O<str> Take the string value in the referenced string variable and output it. (Only the characters of the string are written to standard output.)
L<cell>:<str> Set the referenced cell variable to the length of the referenced string variable.
G<cell>:<str>(<cell>) Set the 1st referenced cell variable to the character value of the character at index of the 2nd referenced cell variable from the referenced string variable. (If the index is not within the range from 1 to the length of referenced string variable then -1 is used instead.)
P<cell>:<str>(<cell>) Set the character from the referenced string variable at the index of the 1st referenced cell variable to the 2nd referenced cell variable. (If the index is not within the range from 1 to the length of the referenced string variable then nothing shall happen,
The value to set will be modded by 65536 within the UTF-8 range.)

Statements

Loop Statements

Instruction Description
F<cell>[ Take the number in the referenced cell variable and execute the code within the block that many times. (Does not do anything if the number is less than or equal to zero)
W<cell>[ Take the number in the referenced cell variable and execute the code within the block until the number is less than or equal to zero.
W<bool>[ Execute the code within the block until the referenced boolean variable is false.
] Represent the end of a loop code block.

If Statements

Instruction Description
I<bool>{ If the referenced boolean variable is true then execute the code within the block.
}<bool>{ If previous if statements have failed and the referenced boolean variable is true then execute the code within the block.
}{ If previous if statements have failed then execute the code within the block.
} Represent the end of an if code block.

Examples

Some of these examples are untested; if you are making the first interpreter, please test whether they work.

Hello, world!

S1"Hello, world!\n"OS1

Infinite Cat

S1"\n"!B1WB1[IS2OS2OS1]

Fibonacci sequence

C1+C2+!B1WB1[NOC1FC2[C3+]FC1[C1-C2+]FC3[C3-C1+]]

Factorial

S1"Factorial: "S2"Factorial of "S3" is "S4".\n"OS1NIC1C1-C2+FC1[C3+FC2[FC3[C2+]]]OS2C1+NOC1OS3NOC2OS4

99 bottles of beer

S1" bottle"S2"s"S3" of beer"S4" on the wall"S5","S6"\n"S7"."S8"Take one down, pass it around"S9"No"S10"Go to the store, buy some more"C1+++++FC1[C1++++]FC1[C1+++]C1-FC1[C2+]C3++!B1WB1[NOC1OS1OS2OS3OS4OS5OS6NOC1OS1OS2OS3OS7OS6OS8OS5OS6C1-NOC1OS1OS2OS3OS4OS7OS6OS6?B1(C1>C3)]NOC1OS1OS2OS3OS4OS5OS6NOC1OS1OS2OS3OS7OS6OS8OS5OS6C1-NOC1OS1OS3OS4OS7OS6OS6NOC1OS1OS3OS4OS5OS6NOC1OS1OS3OS7OS6OS8OS5OS6OS9OS1OS2OS3OS4OS7OS6OS6OS9OS1OS2OS3OS4OS5OS6OS9OS1OS2OS3OS7OS6OS10OS5OS6NOC2OS1OS2OS3OS4OS7OS6

Truth-machine

S1"\n"C1++++++++FC1[C1+++++]FC1[C2+]C2+!B1WB1[IC3?B2(C3==C1)?B3(C3==C2)IB2{OC3OS1!B1}B3[WB1[OC3OS1]]]

Add two numbers

S1"Number #"S2": "S3" + "S4" = "S5"\n"C1+OS1NOC1OS2NIC2C1+OS1NOC1OS2NIC3FC2[C4+]FC3[C4+]NOC2OS3NOC3OS4NOC4OS5

Subtract two numbers

S1"Number #"S2": "S3" - "S4" = "S5"\n"C1+OS1NOC1OS2NIC2C1+OS1NOC1OS2NIC3FC2[C4+]FC3[C4-]NOC2OS3NOC3OS4NOC4OS5

Multiply two numbers

S1"Number #"S2": "S3" * "S4" = "S5"-"S6"\n"C1+OS1NOC1OS2NIC2C1+OS1NOC1OS2NIC3C1--?B1(C2<C1)IB1{!B2WB2[C2+C4+?B2(C2<C1)]FC4[C2+C4-]}?B2(C3<C1)IB2{!B3WB3[C3+C4+?B3(C3<C1)]FC4[C3+C4-]}?B1(B1^B2)?B2(C2=C1)?B3(C3=C1)?B2(B2|B3)!B2?B1(B1&B2)IB2{C3-FC2[C4+]FC4[FC3[C4+]]C3+}NOC2OS3NOC3OS4IB1{OS5}NOC4OS6

Divide two numbers

S1"Number #"S2": "S3" / "S4" = "S5"-"S6"NaN"S7"\n"C1+OS1NOC1OS2NIC2C1+OS1NOC1OS2NIC3C1--?B1(C2<C1)IB1{!B2WB2[C2+C4+?B2(C2<C1)]FC4[C2+C4-]}?B2(C3<C1)IB2{!B3WB3[C3+C4+?B3(C3<C1)]FC4[C3+C4-]}?B1(B1^B2)?B2(C2=C1)?B3(C3=C1)?B2(B2|B3)!B2?B1(B1&B2)IB2{FC2[C5+]WC5[FC3[C5-]C4+]?B3(C5<C1)WB3[C5+?B3(C5<C1)]C4-}NOC2OS3NOC3OS4IB1{OS5}IB3{OS6}{NOC4}OS7