Talk:Qwote

From Esolang
Jump to navigation Jump to search

Interpreter in Io

toBin :=
    File standardInput open() readLine
    asMutable asList

    select(i,
        "\"'" containsSeq(i)
    ) join

    translate("\"'", "01")

out := list()

while(toBin size > 7,
    toBin = toBin splitAt(8)
    out = out append(toBin at(0))
    toBin = toBin at(1)
)

out = out map(i,
    i fromBase(2) asCharacter
) join

out println

Try it online! ----(this comment by A at 12:34, 1 January 2016 UTC; please sign your comments with ~~~~) 13:09, 26 March 2020 (UTC)

Interpreter Written in Rust

    let args: Vec<String> = std::env::args().collect();
    let mut buffer: String = String::new();

    match OpenOptions::new().read(true).open(args[1].clone()) {
        Ok(mut s) => {
            s.read_to_string(&mut buffer).unwrap();
        },
        Err(e) => {
            println!("{:?}", e);
        }
    }

    let code = buffer.chars().into_iter().filter(|x| x == '\'' || x == '\"').collect::<Vec<char>>();
    let mut bytes: Vec<[u8; 8]> = Vec::new();

    let mut i: usize = 0;
    loop {
        if i >= code.len() {
            break;
        }

        let mut byte: [u8; 8] = [0; 8];

        for x in 0..8 {
            let c = code[i + x];
            match c {
                '\'' => byte[(i + x) % 8] = 1,
                '\"' => byte[(i + x) % 8] = 0,
                _ => {
                    // skip
                }
            }
        }

        bytes.push(byte);

        i += 8;
    }

    let ascii_codes = bytes.into_iter().map(|x| { let mut unit: u8 = 0; for i in 0..8 { unit = unit << 1; unit += x[i]; } unit }).collect::<Vec<u8>>();
    for x in ascii_codes {
        print!("{}", x as char);
    }
    println!();


Kudos to User: Areallycoolusername for getting the binary representation right :D

Fac (talk) 06:36, 24 March 2020 (UTC)

Interpreter written in Python 3

def parse_source(src):
    i = 1
    out = ""
    buffer = ""
    for c in src:
        if c == "\"":
            buffer += "0"
        elif c == "\'":
            buffer += "1"
        else:
            continue
        if i == 8:
            out += chr(int(buffer, base=2))
            buffer = ""
            i = 1
            continue
        i += 1
    return out


if __name__ == '__main__':
    source = input()
    try:
        with open(source) as file:
            source = file.read()
    except (FileNotFoundError, OSError):
        ...
    print(parse_source(source))

Binyamin (talk) 22:41, 1 April 2020 (UTC)

Another interpreter written in Python 3 with a few extra things.

Well, still semi-new to Python in general but I made this in Python 3.

'''
Hello, and welcome to this Qwote interpreter. Qwote is some random esoteric language I stumbled upon on the esoteric languages wiki. Apparently there's no interpreter, so here is one.
How Qwote works: literally like binary. " is 0 however while ' is a 1.

--Cirrubec
'''
# Import all libraries that may be necessary for this code.
import os # This will be necessary for communicating with the operating system.

while True: # Start a loop so the user can run code as many times as they'd like.
    # Make certain variables necessary for this interpreter.
    CurrentBinary = "" # Current binary being used.
    Output = "" # This will be printed once the code has been ran through.

    # Prompt the user to input some code.
    print("Either post code here or link to an existing file on your system in the .txt format. You can also translate binary into Qwote by typing QWOTE= and then your binary.")
    Code = str(input("> "))

    # Check if the input is an actual file.
    if os.path.isfile(Code):
        Code = open(Code).read()
    
    # Go through all of the code
    if Code[0:6] == "QWOTE=": # Check if the user input starts with QWOTE=.
        if len(Code) == 6: # Check if the length of the code is only 6, or in other words with QWOTE= only.
            print("Please input some binary to translate into Qwote.")
        else:
            for i in Code[6:len(Code)]:
                if i == "0": # Check if the current string is a 0.
                    Output = Output + '" '
                elif i == "1": # Check if the current string is a 1.
                    Output = Output + "' "
            print(Output) # Finally, print the output.
    else:
        for i in Code:
            CurrentBinary = CurrentBinary + "0" if i == '"' else CurrentBinary # Append 0 to the CurrentBinary variable if the character in the current code is a ".
            CurrentBinary = CurrentBinary + "1" if i == "'" else CurrentBinary # Append 1 to the CurrentBinary variable if the character in the current code is a '.
            if len(CurrentBinary) == 8: # Check if the length of the CurrentBinary value is 0.
                Char = 0 # This will be representing the integer of the character in the first 256 integers of the unicode table.
                for Bit in range(7, -1, -1): # Going backwards to simplify a few things.
                    Char = Char + 2**Bit if CurrentBinary[-Bit - 1] == "1" else Char # Append 2 to the power of Bit if the bit currently being pointed at is a 1.
                Output = Output + chr(Char) # Append to the Output variable with the unicode of the integer.
                CurrentBinary = "" # Clear the binary string for later usage.
    
        if len(CurrentBinary) != 0:
            print("Error: unfinished Qwote.")
        elif len(Code) == 0:
            print("Please input some code.")
        else:
            print(Output) # Finally, print the output.

Cirrubec (talk) 17:20, 5 May 2021 (UTC)