GithubHelp home page GithubHelp logo

4y8 / esoo Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 1.0 54 KB

Like the Programming Languages Zoo but with esoteric languages.

License: BSD 3-Clause "New" or "Revised" License

OCaml 100.00%
esoteric-programming-language esoteric-interpreter esoteric interpreter ocaml programming-language interpreted-programming-language esolang esolangs brainfuck

esoo's Introduction

The Esoteric Programming Languages Zoo

The Esoteric Programming Languages Zoo (a.k.a esoo for short), is a repository of implementations of esoteric programming languages. It is heavly inpired by Andrej Bauer’s plzoo. All of them have an esolang wiki page so if you want informations about them go there. Some of them (like Cthulhu) was marked as unimplemented before the esoo.

esoo's People

Contributors

4y8 avatar legionmammal978 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

elektr1x

esoo's Issues

Numbers do not work in Z implementation with double-space line delimiters

When eval is called with a new line of input, it splits the input line into several double-space-delimited logical lines which are all passed to the strs argument of exec. However, this creates undesired behavior with zz z numbers; numoflist parses the entire remainder of the strs list without regard to logical-line delimiters. To fix this, I would recommend calling exec only once for each logical line in the input line.

Z implementation cannot use the number grid

Since eval is called with an empty mem array, and since Zz assumes that mem.(pointer) already exists, it will always throw an Invalid_argument("index out of bounds") exception. The array should ideally be expanded as necessary.

Z implementation does not compile

I am unable to get the Z interpreter to compile. When I compiled the file verbatim, I got:

File "z.ml", line 56, characters 50-51:
Error: Syntax error: operator expected.

When I removed the second space in the character literal, I got:

File "z.ml", line 63, characters 26-32:
Error: Unbound value regexp

When I replaced regexp with Str.regexp, I got:

File "z.ml", line 68, characters 41-50:
Error: Unbound value real_line
Hint: Did you mean read_line?

When I replaced real_line with read_line, I got:

File "z.ml", line 68, characters 35-73:
Error: This expression has type (int -> int array * int * int) * string list
       but an expression was expected of type 'a * 'b * 'c * 'd

And that's when I gave up since I don't actually know OCaml. Is there some unusual build environment I'm missing here?

Jumping does not work in Z implementation

When exec is called with a jump command, it executes one command at the jump target, then exec_list executes the rest of the commands following the jump command. This can be fixed by restructuring exec to take an instruction pointer. I've made a patched version of z.ml that does this and fixes a few other bugs I've noticed:

  • safe_change has been renamed to expand and its logic has been fixed and deduplicated.
  • Instead of expanding mem when it is written to, the program expands it when pointer is changed or mem.(a) is accessed.
  • mem is initialized as [|0|] instead of [||].
  • exec_list has been removed, and exec has been modified to run the remainder of the commands.
  • The pattern-matching has been modified to accept one command per line.
  • When the input command is called, the program reads a single character as input instead of the first character of an entire line of input.
  • Entering an empty line into the REPL causes it to exit.
let eval input mem a pointer lines =
  let expand l p =
    let len = Array.length l in
    if p < len then l else
    let nl = Array.make (p + 1) 0 in
    Array.blit l 0 nl 0 len;
    nl.(p) <- a;
    nl
  in
  let rec exec ip mem a pointer lines =
    if ip >= List.length lines then mem, a, pointer, lines else
    let strs = String.split_on_char ' ' (List.nth lines ip) in
    let nip = ip + 1 in
    match strs with
      ["z"] -> exec nip mem (Char.code (input_char stdin)) pointer lines
    | ["Z"] -> print_char (Char.chr a);
        exec nip mem a pointer lines
    | "zz" :: "z" :: tl ->
        let rec numoflist lst =
          match lst with
            [] -> ""
          | head :: tail ->
              begin
                match head with 
                  "z"   -> "1"
                | "Z"   -> "2"
                | "zz"  -> "3"
                | "zZ"  -> "4"
                | "Zz"  -> "5"
                | "ZZ"  -> "6"
                | "zzz" -> "7"
                | "zzZ" -> "8"
                | "zZz" -> "9"
                | "zZZ" -> "0"
                | _     -> ""
              end ^ numoflist tail
        in
        exec nip mem (int_of_string (numoflist tl)) pointer lines
    | ["zz"; "Z"] -> let mem = expand mem a in
        exec nip mem mem.(a) pointer lines
    | ["zZ"] -> let mem = expand mem a in
        exec nip mem a a lines
    | ["Zz"] -> mem.(pointer) <- a;
        exec nip mem a pointer lines
    | ["ZZ"; "z"] -> mem.(pointer) <- mem.(pointer) + a;
        exec nip mem a pointer lines
    | ["ZZ"; "Z"] -> mem.(pointer) <- mem.(pointer) - a;
        exec nip mem a pointer lines
    | ["zzz"] -> exec a mem a pointer lines
    | ["zzZ"] -> let nip = if mem.(pointer) = 0 then a else nip in
        exec nip mem a pointer lines
    | _ -> exec nip mem a pointer lines
  in
  let nlines = Str.split (Str.regexp "  ") input in
  exec (List.length lines) mem a pointer (lines @ nlines)

let rec repl mem a pointer lines =
  print_string "> ";
  let line = read_line () in
  if line = "" then () else
  let mem2, a2, pointer2, lines2 = eval line mem a pointer lines in
  repl mem2 a2 pointer2 lines2

let _ =
  repl [|0|] 0 0 [];

Honestly, this has been a good exercise for me in OCaml programming.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.