2 Reference
~karx edited this page 1 year ago

This is the reference for sandwich's language features.


sandwich is comprised of opcodes. The syntax looks like this:


The currently available opcodes are as follows:

  • p - print out the arguments
    • pHello World! will print out Hello World!.
  • a, s, m, d - add, subtract, multiply, and divide, respectively
    • the arguments look like the following:
    • <num1>-<num2>
    • For example: a10-10 will print out 20.
    • the dash in the middle is a separator between the two input numbers.
    • These opcodes will error out if either of the arguments is not a number.
  • l - declare a variable
    • <variable name><variable value>
    • the name of the variable must be only 1 character
    • the value can be any length.
    • if the first character of the value is a <, sandwich will grab input from the user, using everything after the < as a prompt.
    • For example, if your code says ln<Enter your name: , sandwich will prompt the user with Enter your name: and wait for the user to input.
    • Then, it will assign the inputted text to the variable n.
    • Note:
      • To use a variable, use the $ character.
      • For example, p$v will print out the value of variable v.
      • If w is set to World, pHello, $w! will print out Hello, World!
      • Two variables cannot share the same name. If you try to redeclare a variable, the old value will be overwritten.
  • f - declare a function
    • The arguments are the same as declaring a variable.
    • the body of the function has to be one of the math operators.
    • Note:
      • To use a variable, use the * character.
      • For example, p*f will print out the result of function f.
      • Functions will only get evaluated when they're called.
      • This means, if you use variable v in a function, but v gets redefined between the function declaration and when you use it, the function will use the new value of v, and not the value from when the function was defined.
      • Also, functions are re-evaluated for each call.
      • This means that if the function depend on an outside variable and the variable changes frequently, the result of the function will also change frequently.
      • Like variables, two functions cannot share the same name. If you try to redeclare a function, the old function will get overwritten.
  • i - import variables and functions from another file
    • The arguments look like the following:
    • <filename>[-optional-list-of-functions-or-variables-to-import]
    • the list of values should be separated by a -. Each value should have the following syntax:
    • <f or v, function or variable, respectively><name of function/variable>


You can use a # character to create a comment. It works anywhere in the line, but everything after the # will be ignored by the interpreter.

For example:

pHello World!

# This line will be ignored

pThis part will be printed # and this part will not be printed

Example Program

Here's an example program that shows all of these concepts in action:

# prints hello world
p$h $w
p$h $w


p*x *y

ptest # Prints test


ln<Enter your name: 
pYour name is $n.

lo<Enter the first number: 
lt<Enter the second number: 

pThe result is *a