Gdy Brainfuck

From Esolang
Jump to navigation Jump to search

Gdy-Brainfuck is a derivate of Brainfuck but with ABCDEFG.
Created by User:Gadai on 5/18/2023.

Commands

Brainfuck GdyBrainfuck C/C++
+ a p[i]++;
- b pi[i]--;
. d(text) e(number) printf("%s",t); printf("%d",pi[i]);
, None
< A i++;
> B i--;
None c t[c]=xxx;
None f p[i+1]=p[i-1]+p[i];
None F p[i+1]=p[i-1]*p[i];
None g p[i+1]=p[i-1]-p[i];
None G p[i+1]=p[i-1]/p[i];
[ None
] None

Examples

Hello, World!

gbf1
cHceclclcoc,c cWcocrclcdc!c
dC

1+1=2

gbf1
c1c+c1c=dC
aaAaafAe

Interpreter

Interpreter in C++.

#include <fstream>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char **argv) {
    std::vector<char> run_list;
    int power = 0;
    int int_cp = 0;
    std::vector<float> fl_p;
    std::vector<char> str_p;
    for (int i = 0; i < 200; i++)
    {
        fl_p.push_back(0);
    }
    
    std::ifstream file(argv[1]);
    int count = 0;
    if (file.is_open()) {
        char getstr;
        while (file.get(getstr)) {
            run_list.push_back(getstr);
            count++;
        }
        file.close();
        for (int i = 0; i < count; i++) {
            if(run_list[i]=='g' && run_list[i+1]=='b' && run_list[i+2] =='f' && run_list[i+3] =='1' && run_list[i+4] =='\n' && power == 0){
                power = 1;
            }
            if(power == 1){
                if (run_list[i]=='a'){
                    fl_p[int_cp]++;
                }
                else if (run_list[i]=='b'){
                    fl_p[int_cp]--;
                }
                else if (run_list[i]=='A'){
                    int_cp++;
                }
                else if (run_list[i]=='B'){
                    int_cp--;
                }
                else if (run_list[i]=='c'){
                    str_p.push_back(run_list[i+1]);
                    i++;
                }   
                else if (run_list[i]=='d'){
                    for (char c : str_p) {
                        std::cout << c;
                    }
                }
                else if (run_list[i]=='e'){
                    std::cout << fl_p[int_cp];
                }
                else if (run_list[i] == 'C'){
                    str_p.clear();
                }
                else if (run_list[i] == 'f'){
                    fl_p[int_cp+1]=fl_p[int_cp-1]+fl_p[int_cp];
                }
                else if (run_list[i] == 'F'){
                    fl_p[int_cp+1]=fl_p[int_cp-1]*fl_p[int_cp];
                }
                else if (run_list[i] == 'g'){
                    fl_p[int_cp+1]=fl_p[int_cp-1]-fl_p[int_cp];
                }
                else if (run_list[i] == 'G'){
                    if(fl_p[int_cp] == 0){
                        printf("[ERR]\tIt is impossible to divide by 0.");
                        break;
                    }
                    fl_p[int_cp+1]=fl_p[int_cp-1]/fl_p[int_cp];
                }
                
                
                
            }
        }
    } else {
        std::cout << "[ERR]\tCould not open file" << std::endl;
    }
    return 0;
}

Gdy_Brainfuck2

Currently under development

Features to be added:  
 1. Repetition  
 2. User input  
 3. Command (cmd.exe) execution