LRIP

From Esolang
Jump to navigation Jump to search

LRIP is a stack-based esolang created by user:Lebster

Commands

Command Explanation
L Bitshift top of stack to the left
R Bitshift top of stack to the right
I Increment top of stack by 1
P Print top of stack as ASCII
+ Push 0 to top of stack
- Pop from top of stack
k Push user input ASCII code to top of stack
( Start loop
) End loop

Examples

Hello world

ILLLILLLP+ILILLLILLIP+ILILLILILLPP+ILILLILILILIP+ILLLLLP+ILILILLILILIP+ILILLILILILIP+ILILILLLILP+ILILLILILLP+ILILLLILLP

Alphabet

ILLLLLLIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIPIP

Implementations

Python Interpreter

import sys
if len(sys.argv) != 2: print('Please input a file name')
else:
	filename = sys.argv[1].lstrip()
	with open(filename, 'r') as file: program = list(file.read().replace('\n', '').lower())
	stack = [0]
	pos = -1
	while pos < len(program) - 1:
		pos += 1;
		char = program[pos]
		if char == 'l': stack[0] = stack[0] << 1
		elif char == 'r': stack[0] = stack[0] >> 1
		elif char == 'i': stack[0] += 1
		elif char == 'p': print(chr(stack[0]), end='')
		elif char == '+': stack.insert(0, 0)
		elif char == '-':
			stack.pop(0)
			if not stack: stack=[0]
		elif char == 'k': stack.insert(0, ord(input('? ')))
		elif char == '(':
			if stack[0] == 0:
				opened = 0;
				pos += 1
				while pos < len(program):
					if program[pos] == ')' and opened == 0: break
					elif program[pos] == '(': opened += 1
					elif program[pos] == ')': opened -= 1
					pos += 1
		elif char == ')':
			if stack[0] != 0:
				closed = 0;
				pos -= 1
				while pos >= 0:
					if program[pos] =='(' and closed == 0: break
					elif program[pos] == ')': closed += 1
					elif program[pos] == '(': closed -= 1
					pos -= 1

Usage

LRIP.py <file name>

Online

Try it online!