TinyF

From Esolang
Jump to navigation Jump to search
Not to be confused with TinyBF.

TinyF is a brainfuck derivative created by Cursor AI and prompted by User:None1.

Specification

TinyF has the following commands:

  • > - Move the memory pointer to the right.
  • < - Move the memory pointer to the left.
  • + - Increment the memory cell at the pointer.
  • - - Decrement the memory cell at the pointer.
  • . - Output the character signified by the cell at the pointer.
  • , - Input a character and store it in the cell at the pointer.
  • * - Multiply the current cell value by the next cell value.
  • ! - If the current cell value is zero, skip the next command.

Interpreter

Written in C++, generated by the Cursor AI.

#include <iostream>
#include <vector>

class TinyFInterpreter {
private:
    std::vector<int> tape;
    int ptr;

public:
    TinyFInterpreter() : tape(30000, 0), ptr(0) {}

    void interpret(const std::string& code) {
        for (size_t i = 0; i < code.size(); ++i) {
            switch (code[i]) {
                case '>':
                    ++ptr;
                    break;
                case '<':
                    --ptr;
                    break;
                case '+':
                    ++tape[ptr];
                    break;
                case '-':
                    --tape[ptr];
                    break;
                case '.':
                    std::cout << static_cast<char>(tape[ptr]);
                    break;
                case ',':
                    tape[ptr] = std::cin.get();
                    break;
                case '*':
                    tape[ptr] *= tape[ptr + 1];
                    break;
                case '!':
                    if (tape[ptr] == 0 && i + 1 < code.size()) {
                        ++i; // Skip the next command
                    }
                    break;
            }
        }
    }
};

int main() {
    TinyFInterpreter interpreter;
    std::string code;
    std::cout << "Enter TinyF code: ";
    std::getline(std::cin, code);
    interpreter.interpret(code);
    return 0;
}