Smu

From Esolang
Jump to navigation Jump to search

Smu is an esoteric programming language by User:Zzo38 based on Smurf, with some minimalization based on what is written in Talk:Smurf.

Commands

  • () Push a string to the stack. The string is whatever is inside the parentheses, you can have nested parentheses but it must be nested correctly. Only the characters ()=|+ can be inside a string, other characters are ignored or are processed by the preprocessor.
  • = Pops two strings from the stack, and sets the variable with the name specified by the first string (the top value) to the value specified by the second string. Does nothing if not enough strings on the stack.
  • | Splits a string into a head and a tail and pushes them onto the stack (tail first, the head will then be at the top of the stack). If the string is empty then it will pop it from the stack without pushing anything. Does nothing if stack is empty.
  • + Pops two variable names from the top of the stack and joins their values. Value at top is the name of variable which is the value at end of the string, second from top is the beginning of result string. Does nothing if not enough strings on the stack.

Macros

Macros can be used in the preprocessor.

  • & Indicates a comment until the end of the line.
  • Spaces and new-lines are removed during preprocessing.

To define macro, you put the name of macro, which is zero or more digits followed by exactly one uppercase or lowercase letter. And then the definition of macro, followed by the name of the macro again. Macros must be defined before used. To use a macro, just put the name of macro. You cannot define a macro inside of another macro.

Program Running

At the beginning running the program, initialize the stack with one string indicating input bit, | for 0 and + for 1 and = if no input.

At the end of the program, if there is a string on the stack, pop and output it (in order, | outputs bit 0 and + outputs bit 1 and = means to wait for more input unless EOF), and then if there is another string on the stack, pop it and use that as the program to now execute (including pushing the input at the start of running the program). Variables, and the rest of the stack, is kept across running the program multiple times.

Conversion

Assume definitions of x, y, z are defined as pushing a string, each one must be unique and non-empty, and becomes the name of the variable.

  • q becomes (())|x=y=z=xz+z=zy+ please note that it require balance parentheses otherwise the result will not execute correctly
  • h becomes |x=y=x()+
  • t becomes |x=
  • g becomes ()+

Or, in other words:

  • h becomes ty=xg

Examples

Program to copy input to output:

x(+|)xg()+gy(g)ybx=(=)y=xy+x=ba(bxggxg)aa(|=)=a(+=)=baxg

Expanded form of this program:

((+|)=(=)(()+)=(+|)(()+)+(+|)=(+|)()+()+(+|)()+)(|=)=((+|)=(=)(()+)=(+|)(()+)+(+|)=(+|)()+()+(+|)()+)(+=)(+|)=(=)(()+)=(+|)(()+)+(+|)=((+|)=(=)(()+)=(+|)(()+)+(+|)=(+|)()+()+(+|)()+)(+|)()+