InfityTOC

From Esolang
Jump to navigation Jump to search

InfityTOC esolang was planned to be an esolang with so long TOC(Contents list)

Commands

+ increment the accumulator
- decrement the accumulator
o output the accumulator as number
. output the accumulator as ascii
h Hello, World!
9 99 bootles of the beer
e echo
? increment the accumulator by random number from 1 to 10
q Quine

Examples

XKCD Random Number

++++o

Hello, world!

h

99 Bootles Of The Beer

9

output 123

+o+o+o

From 0 to XKCD Random Number

o+o+o+o+o

Quine

q

Random number from 1 to 10

?o

output <3

+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++.---------.

(Linefeeds in code can be removed)

echo (or cat)

e

output 321

+++o-o-o

output 100 linefeeds

++++++++++..........................
.....................................
.....................................

(Linefeeds in code can be removed)

Interpreters

All of them written with ChatGPT. I think here mistakes, but this isnt reason to delete interpreter.

Python

import random
acc = 0
code = input()

for c in code:
    if c == '+': acc += 1
    elif c == '-': acc -= 1
    elif c == 'o': print(acc)
    elif c == '.': print(chr(acc % 256), end='')
    elif c == 'h': print("Hello, World!")
    elif c == '9':
        for n in range(99, 0, -1):
            b1 = "bottle" if n == 1 else "bottles"
            b2 = "bottle" if n-1 == 1 else "bottles"
            nxt = f"{n-1}" if n-1 > 0 else "no more"
            print(f"{n} {b1} of beer on the wall, {n} {b1} of beer.")
            print(f"Take one down and pass it around, {nxt} {b2} of beer on the wall.\n")
    elif c == 'e': print(input())
    elif c == '?': acc += random.randint(1,10)
    elif c == 'q': print(code)

It has written by ChatGPT, because idk python

JS

let acc = 0;
let code = prompt();

for (let c of code) {
  if (c=='+') acc++;
  else if (c=='-') acc--;
  else if (c=='o') console.log(acc);
  else if (c=='.') process.stdout.write(String.fromCharCode(acc % 256));
  else if (c=='h') console.log("Hello, World!");
  else if (c=='9') {
    for (let n=99; n>0; n--) {
      let b1 = n==1?"bottle":"bottles";
      let b2 = n-1==1?"bottle":"bottles";
      let nxt = n-1>0?n-1:"no more";
      console.log(`${n} ${b1} of beer on the wall, ${n} ${b1} of beer.`);
      console.log(`Take one down and pass it around, ${nxt} ${b2} of beer on the wall.\n`);
    }
  }
  else if (c=='e') console.log(prompt());
  else if (c=='?') acc += Math.floor(Math.random()*10)+1;
  else if (c=='q') console.log(code);
}

Too written by ChatGPT

Java

import java.util.*;

public class MiniInterpreter {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int acc = 0;
        String code = sc.nextLine();
        Random rnd = new Random();

        for (char c : code.toCharArray()) {
            switch(c) {
                case '+': acc++; break;
                case '-': acc--; break;
                case 'o': System.out.println(acc); break;
                case '.': System.out.print((char)(acc % 256)); break;
                case 'h': System.out.println("Hello, World!"); break;
                case '9':
                    for(int n=99;n>0;n--){
                        String b1 = n==1?"bottle":"bottles";
                        String b2 = n-1==1?"bottle":"bottles";
                        String nxt = n-1>0?String.valueOf(n-1):"no more";
                        System.out.println(n+" "+b1+" of beer on the wall, "+n+" "+b1+" of beer.");
                        System.out.println("Take one down and pass it around, "+nxt+" "+b2+" of beer on the wall.\n");
                    }
                    break;
                case 'e': System.out.println(sc.nextLine()); break;
                case '?': acc += rnd.nextInt(10)+1; break;
                case 'q': System.out.println(code); break;
            }
        }
    }
}

Ruby

acc = 0
code = gets.chomp

code.each_char do |c|
  case c
  when '+'
    acc += 1
  when '-'
    acc -= 1
  when 'o'
    puts acc
  when '.'
    print acc % 256 .chr
  when 'h'
    puts "Hello, World!"
  when '9'
    99.downto(1) do |n|
      b1 = n == 1 ? "bottle" : "bottles"
      b2 = n-1 == 1 ? "bottle" : "bottles"
      nxt = n-1 > 0 ? (n-1).to_s : "no more"
      puts "#{n} #{b1} of beer on the wall, #{n} #{b1} of beer."
      puts "Take one down and pass it around, #{nxt} #{b2} of beer on the wall.\n"
    end
  when 'e'
    puts gets.chomp
  when '?'
    acc += rand(1..10)
  when 'q'
    puts code
  end
