Rogex

From Esolang
Jump to navigation Jump to search
Rogex Logo

Rogex (or RGX) is an esoteric programming language created by Lebster.

In Rogex, there is a 256 cell long memory, with hexadecimal addresses (eg ff = 255). There is also a buffer, which is the equivalent of one memory cell.

Operations

Structure

In Rogex, each command has a certain structure, which is as follows:

*1 ( First character,  essentially the command name )
*2 ( Second character, argument one of the command / first  digit of cell address )
*3 ( Third character,  argument two of the command / second digit of cell address )

Every command is formatted as such:

*1*2*3

EG:

A0F

Comments

Comments in Rogex can follow any of these formats:

[code] # comment (still comment)
[code] // comment (still comment)
[code] /* comment */ [code again]

Commands

The loop value, buffer and saved cell address all start as 0

*1 Operation *2 Explanation *3 Explanation
0 Get input to buffer 0 or 1 0 = As number or 1 = As ASCII 0-F 0 = Base 10 or 1 = Hex
1 Print buffer 0 or 1 0 = As number or 1 = As ASCII 0-F 0 = Base 10 or 1 = Hex
2 Print cell at saved address 0 or 1 0 = As number or 1 = As ASCII 0-F 0 = Base 10 or 1 = Hex
3 Add buffer to cell 0-F Cell address 0-F Cell address
4 Subtract buffer from cell 0-F Cell address 0-F Cell address
5 Multiply buffer by cell 0-F Cell address 0-F Cell address
6 Divide cell by buffer 0-F Cell address 0-F Cell address
7 Increment the buffer 0-F Hex number 0-F Hex number
8 Decrement the buffer 0-F Hex number 0-F Hex number
9 Set the buffer 0-F Hex number 0-F Hex number
A Print ASCII 0-F Hex ASCII value 0-F Hex ASCII value
B Set saved address 0-F Cell address 0-F Cell address
C Stop 0 Changes nothing 0 Changes nothing
D Set the loop value to the value of cell 0-F Cell address 0-F Cell address
E If the buffer is the loop value, jump to the corresponding F** in the program, otherwise do nothing 0 Changes nothing 0 Changes nothing
F If the buffer is not the loop value, jump to the corresponding E** in the program, otherwise do nothing 0 Changes nothing 0 Changes nothing

Implementations

Interpreter

Python interpreter:

import sys, re 
if len(sys.argv)<2: 
    print("""Usage: 
Rogex [-c] [filename] 
-c      : Interpret all following arguments as Rogex code and execute 
filename: Run filename as Rogex code 
""") 
    sys.exit(0) 
elif sys.argv[1]=="-c": 
    prg=.join(sys.argv[2:]).lower()   
else: 
    f = open(sys.argv[1], "r"); 
    prg = f.read().lower(); 
    f.close(); 
prg = (re.compile('#(?=.*).*|\/\/(?=.*).*|\/\*(.*)\*\/',re.IGNORECASE).sub("",prg)) 
prg = (re.compile('[^a-f0-9]*', re.IGNORECASE).sub("", prg)) 
mem=[0]*256 
prgPos=0 
buff=0 
sadr=0 
lval=0 

def prnt(s,a,b): 
    if a=='0': 
        if b=='0': 
            print(s,end=) 
        elif b=='1': 
            print(format(s,'x'),end=) 
    elif a=='1': 
        print(chr(s),end=) 

while prgPos<len(prg): 
    op=prg[prgPos]; 
    a1=prg[prgPos+1]; 
    a2=prg[prgPos+2]; 
    adr=int((a1+a2),16) 

    if op=='0': 
           if a1=='0': 
               # as base a2 
               if a2=='0': 
                   buff=int(input("Input Base 10 Number: ")) 
               elif a2=='1': 
                   buff=int(input("Input Base 16 Number: "),16) 
           elif a1=='1': 
               # as ASCII 
               buff=ord(input("Input character: ")) 
    elif op=='1': 
        prnt(buff,a1,a2) 
    elif op=='2': 
        prnt(mem[sadr],a1,a2) 
    elif op=='3': 
        mem[adr]+=buff 
    elif op=='4': 
        mem[adr]-=buff 
    elif op=='5': 
        mem[adr]*=buff 
    elif op=='6': 
        mem[adr]/=buff 
    elif op=='7': 
        buff+=adr 
    elif op=='8': 
        buff-=adr 
    elif op=='9': 
        buff=adr 
    elif op=='a': 
        print(chr(adr),end=) 
    elif op=='b': 
        sadr=adr 
    elif op=='c': 
        sys.exit(0) 
    elif op=='d': 
        lval=mem[int(str(adr),16)] 
    elif op=='e': 
        if buff == lval: 
            opened = 0 
            prgPos+=3 
            while prgPos < len(prg): 
                if prg[prgPos] == 'f' and opened == 0: 
                    break 
                elif prg[prgPos] == 'e': 
                    opened += 1 
                elif prg[prgPos] == 'f': 
                    opened -= 1 
                prgPos += 3 
    elif op=='f': 
        if buff != lval: 
            closed = 0 
            prgPos-=3 
            while prgPos < len(prg): 
                if prg[prgPos] == 'e' and closed == 0: 
                    break 
                elif prg[prgPos] == 'f': 
                    closed += 1 
                elif prg[prgPos] == 'e': 
                    closed -= 1 
                prgPos -= 3 
    prgPos+=3 

Usage

Rogex.py [-c] [filename]
-c      : Interpret all following arguments as Rogex code and execute
filename: Run filename as Rogex code

Online

Online tools for Rogex:

Name Description Link
Online interpreter Run Rogex code online HERE
Encode any message Convert any string to a Rogex program that will print that string HERE
Decode any message 'encode any message' but reversed! (does not actually run code so results may be incorrect) HERE
An alternate arrangement of the python interpreter on TIO Code goes into the code box rather than the arguments to give it a more authentic feel Rearranged by JonoCode9374/Lyxal and used on CGCC

Examples

Hello, world!

A48A65A6cA6cA6fA2cA20A77A6fA72A6cA64A21

Cat

010110

Truth-machine

000E00100F00100

Print Numbers 1 to 10

90B300D00901E00100701A20F00

Reciprocal of a Number

701300001600200