Left-Right March

From Esolang
Jump to navigation Jump to search

Left‐Right March is an esoteric programming language created by User:DigitalDetective47. It works by having a pointer moving across the program, executing instructions as it goes. It canonically uses the extension .lrm for scripts.

Program structure

When a program starts, the first line of the source code is converted into a field of cells. Everything after the first line break is treated as a comment. There is an accumulator (A), which can hold a value between 0 and 99. Any operation that would cause A to be outside of this range will have its result stored modulo 100 so that it will fit. It uses LSCEF to encode and decode characters. If a program attempts to decode a value of 98 or 99, it throws an error. The pointer is placed on the leftmost cell of the field, facing right. It then enters into a loop of executing the cell that it is on and then moving one cell in the direction that it is facing. If the pointer leaves the field, either through its natural movement or through a jump command, the program terminates with no errors. If an error ever occurs, the program immediately halts and a (preferably descriptive) error message is printed.

Commands

If the command to be executed is a digit, it immediately returns (acts as an NOP). If the command is not a digit, then a two‐digit number is read immediately after it in the direction of the pointer and stored in F. (Example: 34c12 will execute the c instruction with an argument of 12 when the pointer passes from left to right, and will execute the c instruction with an argument of 34 when the pointer passes from right to left.) Single‐digit values must have a leading zero added to them. If the two characters after the command do not form a valid number, an error is thrown. Then, the command is interpreted using the following table:

All commands
Command Name Description
a Add Stores the result of A+F in A.
b Branch Moves the pointer forward F cells if A≠0.
c Copy Stores F in A.
d Divide Stores the result of A//F (Integer division) in A, throwing an error if F=0.
e Extend Inserts a cell containing the character specified by A to the program F spaces ahead of the pointer. If the location indicated by F is beyond the edge of the program, the character is placed at the edge of the program.
i Input Gets a character from the input and stores its value into A. If the input stream is exhausted, return 99.
j Jump Moves the pointer forward F cells.
l Left Makes the pointer face left.
m Multiply Stores the result of A×F in A.
p Print Prints the character corresponding to A.
r Right Makes the pointer face right.
s Subtract Stores the result of A−F in A.
w Write Stores A in F.

If the command read is not present in the table, the program throws an error.

Examples

Hello, world!

c09p00c32p00c39p00p00c42p00c88p00c01p00c50p00c42p00c45p00c39p00c31p00c64p00

Truth-machine

i00s54b11c54p00j14c55r00p00l00

Text dump program generator

This program takes a string as input from the user and outputs the source code of a Left‐Right March program that will print the string given. It also optimizes strings with repeated letters by omitting unnecessary uses of the c command.

j03ri00a01b05j64s01j10r02j3800s98w00b10j9710j00a98w00l00r02j5200w00c30p05j02l75j79r00c000w00a54p00j26r02j2710d00w000a00j0900cl38jl00a54p00c43p00c54p00p73j02l00

(This program does not actually contain line breaks, it is simply too long to fit on one line)

Cat program

j03ri00a01b05j14s01p18j02l00

Implementations