end

Lua

math.randomseed(os.time())
acc = 0
io.write("Enter code: ")
code = io.read()

for i = 1, #code do
    local c = code:sub(i,i)
    if c == '+' then acc = acc + 1
    elseif c == '-' then acc = acc - 1
    elseif c == 'o' then print(acc)
    elseif c == '.' then io.write(string.char(acc % 256))
    elseif c == 'h' then print("Hello, World!")
    elseif c == '9' then
        for n = 99,1,-1 do
            local b1 = n==1 and "bottle" or "bottles"
            local b2 = (n-1)==1 and "bottle" or "bottles"
            local nxt = (n-1)>0 and (n-1) or "no more"
            print(n.." "..b1.." of beer on the wall, "..n.." "..b1.." of beer.")
            print("Take one down and pass it around, "..nxt.." "..b2.." of beer on the wall.\n")
        end
    elseif c == 'e' then print(io.read())
    elseif c == '?' then acc = acc + math.random(1,10)
    elseif c == 'q' then print(code)
    end
end

C++

#include <bits/stdc++.h>
using namespace std;

int main() {
    srand(time(0));
    int acc = 0;
    string code;
    getline(cin, code);

    for(char c : code) {
        switch(c) {
            case '+': acc++; break;
            case '-': acc--; break;
            case 'o': cout << acc << endl; break;
            case '.': cout << char(acc % 256); break;
            case 'h': cout << "Hello, World!" << endl; break;
            case '9':
                for(int n=99;n>0;n--) {
                    string b1 = n==1?"bottle":"bottles";
                    string b2 = (n-1)==1?"bottle":"bottles";
                    string nxt = (n-1>0)?to_string(n-1):"no more";
                    cout << n << " " << b1 << " of beer on the wall, " << n << " " << b1 << " of beer.\n";
                    cout << "Take one down and pass it around, " << nxt << " " << b2 << " of beer on the wall.\n\n";
                }
                break;
            case 'e': { string input; getline(cin,input); cout << input << endl; } break;
            case '?': acc += rand()%10 + 1; break;
            case 'q': cout << code << endl; break;
        }
    }
}

Rust

use std::io::{self, Write};
use rand::Rng;

fn main() {
    let mut acc = 0;
    let mut code = String::new();
    io::stdin().read_line(&mut code).unwrap();
    let mut rng = rand::thread_rng();

    for c in code.chars() {
        match c {
            '+' => acc += 1,
            '-' => acc -= 1,
            'o' => println!("{}", acc),
            '.' => print!("{}", (acc % 256) as u8 as char),
            'h' => println!("Hello, World!"),
            '9' => {
                for n in (1..=99).rev() {
                    let b1 = if n == 1 { "bottle" } else { "bottles" };
                    let b2 = if n-1 == 1 { "bottle" } else { "bottles" };
                    let nxt = if n-1 > 0 { (n-1).to_string() } else { "no more".to_string() };
                    println!("{} {} of beer on the wall, {} {} of beer.", n, b1, n, b1);
                    println!("Take one down and pass it around, {} {} of beer on the wall.\n", nxt, b2);
                }
            }
            'e' => {
                let mut input = String::new();
                io::stdin().read_line(&mut input).unwrap();
                print!("{}", input);
            }
            '?' => acc += rng.gen_range(1..=10),
            'q' => print!("{}", code),
            _ => {}
        }
        io::stdout().flush().unwrap();
    }
}

Pascal

program MiniInterpreter;
uses crt, sysutils;

var
  acc, i, n: Integer;
  code, inputLine, nxt, b1, b2: string;

begin
  Randomize;
  acc := 0;
  Readln(code);

  for i := 1 to Length(code) do
  begin
    case code[i] of
      '+': acc := acc + 1;
      '-': acc := acc - 1;
      'o': Writeln(acc);
      '.': Write(Chr(acc mod 256));
      'h': Writeln('Hello, World!');
      '9':
        for n := 99 downto 1 do
        begin
          if n = 1 then b1 := 'bottle' else b1 := 'bottles';
          if n-1 = 1 then b2 := 'bottle' else b2 := 'bottles';
          if n-1 > 0 then nxt := IntToStr(n-1) else nxt := 'no more';
          Writeln(n, ' ', b1, ' of beer on the wall, ', n, ' ', b1, ' of beer.');
          Writeln('Take one down and pass it around, ', nxt, ' ', b2, ' of beer on the wall.');
          Writeln;
        end;
      'e': 
        begin
          Readln(inputLine);
          Writeln(inputLine);
        end;
      '?': acc := acc + Random(10) + 1;
      'q': Writeln(code);
    end;
  end;
