A complete Befunge-93 interpreter with an interactive GUI debugger and development environment.
befunge-interpreter is a full-featured implementation of the Befunge-93 programming language with real-time visualization, interactive debugging, and comprehensive development tools. Befunge is a two-dimensional, stack-based esoteric programming language where the instruction pointer moves through a grid of characters.
Real-time execution with IP tracking, stack visualization, and interactive tooltips
- Full specification compliance - All standard opcodes supported
- Self-modifying code - Complete
p(put) andg(get) operations with extended 32-bit value storage - C-style arithmetic - Proper division and modulo semantics matching the specification
- String mode - Multi-line string support with proper grid navigation
- Wraparound navigation - Standard torus topology for IP movement
- Real-time visualization - Live IP tracking with syntax highlighting
- Interactive debugging - Breakpoints with Ctrl+Click, step-by-step execution
- Smart output window - Dedicated output with live stack visualization and intelligent docking
- Speed control - Configurable execution speed (1-500ms) and batch processing (1-50 steps/tick)
- Settings persistence - Per-file configuration automatically saved as
.befmeta.jsonsidecars
- Interactive tooltips - Hover over any opcode for instant documentation with formatted tables
- Professional keyboard shortcuts - Complete hotkey support (F5 run, F10 step, Esc stop, Ctrl+O open)
- Asynchronous I/O - Non-blocking input handling for
&and~operations - File validation - Smart detection of Befunge files with helpful error messages
- Window management - Smart docking system that follows main window movement
- Python 3.8+
- tkinter (usually included with Python)
# Clone the repository
git clone https://github.com/yourusername/befunge-interpreter.git
cd befunge-interpreter
# Run with file dialog
python main.py
# Open a specific file
python main.py examples/hello.bf
python main.py src/[program].bf.bf- Standard Befunge files.befunge- Alternative Befunge extension
- F5 - Run program (opens output window)
- F10 - Step through program one instruction at a time
- Esc - Stop execution
- Ctrl+O - Open file
- Ctrl+Click - Toggle breakpoint on any cell
- Open a Befunge file or start with a blank grid
- Set breakpoints by Ctrl+clicking on grid cells
- Adjust speed using the delay slider (1-500ms between steps)
- Run or step through your program while watching the stack and output
- Settings auto-save per file for seamless workflow resumption
- Hover tooltips - Mouse over any character for opcode documentation
- Live stack display - Watch stack changes in real-time with ASCII character preview
- Output management - Copy, save, or clear program output with autoscroll control
- Visual debugging - IP position (mint green), breakpoints (orange-red), hover cells (dark green)
befunge-interpreter/
βββ core/ # Interpreter engine
β βββ interpreter.py # Main interpreter with extended storage
β βββ InstructionPointer.py # IP management and grid navigation
β βββ stack.py # Befunge-specific stack with zero semantics
β βββ direction.py # 2D movement system
β βββ ops.py # Opcode dispatch table
β βββ types.py # Enums and data structures
β βββ utils.py # C-style arithmetic utilities
βββ ui/ # GUI components
β βββ app.py # Main application with smart docking
β βββ opcode_hovertips.py # Interactive tooltip system
β βββ opcodes.py # Opcode documentation and formatting
β βββ format_stack.py # Stack visualization utilities
βββ validate/ # Input validation
β βββ validate_load.py # File and content validation
βββ main.py # CLI entry point
| Category | Opcodes | Description |
|---|---|---|
| Arithmetic | + - * / % |
C-style arithmetic with proper truncation |
| Comparison | ` ! |
Greater-than and logical NOT |
| Directions | > < ^ v ? |
IP movement and random direction |
| Conditionals | _ | |
Horizontal and vertical if statements |
| Stack | : \ $ |
Duplicate, swap, pop operations |
| I/O | . , & ~ |
Integer/character output and input |
| Grid | g p |
Get and put for self-modifying code |
| Control | # @ " |
Bridge, halt, string mode |
| Literals | 0-9 |
Push digit values |
Self-Modifying Code with Extended Storage
- Values 0-255: Stored directly in grid as characters
- Values outside 0-255: Stored in shadow dictionary with grid showing low byte
- Full 32-bit integer support while maintaining visual grid fidelity
Intelligent Grid Management
- Automatic padding to 80Γ25 minimum (Befunge-93 standard)
- Original program dimensions preserved for visualization
- Efficient updates with revision tracking
>25*"!dlroW ,olleH">:#,_@&>:1-:v v *_$.@
^ _$>\:^>91+0p>:91+0g1+91+0p.91+0g9`#@_^Each Befunge file automatically gets a settings sidecar:
{
"version": 2,
"delay_ms": 50,
"steps_per_tick": 1,
"breakpoints": [
{"x": 0, "y": 0},
{"x": 15, "y": 0}
]
}- Incremental rendering - Only updates changed grid regions
- Batch processing - Execute multiple steps per GUI update
- Output streaming - Efficient handling of large program output
- Smart docking - Minimal window repositioning calculations
- Event-driven execution - Non-blocking with timer-based stepping
- Resource management - Proper cleanup and memory management
- Error handling - Graceful degradation with user feedback
- Cross-platform - Pure Python/Tkinter for maximum compatibility
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone and setup
git clone https://github.com/yourusername/befunge-interpreter.git
cd befunge-interpreter
# Run tests (when available)
python -m pytest
# Run with development options
python main.py --helpThis project is licensed under the MIT License - see the LICENSE file for details.
- Befunge-93 Specification by Chris Pressey
If befunge-gui doesn't meet your needs, consider these alternatives:
- bef - Command-line Befunge interpreter
- cfunge - High-performance C implementation
- pyfunge - Python Befunge-98 interpreter (different spec)
- jefunge - Web-based Befunge interpreter