Author Topic: Spyrodecimal - esolang  (Read 5576 times)

0 Members and 2 Guests are viewing this topic.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Spyrodecimal - esolang
« on: January 08, 2012, 03:48:13 pm »
First off, esolang is short for esoteric programming language.
Spyrodecimal is an esolang where all the commands are numbers.

Here are all the commands:

0 - Pauses the program for 1/10 second.
1 - Prints the ASCII equivalent of the number in memory.
n - Prints the actual number in memory.
2 - Increases the number in memory.
3 - Decreases the number in memory.
4 - Gets one character of input, and stores it in memory.
5 - Prints a new line.
6 - Generates a random number between 1 and 256 and stores it in memory.
7 - Moves the program reader back for the amount in memory. For example, if 5 is in memory, it will move back 5 spaces.
8 - Erases the memory.
9 - Same as 7, except moves the reader forward instead of backward.
q - Quits the interpreter.
x - quits the program, but not the interpreter.
s - Stores the current memory value into one of six variables (a, b, c, d, e, f). Variables are not affected by 8. Syntax (s<var> example: sa)
r - Recalls the value stored into one of six variables (a, b, c, d, e, f) and stores it in memory. Syntax (r<var> example: ra)

I'm currently working on the interpreter (in C++).
Any ideas are welcome!
« Last Edit: January 09, 2012, 07:39:30 pm by Spyro543 »

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #1 on: January 08, 2012, 05:33:45 pm »
Project Update:
Source Code:
Code: [Select]
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int loopstart = 0;
int main()
{
    cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n";
    string prgm;
    signed int mem = 0;
    bool loop = false;
    while (true)
    {
        cout << ">>> ";
        cin >> prgm;
        for (int i=0;i < prgm.length();i++)
        {
            char data = prgm[i];
            switch (data)
            {
                case '0':
                Sleep(0.1);
                break;
                case '1':
                if (prgm[i+1]=='n') cout << mem;
                else cout << (char)mem;
                break;
                case '2':
                mem++;
                break;
                case '3':
                mem--;
                break;
                case '4':
                char inp;
                mem = 0;
                cin >> inp;
                mem = (int)inp;
                break;
                case '5':
                cout << "\n";
                break;
                case '6':
                mem = rand() % 256 + 1;
                break;
                case '7':
                loop = false;
                loopstart = i;
                break;
                case '8':
                mem = 0;
                break;
                case '9':
                if (loop==true)
                {
                    i++;
                    loop = false;
                }
                else
                {
                i = loopstart;
                loop = true;
                }
                break;
                case 'q':
                return 0;
                break;
                case 'n':
                break;
                default:
                cout << "\nUnknown command...\n";
            }
        }
        cout << "\nProgram finished.\n";
    }
}
CPP file and executable attached to this post. I'm still having a little trouble with the 7's and 9's (also, the 7 has to be before the 9).
« Last Edit: January 08, 2012, 07:33:43 pm by Spyro543 »

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Spyrodecimal - esolang
« Reply #2 on: January 09, 2012, 12:08:45 pm »
Haha nice!

Calc version soon?

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #3 on: January 09, 2012, 03:22:05 pm »
Haha nice!