end.

Go

package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"time"
)

func main() {
	rand.Seed(time.Now().UnixNano())
	acc := 0
	reader := bufio.NewReader(os.Stdin)
	code, _ := reader.ReadString('\n')

	for _, c := range code {
		switch c {
		case '+':
			acc++
		case '-':
			acc--
		case 'o':
			fmt.Println(acc)
		case '.':
			fmt.Printf("%c", acc%256)
		case 'h':
			fmt.Println("Hello, World!")
		case '9':
			for n := 99; n > 0; n-- {
				b1 := "bottles"
				b2 := "bottles"
				nxt := "no more"
				if n == 1 {
					b1 = "bottle"
				}
				if n-1 == 1 {
					b2 = "bottle"
				}
				if n-1 > 0 {
					nxt = fmt.Sprint(n - 1)
				}
				fmt.Printf("%d %s of beer on the wall, %d %s of beer.\n", n, b1, n, b1)
				fmt.Printf("Take one down and pass it around, %s %s of beer on the wall.\n\n", nxt, b2)
			}
		case 'e':
			input, _ := reader.ReadString('\n')
			fmt.Print(input)
		case '?':
			acc += rand.Intn(10) + 1
		case 'q':
			fmt.Print(code)
		}
	}
}

R

set.seed(as.numeric(Sys.time())) 
acc <- 0
code <- readline(prompt="")

for (c in strsplit(code, "")[[1]]) {
  if (c == "+") {
    acc <- acc + 1
  } else if (c == "-") {
    acc <- acc - 1
  } else if (c == "o") {
    print(acc)
  } else if (c == ".") {
    cat(intToUtf8(acc %% 256))
  } else if (c == "h") {
    cat("Hello, World!\n")
  } else if (c == "9") {
    for (n in 99:1) {
      b1 <- ifelse(n == 1, "bottle", "bottles")
      b2 <- ifelse(n-1 == 1, "bottle", "bottles")
      nxt <- ifelse(n-1 > 0, as.character(n-1), "no more")
      cat(sprintf("%d %s of beer on the wall, %d %s of beer.\n", n, b1, n, b1))
      cat(sprintf("Take one down and pass it around, %s %s of beer on the wall.\n\n", nxt, b2))
    }
  } else if (c == "e") {
    input <- readline()
    cat(input, "\n")
  } else if (c == "?") {
    acc <- acc + sample(1:10, 1)
  } else if (c == "q") {
    cat(code, "\n")
  }
}

Kotlin

import kotlin.random.Random

fun main() {
    var acc = 0
    val code = readLine() ?: ""

    for (c in code) {
        when (c) {
            '+' -> acc++
            '-' -> acc--
            'o' -> println(acc)
            '.' -> print(acc.toChar())
            'h' -> println("Hello, World!")
            '9' -> for (n in 99 downTo 1) {
                val b1 = if (n == 1) "bottle" else "bottles"
                val b2 = if (n - 1 == 1) "bottle" else "bottles"
                val nxt = if (n - 1 > 0) "${n - 1}" else "no more"
                println("$n $b1 of beer on the wall, $n $b1 of beer.")
                println("Take one down and pass it around, $nxt $b2 of beer on the wall.\n")
            }
            'e' -> println(readLine())
            '?' -> acc += Random.nextInt(1, 11)
            'q' -> println(code)
        }
    }
}

Python (Tkinter GUI)

import tkinter as tk
from tkinter import scrolledtext
import random

def run_code():
    code = code_input.get("1.0", tk.END).strip()
    acc = 0
    output_text.delete("1.0", tk.END)

    for c in code:
        if c == '+': acc += 1
        elif c == '-': acc -= 1
        elif c == 'o': output_text.insert(tk.END, f"{acc}\n")
        elif c == '.': output_text.insert(tk.END, chr(acc % 256))
        elif c == 'h': output_text.insert(tk.END, "Hello, World!\n")
        elif c == '9':
            for n in range(99, 0, -1):
                b1 = "bottle" if n == 1 else "bottles"
                b2 = "bottle" if n-1 == 1 else "bottles"
                nxt = f"{n-1}" if n-1 > 0 else "no more"
                output_text.insert(tk.END, f"{n} {b1} of beer on the wall, {n} {b1} of beer.\n")
                output_text.insert(tk.END, f"Take one down and pass it around, {nxt} {b2} of beer on the wall.\n\n")
        elif c == 'e':
            user_input = tk.simpledialog.askstring("Input", "Enter a string:")
            output_text.insert(tk.END, f"{user_input}\n")
        elif c == '?': acc += random.randint(1,10)
        elif c == 'q': output_text.insert(tk.END, f"{code}\n")

