app simply

Simply Script Interpreter

5 releases (3 breaking)

0.4.0 Jul 6, 2023
0.3.1 Jul 6, 2023
0.3.0 Jul 6, 2023
0.2.0 Sep 7, 2022
0.1.0 Sep 7, 2022

#1729 in Command line utilities

MIT license

23KB
459 lines

Simply Script

This project provides an interpreter for "simply script", a super-simple scripting language (inspired by Assembly) that is mostly used for coding puzzles.

Syntax

"simply script" supports the following commands:

Set Command

set |register| |value|

Sets the value (32-bit integer) of the indicated register. Register names can be any combination of letters, numbers, and underscore characters, but must start with a letter. This command essentially serves the purpose of assigning a value to a variable.

Copy Command

cpy |register 1| |register 2|

Copies the value from |register 1| to |register 2|.

Add Command

add |register 1| |register 2|

Adds the value stored in |register 1| to the value stored in |register 2|. Stores the final value in |register 2|.

Sub Command

sub |register 1| |register 2|

Subtracts the value stored in |register 1| from the value stored in |register 2|. Stores the final value in |register 2|.

Jump Command

jmp |register|

The next line to execute will be the line whose value is stored in |register|. Attempting to jump to a line number less than 1 will result in a NegativeExecutionPointer error.

Jump When Zero Command

jwz |register 1| |register 2|

Check the value in |register 1|. If that value is 0, continue execution at the line number stored in |register 2|. Otherwise, continue execution with the next line.

Jump When Negative Command

jwz |register 1| |register 2|

Check the value in |register 1|. If that value is less than 0, continue execution at the line number stored in |register 2|. Otherwise, continue execution with the next line.

Jump When Positive Command

jwz |register 1| |register 2|

Check the value in |register 1|. If that value is greater than 0, continue execution at the line number stored in |register 2|. Otherwise, continue execution with the next line.

Jump Not Zero Command

jnz |register 1| |register 2|

Check the value in |register 1|. If that value is not 0, continue execution at the line number stored in |register 2|. Otherwise, continue execution with the next line.

Greater Than Command

gth |register 1| |register 2|

If the value stored in |register 1| is greater than |register 2|, store 1 in |register 2|, otherwise, store -1 in |register 2|.

Less Than Command

lth |register 1| |register 2|

If the value stored in |register 1| is less than |register 2|, store 1 in |register 2|, otherwise, store -1 in |register 2|.

Output Command

out |register|

Print the value stored in |register| to standard out.

Character Command

chr |register|

Print the value stored in |register| to standard out as an ASCII character if the value is a valid ASCII character code. If the character does not represent a valid ASCII character code, prints a '·' character instead.

Usage

Just write your "simply script" into a text file (like "do_calculation.ok") and run the script with simply do_calculation.ok.

Examples

Countdown

Sets input value to num, then prints all values counting down from num to zero. If num is negative, then nothing is printed.

set num 25
set one 1
set A 9
set B 5
jwn num A
out num
sub one num
jmp B

Print Greater Number

Sets input values to num1 and num2, then identifies and returns the greater number. Just returns one of the numbers if they are equal. By convention, registers holding line numbers for jumps are named "Excel-style" using capital letters (A-Z, AA-ZZ, etc.).

set num1 18
set num2 15
set A 10
set B 11
cpy num2 compare
gth num1 compare
jwp compare A
out num2
jmp B
out num1

Dependencies

~4MB
~82K SLoC