FISHQ9+

From Esolang
Jump to navigation Jump to search

FISHQ9+ is a simple interpreted language created by combining the functionality of Deadfish and HQ9+.

FISHQ9+ has complete backwards compatibility with deadfish and HQ9+. As anything that is not a command is ignored, FISHQ9+ will have some forwards compatibility with newer versions of FISHQ9+.

FISHQ9+ is not case sensitive, unlike deadfish and has the advanced output features of deadfish and HQ9+, but no input.

Programs in FISHQ9+ must be under 256 characters, or the interpreter will crash. Programs must also end with the K command. These might be considered easily fixable bugs, but I call them features so I don't have to spend a few minutes fixing them.

Commands

Increment Decrement Square Output Accumulator Output "Hello World" Output Quine Output 99 Bottles Terminate
FISHQ9+ i I + d D s S o O h H q Q 9 k K

FISHQ9+ follows the deadfish tradition of only setting the accumulator to zero if and only if acc == -1 || acc == 256.

Examples

There are two ways of running FISHQ9+: shell mode and file mode. Shell mode is used by running fishqnp while file mode is used by running fishqnp < program.txt. The standard shell does not add >> characters. Any program used in file mode must end in a terminate command.

As FISHQ9+ inherited deadfish math, iissso outputs 0, while iissiso outputs 289.

This is a basic program that gives information about the language:

(Put many newlines here (you need them to clear junk before the end))
This is a demo of FISHQ9+. The instructions are: i, d, s, o, h, 9, qk

Implementations

C

//FISHQ9+ Interpreter
//Based off of a deadfish interpreter

#include <stdio.h>

int bottles() {
   int b;

   puts("99 bottles of beer on the wall, 99 bottles of beer.");

   for (b = 98; b > 1; b--) {
       printf("Take one down and pass it around, %d bottles of beer on the wall.\n\n", b);
       printf("%d bottles of beer on the wall, %d bottles of beer.\n", b, b);
   }

   puts("Take one down and pass it around, 1 bottle of beer on the wall.\n");
   puts("1 bottle of beer on the wall, 1 bottle of beer.");
   puts("Take one down and pass it around, no more bottles of beer on the wall.\n");
   puts("No more bottles of beer on the wall, no more bottles of beer.");
   puts("Go to the store and buy some more, 99 bottles of beer on the wall.");

   return 0;
}

int main(void) {
   int acc = 0;
   int pl = 0;
   char code[256];                 //It looked good at the time. It causes a bug, but I'll call it a feature that prevents spaghetti code
   
   for(int i = 0; i < 256; i++)
       code[i] = 0;

   while(1) {
       char input; 

       scanf("%c", &input);        //This line is from the deadfish interpreter. Probably causes a bug, but I still won't change it because it's one of the only lines I didn't completely change
       code[pl] = input;
       pl++;
        
       if(acc == -1 || acc == 256)
           acc = 0;

       if(input == 'i' || input == 'I' || input == 43)
           acc++;
       else if(input == 'd' || input == 'D')
           acc--;
       else if(input == 's' || input == 'S')
           acc *= acc;
       else if(input == 'o' || input == 'O')
           printf("%d\n", acc);
       else if(input == 'h' || input == 'H')
           puts("Hello World.");
       else if(input == 'q' || input == 'Q')
           puts(code);
       else if(input == '9')
           bottles();
       else if(input == 'k' || input == 'K')
           return 0;
   }
}

Kotlin

/**
 * FISHQ9+ Interpreter
 *
 * This interpreter for FISHQ9+ :
 *  - is written in Kotlin (check it out, if you're tired of java)
 *  - does not impose 256 character limit
 *  - adds ">> " prompt for better orientation
 *  - can interpret segments of code (i.e. ">> iissiso")
 *  - has a .jar executable here: http://bit.ly/FISHQ9plus
 *
 *  @author Mychal
 */

fun main(args : Array<String>) {
    var input : String
    var a : Int = 0
    var c : String = ""
    while (true){
        print(">> ")
        input = readLine()?: "NULL"
        c += input
        for(inst : Char in input.toCharArray()) {
            if(a == 256 || a == -1) a = 0
            when (inst) {
                'i', 'I', '+' -> a++
                'd', 'D' -> a--
                'o', 'O' -> println(a)
                's', 'S' -> a *= a
                'h', 'H' -> println("Hello World!")
                'q', 'Q' -> {
                    for (ch in c) print(ch); println()
                }
                '9' -> bottles()
                'k', 'K' -> return;
                else -> print(0.toChar())
            }
        }
    }
}

fun bottles(){
    println("99 bottles of beer on the wall, 99 bottles of beer.")
    for(b : Int in 98 downTo 2){
        println("Take one down and pass it around, $b bottles of beer on the wall.\n")
        println("$b bottles of beer on the wall, $b bottles of beer.")
    }
    println("Take one down and pass it around, 1 bottle of beer on the wall.")
    println()
    println("1 bottle of beer on the wall, 1 bottle of beer.")
    println("Take one down and pass it around, no more bottles of beer on the wall.")
    println()
    println("No more bottles of beer on the wall, no more bottles of beer.")
    println("Go to the store and buy some more, 99 bottles of beer on the wall.")
}

See Also