100 Helloslanguages
Home / Languages / Befunge

Befunge

1993fraglet
esotericstack-basedtwo-dimensional.bf.b93.befunge
docker run --rm --platform="linux/amd64" 100hellos/befunge:latest

MCP + fragletc

MCPstdin
This language supports code execution via MCP and the fragletc CLI. Stdin piping is supported.
Install fragletc →

It is described as a cross between forth and lemmings wikipedia, and yes... those lemmings! The grid based instruction set combined with a stack-based operation and dataframe, results in mind-melting awesomeness.

Instruction List

0-9 	Push this number onto the stack.
+ 	Addition: Pop a and b, then push a+b
- 	Subtraction: Pop a and b, then push b-a
* 	Multiplication: Pop a and b, then push a*b
/ 	Integer division: Pop a and b, then push b/a, rounded towards 0.
% 	Modulo: Pop a and b, then push the remainder of the integer division of b/a.
! 	Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero.
` 	Greater than: Pop a and b, then push 1 if b>a, otherwise zero.
> 	Start moving right
< 	Start moving left
^ 	Start moving up
v 	Start moving down
? 	Start moving in a random cardinal direction
_ 	Pop a value; move right if value=0, left otherwise
| 	Pop a value; move down if value=0, up otherwise
" 	Start string mode: push each character's ASCII value all the way up to the next "
: 	Duplicate value on top of the stack
\ 	Swap two values on top of the stack
$ 	Pop value from the stack and discard it
. 	Pop value and output as an integer followed by a space
, 	Pop value and output as ASCII character
# 	Bridge: Skip next cell
p 	A "put" call (a way to store a value for later use). Pop y, x, and v, then change the character at (x,y) in the program to the character with ASCII value v
g 	A "get" call (a way to retrieve data in storage). Pop y and x, then push ASCII value of the character at that position in the program
& 	Ask user for a number and push it
~ 	Ask user for a character and push its ASCII value
@ 	End program

Hello World

64+"!dlroW olleH">:v
                 ^,_@

Coding Guide

Language Version

Befunge-93 (TBC — Tim's Befunge Compiler: transpile to C, then gcc)

Execution Model

  • Your fragment is the entire program (whole-file replacement). The playfield is 80×25; the instruction pointer starts at (0,0) moving right.
  • Code is compiled via tbc to C, then built and run.

Key Characteristics

  • Two-dimensional: instructions on a grid; execution can go left, right, up, down.
  • Stack-based (Forth-like).
  • Commands include: 0-9 (push), + - * / %, ! (not), ` (greater-than), > < ^ v (direction), _ | (conditional direction), " (string mode), : \ $ (dup, swap, pop), . , (output number / ASCII), # (skip), g p (get/put cell), & ~ (input number / character), @ (end).

Fragment Authoring

Write a complete Befunge-93 program. The entire file is your program; there is no template wrapper. Keep the playfield in mind (80 columns × 25 rows). Use @ to end the program.

Stdin

  • ~ — Read one character from stdin; push its ASCII value. On EOF, push -1.

  • & — Read an integer from stdin and push it.

  • Single character: ~,@ — read one character with ~, output with ,, end with @. Works everywhere.

  • Cat (echo all stdin): e.g. one line ~:0 then #@_,< — read with ~, stop on EOF (-1), else output with , and loop. Interpreter/compiler behavior may vary; the one-char form above is the most portable.

Command-line arguments

Befunge-93 has no notion of command-line arguments; input is via stdin only (e.g. ~ and &).

Common Patterns

  • Hello World: Push ASCII values in string mode, then output with , in a loop (e.g. 64+"!dlroW olleH">:v and ^,_@).
  • Cat (echo stdin): e.g. ~:0 then #@_,< on one line (backtick ` is the greater-than test).
  • Output number: . pops and prints as integer (with space).
  • Output character: , pops and prints as ASCII.

Caveats

  • Playfield is 80×25; long lines or many lines get truncated.
  • Your fragment replaces the whole file — no markers, no template.
  • Compilation (tbc + gcc) runs on every execution; build errors appear on stderr.

Fraglet Scripts

Factorial

#!/usr/bin/env -S fragletc --vein=befunge
512*3*4*5*.@

Squares

#!/usr/bin/env -S fragletc --vein=befunge
11*.:22*.:33*.:44*.:55*.:@

Stdin Echo

#!/usr/bin/env -S fragletc --vein=befunge
~,@

Stdin Upper

#!/usr/bin/env -S fragletc --vein=befunge
~,@

Test

#!/usr/bin/env -S fragletc --vein=befunge
64+"!dlroW olleH">:v
                 ^,_@

Connections

influenced by

Container Info

image100hellos/befunge:latest
build scheduleFriday
fragletenabled