Calc version soon?
Maybe, if I can figure out how to get string formatting in TI-BASIC like I did with C++.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #4 on: January 09, 2012, 03:47:38 pm »
Another Project Update!!!
The roles of  7 and 9 have changed:
7 - Ignores everything until the next 7. (Could allow for comments?)
9 - Repeats the command before it once.
And a new command has been added:
x - quits the program, but not the interpreter.
Here's the source:
Code: [Select]
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int loopstart = 0;
int main()
{
    cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n";
    string prgm;
    signed int mem = 0;
    int pos = 0;
    char data;
    bool ignore = false;
    bool repeat = false;
    while (true)
    {
        cout << ">>> ";
        cin >> prgm;
        for (int i=0;i < prgm.length();i++)
        {
            data = prgm[i];
            if (ignore==true)
            {
                if (data=='7')
                {
                    ignore = false;
                }
            }
            else
            {
                switch (data)
                {
                    case '0':
                    Sleep(100);
                    break;
                    case '1':
                    if (prgm[i+1]=='n') cout << mem;
                    else cout << (char)mem;
                    break;
                    case '2':
                    mem++;
                    break;
                    case '3':
                    mem--;
                    break;
                    case '4':
                    char inp;
                    mem = 0;
                    cin >> inp;
                    mem = (int)inp;
                    break;
                    case '5':
                    cout << "\n";
                    break;
                    case '6':
                    mem = rand() % 256 + 1;
                    break;
                    case '7':
                    ignore = true;
                    break;
                    case '8':
                    mem = 0;
                    break;
                    case '9':
                    if (repeat==false)
                    {
                        i--;
                        repeat = true;
                    }
                    else if (repeat==true)
                    {
                        repeat = false;
                    }
                    break;
                    case 'q':
                    return 0;
                    break;
                    case 'n':
                    break;
                    case 'x':
                    goto end;
                    break;
                    default:
                    break;
                }
            }
        }
        end:
        cout << "\nProgram finished.\n";
    }
}
Attached are the source file and executable.
« Last Edit: January 09, 2012, 04:07:57 pm by Spyro543 »

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Spyrodecimal - esolang
« Reply #5 on: January 09, 2012, 04:13:17 pm »
Well, you could use hexadecimal instead of using letters that isn't numbers. Suggestion like this. Plus you could store your program in a BigNum and crypt stuff in decimal or use nib{ in Axe (if you want to "compile" programs). Therefore keeping the idea of an entierely decimal language.
« Last Edit: January 09, 2012, 04:17:40 pm by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #6 on: January 09, 2012, 07:41:42 pm »
MORE UPDATES!!!

Source:
Code: [Select]
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int loopstart = 0;
int main()
{
    cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n";
    string prgm;
    signed int mem = 0;
    int pos = 0;
    char data;
    signed int a = 0;
    signed int b = 0;
    signed int c = 0;
    signed int d = 0;
    signed int e = 0;
    signed int f = 0;
    char var;
    while (true)
    {
        cout << ">>> ";
        cin >> prgm;
        for (int i=0;i < prgm.length();i++)
        {
            data = prgm[i];
            switch (data)
            {
                case '0':
                Sleep(100);
                break;
                case '1':
                cout << (char)mem;
                break;
                case '2':
                mem++;
                break;
                case '3':
                mem--;
                break;
                case '4':
                char inp;
                mem = 0;
                cin >> inp;
                mem = (int)inp;
                break;
                case '5':
                cout << "\n";
                break;
                case '6':
                mem = rand() % 256 + 1;
                break;
                case '7':
                i -= mem;
                break;
                case '8':
                mem = 0;
                break;
                case '9':
                i += mem;
                break;
                case 'q':
                return 0;
                break;
                case 'n':
                cout << mem;
                break;
                case 'x':
                goto end;
                break;
                case 'r':
                var = prgm[i+1];
                if (var=='a') mem = a;
                else if (var=='b') mem = b;
                else if (var=='c') mem = c;
                else if (var=='d') mem = d;
                else if (var=='e') mem = e;
                else if (var=='f') mem = f;
                break;
                case 's':
                var = prgm[i+1];
                if (var=='a') a = mem;
                else if (var=='b') b = mem;
                else if (var=='c') c = mem;
                else if (var=='d') d = mem;
                else if (var=='e') e = mem;
                else if (var=='f') f = mem;
                break;
                default:
                break;
            }
        }
        end:
        cout << "\nProgram finished.\n";
    }
}
Look at the first post, 1n is now n, s and r commands are added, and 7 and 9 are changed.
Download links:
Source: http://anova.57o9.org/junk/spd/spyrodec.cpp
EXE: http://anova.57o9.org/junk/spd/spyrodec.exe

This update takes Spyrodecimal one step further to becoming Turing complete!
« Last Edit: January 09, 2012, 07:42:21 pm by Spyro543 »

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Spyrodecimal - esolang
« Reply #7 on: January 10, 2012, 12:50:45 pm »
but if i understand it correct, you can only have one goto and one label, or not?

and btw, i voted for change to symbols, since i think it might get too complicated when using variables..
« Last Edit: January 10, 2012, 12:53:00 pm by Nick »

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #8 on: January 12, 2012, 02:22:47 pm »
Here is my try at a small interpreted language :)

It has one variable for operations (like your memory, I call it register), 256 labels and 2048 bytes of memory where you can read and write from.

