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.


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.


Hello, world!




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.


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

Cat program