Surtic

From Esolang
Jump to navigation Jump to search

Surtic ("Sir Chick") is an esoteric programming language created by User:Digital Hunter with help from User:Galaxtone.

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

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.

Surtic supports basic logic flow structures and traditional operations, but creative solutions must be used for basic maths operations (examples demonstrating this at the bottom of the page).

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

There's no official way to write in comments, but {}{ example text here } may be used. Essentially, the first else block ensures that no other logic blocks will be run until a new if block, so the text within the second pair of brackets will be ignored. Being careful, all comments that come afterward can be written within an independent block.

Instruction Syntax

All letters are case-insensitive (you can use capital and lowercase interchangeably).

# refers to any whole number.

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

<cell> refers to C# for referencing a number variable, # must be greater than or equal to 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).

'...' 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. Surtic does not use double quotes.

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>(<cell>:<cell>) Generate a random integer between the lesser of the values of the two cells in parentheses with the greater of the two values (inclusive) and store this integer in the first 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 2nd referenced cell variable to the 1st 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

Note: Nothing requires that an if code block must be written together (there can be else-ifs and elses dispersed throughout a program after their parent if block)

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.

Example Programs

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]]]

Deadfish Interpreter

s0'diissisdo'c9-c10++++fc10[fc10[c10++]]c8++++++++++fc8[fc8[c3+c4+c5+c6+]c10+++c5+c6+]fc8[c8-]c3+++++fc4[c10-]c10++c6+c5+++++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