Spoiler For Commands:
d      Enable/disable debug mode
n      Print new line
i      Get char from keyboard
p      Print char
I      Get number from keyboard
P      Print number
k        Immediately get char from keyboard (doesn't wait for enter) without local echo
t      Generate random number
lX      Create label X
jX      Jump to label X
sX      Store register to X, where X must be one printable character, e.g. 12 wouldn't work. This means, you can't access all 2048 bytes through this command, you will have to use SX and RX
rX      Restore X to register
SX      Store register to the address stored in X (like a pointer)
RX      Restore value at the address stored in X to register
1      Increment register
2      Decrement register
+X      register = register + value at X
-X      register = register - value at X
*X      register = register * value at X
/X      register = register / value at X
x      Clear register
=X      Store X (=88) in register
?XY      If-Clause
      X --> =      register == Y
      X --> !      register != Y
      X --> >      register >  Y
      X --> <      register <  Y
;      Ends If-Clause (and btw, at the moment nested Ifs don't work at all)

Code:
Code: [Select]
#include <iostream>
#include <conio.h>
#include <string.h>
#include <string>
#include <windows.h>
#include <time.h>

using namespace std;

int main(void)
{
int memory[2048];
int label[256];
int reg;
int deep;
bool ignore = false;
bool debug = false;
char tmp;
srand((unsigned)time(NULL));
while(true)
{
string program;
cout << endl << ">>>";
cin >> program;
memset(memory,0,2048*sizeof(int));
memset(label,0,256*sizeof(int));
reg = 0;
deep = 0;
for (int i=0; i < program.length(); i++)
{
if(program[i] == 'l')
{
label[program[i+1]] = i+1;
if(debug) cout << "Label " << program[i+1] << " at " << i+1 << endl;
}
}
for (int i=0; i < program.length(); i++)
{
if(ignore && program[i] != ';') continue;
else ignore = false;
if(debug) cout << "op=" << program[i] << ", pos=" << i << ", reg=" << reg << " (" << (char)reg << ")" << endl;
switch(program[i])
{
case 'd':
debug = !debug;
if(debug) cout << "\tdebug=" << debug << endl;
break;
case 'n':
cout << endl;
break;
case 'i':
if(debug) cout << "\tinput ";
cin >> tmp;
reg = tmp;
break;
case 'p':
if(debug) cout << "\tprint " << (char)reg << endl;
else cout << (char)reg;
break;
case 'I':
if(debug) cout << "\tinput ";
cin >> reg;
break;
case 'P':
if(debug) cout << "\tprint " << reg << endl;
else cout << reg;
break;
case 'k':
reg = getch();
break;
case 't':
reg = rand();
if(debug) cout << "\trand=" << (int)reg << endl;
break;
case 'j':
if(debug) cout << "\tlabel=" << program[i+1] << ", pos=" << label[program[i+1]] << endl;
i = label[program[i+1]];
break;
case 's':
memory[program[i+1]] = reg;
i++;
if(debug) cout << "\tmemory(" << program[i] << ")=" << reg << endl;
break;
case 'r':
reg = memory[program[i+1]];
i++;
if(debug) cout << "\tmemory(" << program[i] << ")=" << reg << endl;
break;
case 'S':
memory[memory[program[i+1]]] = reg;
i++;
break;
case 'R':
//cout << program[i+1] << "," << memory[program[i+1]] << "," << memory[memory[program[i+1]]] << endl;
reg = memory[memory[program[i+1]]];
i++;
break;
case '1':
reg++;
break;
case '2':
reg--;
break;
case '+':
if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", add=" << reg + memory[program[i+1]] << endl;
reg = reg + memory[program[i+1]];
i++;
break;
case '-':
if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", subtract=" << reg - memory[program[i+1]] << endl;
reg = reg - memory[program[i+1]];
i++;
break;
case '/':
if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", divide=" << reg / memory[program[i+1]] << endl;
reg = reg / memory[program[i+1]];
i++;
break;
case '*':
if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", multiply=" << reg * memory[program[i+1]] << endl;
reg = reg * memory[program[i+1]];
i++;
break;
case 'x':
reg = 0;
break;
case '=':
reg = program[i+1];
i++;
break;
case '?':
if(program[i+1] == '=')
{
if(reg == memory[program[i+2]]) ignore = false;
else ignore = true;
}
else if(program[i+1] == '!')
{
if(reg != memory[program[i+2]]) ignore = false;
else ignore = true;
}
else if(program[i+1] == '>')
{
if(reg > memory[program[i+2]]) ignore = false;
else ignore = true;
}
else if(program[i+1] == '<')
{
if(reg < memory[program[i+2]]) ignore = false;
else ignore = true;
}
if(debug) cout << "\tif reg " << program[i+1] << " memory(" << program[i+2] << ") --> " << ignore << endl;
i += 2;
break;
default:
break;
}
}
}
}

A simple and documented Guess the number:
Spoiler For Code:
t                            // Create random number
sa                            // Save it in a
lA                            // Label A
   rc                         // Get c (number of guesses)
   1                         // Increment c
   sc                         // Store c
   =Np=up=mp=bp=ep=rp=?p          // Print "Number?"
   I                         // Input number
   sb                         // Store it in b
   ?>a                      // register > a?
      =Sp=mp=ap=lpp=ep=rpn       // Print "Smaller"
      rb                      // Restore b
      jA                      // Repeat
   ;                         // If-End
   ?<a                      // register < a?
      =Bp=ip=gpp=ep=rpn          // Print "Bigger"
      rb                      // Restore b
      jA                      // Repeat
   ;                         // If-End
   ?=a                      // register == a?
      =Cp=op=rpp=ep=cp=tp=!p       // Print "Correct!"
      n                      // new line
      =Tp=rp=ip=ep=sp=:p          // Print "Tries:"
      rc                      // Get c (number of guesses)
      P                      // Print number of guesses
   ;                         // If-End


Resulting program:
tsalArc1sc=Np=up=mp=bp=ep=rp=?pIsb?>a=Sp=mp=ap=lpp=ep=rpnrbjA;?<a=Bp=ip=gpp=ep=rpnrbjA;?=a=Cp=op=rpp=ep=cp=tp=!pn=Tp=rp=ip=ep=sp=:prcP;

And a brainfuck interpreter ;D (won't work with nested loops)
Spoiler For Code:
=d // 100
sA // A = instruction pointer, points to 100

=! // 33
sB
*B // 33 * 33 = 1089
sB // memory pointer, points to 1089

=A // 65
sC
=N // 78
-C // 78 - 65 = 13, CR
sC // C holds CR

lA // Program read loop
k // Read char
p // Local echo
?!C // Char = CR?
   SA // Store in instruction pointer target
   rA
   1 // Increment insctruction pointer
   sA
   jA // loop end
; // End of program read loop

n

=d
sA // Reset instruction pointer
lB // Main loop start

=> // Brainfuck: Increments Pointer.
sE // Opcode buffer
RA // Get instruction
?=E
   rB
   1
   sB
;

=< // Brainfuck: Decrements Pointer.
sE
RA
?=E
   rB
   2
   sB
;

=+ // Brainfuck: Increments Pointer Target.
sE
RA
?=E
   RB
   1
   SB
;

=- // Brainfuck: Decrements Pointer Target.
sE
RA
?=E
   RB
   2
   SB
;

=. // Brainfuck: Prints Pointer Target.
sE
RA
?=E
   RB
   p
;

=, // Brainfuck: Reads char.
sE
RA
?=E
   k
   p // Local echo
   SB
;

=[ // Brainfuck: Jumps after "]" if pointer target is 0
sE
RA
?=E
   RB // Get pointer target
   ?=D // = 0?
      lC // Increment instruction pointer until ] appears
      =] // Load ]
      sa
      rA
      1
      sA
      RA
      ?!a
         jC
      ;
   ;
;

=] // Brainfuck: Jumps back to "[" if pointer target nonzero
sE
RA
?=E
   RB
   ?!D // != 0?
      lD // Decrement instruction pointer until [ appears
      =[
      sa
      rA
      2
      sA
      RA
      ?!a
         jD
      ;
   ;
;

rA
1 // Increment instruction pointer
sA
RA
?!D // D should be 0
   jB
;


Resulting program:
=dsA=!sB*BsB=AsC=N-CsClAkp?!CSArA1sAjA;n=dsAlB=>sERA?=ErB1sB;=<sERA?=ErB2sB;=+sERA?=ERB1SB;=-sERA?=ERB2SB;=.sERA?=ERBp;=,sERA?=EkpSB;=[sERA?=ERB?=DlC=]sarA1sARA?!ajC;;;=]sERA?=ERB?!DlD=[sarA2sARA?!ajD;;;rA1sARA?!DjB;

Brainfuck "Hello World":
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]<.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>-]<+.[-]++++++++++.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Spyrodecimal - esolang
« Reply #9 on: January 12, 2012, 03:22:41 pm »
wow that's cool D:
Maybe I should re-do Spyrodecimal in Python (since I know python better)