GithubHelp home page GithubHelp logo

mvillafuertem / befunge-93 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from systemfw/befunge-93

0.0 0.0 0.0 30 KB

Purely Functional, Final Tagless interpreter for the Befunge-93 esolang

Scala 100.00%

befunge-93's Introduction

Befunge-93

A purely functional Befunge-93 interpreter, written in final tagless style. Showcasing the beauty and power of compositional design.

The interpreter

Given a Befunge-93 program, usually expressed as a multiline string

val helloWorld = 
    """
>              v
v  ,,,,,"Hello"<
>48*,          v
v,,,,,,"World!"<
>25*,@
   """

you can run it to completion by calling befunge.run(helloWorld), or step through it in debug mode with befunge.debug(helloWorld). Note that both return a cats.effect.IO], which describes their behaviour in a purely functional manner. You can compose the IO computations in a larger program, or, if you want to actually trigger their execution because you are in main or in the repl, call .unsafeRunSync on them.

The befunge object also contains some example programs for you to try out.

The language

Befunge-93 is a stack-based, reflective, bidimensional esoteric programming language. The spec is here

A short table of the commands is as follows:

Command Summary

COMMAND         INITIAL STACK (bot->top)RESULT (STACK)
-------         -------------           -----------------
+ (add)         <value1> <value2>       <value1 + value2>
- (subtract)    <value1> <value2>       <value1 - value2>
* (multiply)    <value1> <value2>       <value1 * value2>
/ (divide)      <value1> <value2>       <value1 / value2> (nb. integer)
% (modulo)      <value1> <value2>       <value1 mod value2>
! (not)         <value>                 <0 if value non-zero, 1 otherwise>
` (greater)     <value1> <value2>       <1 if value1 > value2, 0 otherwise>
> (right)                               PC -> right
< (left)                                PC -> left
^ (up)                                  PC -> up
v (down)                                PC -> down
? (random)                              PC -> right? left? up? down? ???
_ (horizontal if) <boolean value>       PC->left if <value>, else PC->right
| (vertical if)   <boolean value>       PC->up if <value>, else PC->down
" (stringmode)                          Toggles 'stringmode'
: (dup)         <value>                 <value> <value>
\ (swap)        <value1> <value2>       <value2> <value1>
$ (pop)         <value>                 pops <value> but does nothing
. (pop)         <value>                 outputs <value> as integer
, (pop)         <value>                 outputs <value> as ASCII
# (bridge)                              'jumps' PC one farther; skips
                                        over next command
g (get)         <x> <y>                 <value at (x,y)>
p (put)         <value> <x> <y>         puts <value> at (x,y)
& (input value)                         <value user entered>
~ (input character)                     <character user entered>
@ (end)                                 ends program

befunge-93's People

Contributors

systemfw avatar

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.