# --- GUI setup ---
root = tk.Tk()
root.title("Mini Interpreter GUI")

tk.Label(root, text="Enter code:").pack()
code_input = scrolledtext.ScrolledText(root, width=60, height=10)
code_input.pack()

run_btn = tk.Button(root, text="Run", command=run_code)
run_btn.pack(pady=5)

tk.Label(root, text="Output:").pack()
output_text = scrolledtext.ScrolledText(root, width=60, height=20)
output_text.pack()

root.mainloop()

Tcl (Tk GUI)

#!/usr/bin/env tclsh

package require Tk

# --- GUI setup ---
wm title . "Mini Interpreter GUI"

label .lbl -text "Enter code:"
pack .lbl

text .code -width 60 -height 10
pack .code

button .run -text "Run" -command {
    set code [.code get 1.0 end]
    .output delete 1.0 end
    set acc 0
    foreach c [split $code {}] {
        switch $c {
            "+" { incr acc }
            "-" { incr acc -1 }
            "o" { .output insert end "$acc\n" }
            "." { .output insert end [format "%c" $acc] }
            "h" { .output insert end "Hello, World!\n" }
            "9" {
                for {set n 99} {$n > 0} {incr n -1} {
                    set b1 [expr {$n==1 ? "bottle" : "bottles"}]
                    set b2 [expr {$n-1==1 ? "bottle" : "bottles"}]
                    set nxt [expr {$n-1>0 ? $n-1 : "no more"}]
                    .output insert end "$n $b1 of beer on the wall, $n $b1 of beer.\n"
                    .output insert end "Take one down and pass it around, $nxt $b2 of beer on the wall.\n\n"
                }
            }
            "e" {
                set input [tk_getOpenFile -title "Enter input string"] ;# упрощённый вариант
                .output insert end "$input\n"
            }
            "?" { incr acc [expr {int(rand()*10)+1}] }
            "q" { .output insert end "$code\n" }
        }
    }
}

pack .run -pady 5

label .lbl2 -text "Output:"
pack .lbl2

text .output -width 60 -height 20
pack .output

# --- main loop ---

BASIC

CLS
DIM code AS STRING
DIM acc AS INTEGER
acc = 0

INPUT "Enter code: ", code$

FOR i = 1 TO LEN(code$)
    c$ = MID$(code$, i, 1)
    IF c$ = "+" THEN acc = acc + 1
    IF c$ = "-" THEN acc = acc - 1
    IF c$ = "o" THEN PRINT acc
    IF c$ = "." THEN PRINT CHR$(acc MOD 256);
    IF c$ = "h" THEN PRINT "Hello, World!"
    IF c$ = "9" THEN
        FOR n = 99 TO 1 STEP -1
            IF n = 1 THEN b1$ = "bottle" ELSE b1$ = "bottles"
            IF n-1 = 1 THEN b2$ = "bottle" ELSE b2$ = "bottles"
            IF n-1 > 0 THEN nxt$ = STR$(n-1) ELSE nxt$ = "no more"
            PRINT n; " "; b1$; " of beer on the wall, "; n; " "; b1$; " of beer."
            PRINT "Take one down and pass it around, "; nxt$; " "; b2$; " of beer on the wall."
            PRINT
        NEXT n
    END IF
    IF c$ = "e" THEN
        INPUT "Enter string: ", input$
        PRINT input$
    END IF
    IF c$ = "q" THEN PRINT code$
NEXT i

MAKE "acc 0
PRINT [Enter code:]
MAKE "code READWORD

FOR [i 1 COUNT :code] [
  MAKE "c ITEM i :code
  IF :c = "+" [MAKE "acc :acc + 1]
  IF :c = "-" [MAKE "acc :acc - 1]
  IF :c = "o [PRINT :acc]
  IF :c = "h [PRINT [Hello, World!]]
  IF :c = "q [PRINT :code]
]

interpreters written in this esolang

16 bytes :P

e