Lightlang

From Esolang
Jump to navigation Jump to search
This article is a stub, which means that it is not detailed enough and needs to be expanded. Please help us by adding some more information.

Lightlang is an esoteric programming language designed by User:Felixcesar15 that only uses 1 bit as main memory. (infact it was designed in 1 hour!)

Instructions

Each character is an instruction (like brainfuck) (Note:any invaild instruction is ignored so you can comment your hardworked code)

  •  ! - Toggle the bit.
  • . - Print the state of the bit. (As 0 and 1)
  • . , - Ask for input, if it's nothing, turn the bit on, otherwise turn the bit off.
  • & - Set the bit to random state.
  • @ - If the bit is on, don't read the next instruction, otherwise do nothing.
  • $ - Read the next instruction 2 times.(can be stacked)
  • - - Halt the program. (why tho)
  • / - Reverse the direction of the instruction pointer.
  • > - Jump to the next instruction of the nearest < if the bit is off.
  • < - Jump to the next instruction of the nearest > if the bit is on.
  •  % - Jump to the start of the program.
  • _ - Sleep for 1 second.

Examples

This will enter an infinite loop

%

This will print the bit, toggle it then repeat

.!%

Same as above but it has delaying

.!_%

This will print 0 if the input is nothing (Repeating)

,.%

Implementations

Python (by User:Felixcesar15)

Note from implementor: This interpreter has rushed so it has no debugging features and instructions > and < are not implementated (this may improve tho)

Bugs found so far:

Stacking $ will trigger an error
import random
import time
class Program:
 def __init__(self):
  self.bit = False
  self.ptr = 0
  self.reversed = False
  self.instructions_map = {
  '!': self.toggle,
  '.': self.print,
  ',': self.input,
  '&': self.random,
  '@': self.condition,
  '$': self.repeat,
  '-': self.halt,
  '/': self.reverse,
  #'>': self.jump_forward, <- TODO
  #'<': self.jump_backward, <- TODO
  '%': self.jump_to_start,
  '_': self.sleep,
  }
 def toggle(self):
  """!"""
  self.bit = False if self.bit == True else True
 def print(self):
  """."""
  print(0 if self.bit == False else 1)
 def input(self):
  ""","""
  self.bit = False if input() == "" else True
 def random(self):
  """&"""
  self.bit = False if random.randint(0, 1) == 0 else True
 def condition(self):
  """@"""
  if self.bit == True:
   self.ptr += 1
 def repeat(self):
  """$"""
  self.execute(code[self.ptr + 1])
 def halt(self):
  """-"""
  self.halted = True
 def reverse(self):
  """/"""
  self.reversed = False if self.reversed == True else True
 def jump_to_start(self):
  """%"""
  self.ptr = -1
 def sleep(self):
  """_"""
  time.sleep(1)
 def execute(self, instruction):
  """Executes a single instruction"""
  #print(instruction)
  if instruction not in self.instructions_map: return
  self.instructions_map[instruction]()
 def interpret(self, code):
  while self.ptr <= len(code) - 1 and self.ptr >= 0:
   #print(self.ptr)
   self.execute(code[self.ptr])
   self.ptr += 1 if self.reversed == False else -1
def run(code):
 #print(code)
 interpreter = Program()
 interpreter.interpret(code)
 print("\n[Program ended]")
if __name__ == "__main__":
 file = open(input("Type the path of your code:\n"))
 code = file.read()
 file.close()
 run(code)