Script Assembly Code

From Esolang
Jump to navigation Jump to search

Script Assembly Code is a low-level esolang. The code looks like actual “assembly code” but much simpler.

syntax

basic

Use %prt to print texts on the screen. Insert . at the beginning of the line to tell the interpreter execute the code on that line. Use \s to create a space character. Don’t add space randomly! This will result in an error. Example :

. %prt Hello\sWorld!         # this will be executed
%prt Hello!                  # this won’t be executed
.% prt hi hi hi  abc         # error

math calculation

Use %r %{code type} {input} {input2} to perform a calculation. Use prt function to show the result. ${n} means the result on line(n). code type can be :

  • +
  • -
  • *
  • /
  • m (mod function)

Some another examples:

%r %+ 4 78
. %prt $1        # prints 82. (4 + 78 on line 1)
%r %* 2 $1       # 2 + {result of line 1} 
. %prt $3        # prints 164. (2 * (4 + 78) on line 3 and 1)

stack

stack is a list of line to be executed. Use %c ={name} {[line list]} to create a stack.

%r %m 5 3
%prt $1
%prt Hi\sHi\sHi
. %c =mystack $2 $3

# stack named “mystack” created but didn’t execute by the interpreter.

control flow

Use control flow (syntax : %i %{type} {input} {input2} {when true stack} {optional: when false stack} ) to create If Else statement.

Type can be:

  • gt >
  • lt <
  • ge >=
  • le <=
  • eq ==
%r %- 67 66
%prt $1
. %c =anotherstack $2
%prt how?5<4?
. %c =s $4
. %i %gt 5 4 =anotherstack =s

# if (5>4), prints result of 67-66, else print “how?5<4?”

variables

Use %v %{action} *{variable name} {value} to create,set,change variable and it’s value. action can be :

  • n (create variable)
  • s (set variable value)
  • c (change variable value)
. %v %n *myvariable 123         
. %v %s *myvariable 122
. %v %c *myvariable 1


loops

Use %rp {stack} {repeat times} to create loop.

%prt repeating\s10\stimes
. %c =s $1
. %rp =s 10

Use %brk {brk out} to break out of an loop. brk out usually is 2.

. %v %n *i 0
%brk 2
. %c =one $2
%v %c *i 1
. %c =two $4
%i %ge *i 10 =one =two
. %c =ifelse $6
. %rp =ifelse 10000000000
. %prt finished!

Here’s an pseudo code of above program.

new variable i
set i to 0
repeat 10000000000 {
  if i >= 10 then
    break out to line after repeat
  else
    change i by 1
}
print "finished!"

semicolon

You may add ; after each line of code. This is optional, and for minify the code.

. %prt hi!
. %prt abc

Can become

. %prt hi! ;
. %prt abc ;

Or

. %prt hi! ; . %prt abc ;

import and export

There is some built in libraries for you to import. They will be explained later.

. #import string %wit _    # import string library, set it to _
# you may change _ to other single chars
. %prt _get 0 hihi  # prints h ("hihi"’s first char)

When you want to export things, you may add export.

. %prt hi!
. %c =c $1
. #export =c %wit custom     # export library named custom with stack

Libraries

You can import built in libraries. Here is some Doc. All {} is input that you can modify. (Their name is all lowercase, default import as _)

string

Import :

. #import string %wit _

Get char at index in string

. _get {index} {string}

Returns string.charAt(index-1)

Get count of substrings appear in strings

. _cnt {string} {substring}