(0,0)
New Load Save Grid Size
Edit mode Run Syntax Coloring Flow Visualizer
Clipboard (Ctrl+click on grid)
Direction: Right (Shift+Right Cursor Key) Left Down Up
Mode: Code String Insert
Start Pause Stop Next Step Trace Cursor Movement
Grid Annotate Stack Terminal Input Box
Help About Settings

Speed: 🐢🐇

jsFunge IDE

GridClose
StackClose
InputClose
TerminalClose
ImportClose
Select a program to import:
Load File from My ComputerDelete ProgramCancelOK
ExportClose
Program Name: Author:
Copy this link to share this program:
Save Plaintext to My Computer Save to this Browser Save to Address Bar OK
HelpClose
Befunge-93 GuidejsFunge IDE Guide

What is Befunge-93?

Befunge is a stack-based, reflective, esoteric programming language. It differs from conventional languages in that programs are arranged on a two-dimensional plaayfield. "Arrow" instructions direct the control flow to the left, right, up or down, and loops are constructed by sending the control flow in a cycle.

For more informations, see the wikipedia page.


Instruction set

Flow direction:

  • >  Start moving right
  • <  Start moving left
  • v  Start moving down
  • ^  Start moving up
  • ?  Start moving in a random direction

Mathematical and logical operations:

  • +  Addition: pop a and b, and then push a+b
  • -  Subtraction: pop a and b, and then push b-a
  • *  Multiplication: pop a and b, and then push a*b
  • /  Division (integer): pop a and b, and then push b/a
       If a is 0, ask user for desired result.
  • %  Modulo: pop a and b, and then push b%a
       If a is 0, halt and catch fire
  • !  Logical NOT: pop a value. If the value is zero,
       push 1; otherwise, push zero.

Tests:

  • `  Greater than: pop a and b, then push 1 if b>a,
       otherwise push zero.

Jumps:

  • _  Pop a value; move right if value=0, left otherwise.
  • |  Pop a value; move down if value=0, up otherwise.
  • #  Skip the next cell

Stack operations:

  • 0-9  Push the number on the stack
  •   :  Duplicate value on top of the stack
  •   $  Pop a value from the stack
  •   \  Swap two values on top of the stack.

Input / Output:

  • .  Pop value and output as an integer.
  • ,  Pop value and output as an ASCII character.
  • p  Put: pop y, x and v, then set position (x,y) in
       the playfield to the value v (truncated to
       a signed byte.)
  • g  Get: pop y and x, then push the value at that
       position in the playfield.
  • &  Push to stack user input interpreted as a decimal number.
  • ~  Push to stack one character of user input.

Other instructions:

  • "  Start string mode: push each character's ASCII
       value all the way up to the next ".
  • @  The end of the program.

Interesting links

How to Use This IDE

This IDE has several features which may not be obvious at a first glance.


Toolbar

Program Options

  • New  Switch to edit mode and clear the grid
  • Load  Open a dialog where you can select
           an example to load
  • Save  Open a dialog where you can copy a URL
           that will let you share or save your program
  • Grid Size  Open a dialog where you can change
           the dimensions of the grid

  • Edit mode  Switch to Edit Mode
  • Run  Switch to Run Mode
  • Syntax Coloring  Turn on Syntax Coloring
  • Flow Visualizer  Turn on Flow Visualization

Edit Mode Options

  • Clipboard (Ctrl+click/long press/drag on grid)  Open the Clipboard dialog
  • RightLeft DownUp  Select the direction the cursor will
                            move when typing on the grid.
  • Code  Switch to Code Typing mode
  • String  Switch to String Typing mode
  • Insert  Toggle Insert Typing mode

Run Mode Options

  • Start  Start the program running
  • Pause  Pause a running program
  • Stop  Halt and reset a running or paused program
  • Next Step  Advance the program a single step
  • Trace Cursor Movement  Toggle Cursor Tracing Mode
  • Speed Slider  Set the speed the program runs
                             Faster speeds won't show every step

Windows and Dialogues

  • GridGrid  Show the Grid/Text window if it is hidden
                In Edit Mode, toggle between text/grid mode
  • AnnotateShow the dialog to annotate cells.
  • Stack  Show the Stack window if it is hidden
  • Terminal  Show the Terminal window if it is hidden
  • Input Box  Show the Input Box window if it is hidden

  • Help  Show this window if it is hidden
  • About  Show the About window if it is hidden
  • Settings  Show the Settings window if it is hidden

Global Features

Windows

Windows and Dialogs can be dragged around by their title bars and hidden by choosing the X in the corner. They can always be shown again from the toolbar.

Certain windows (Stack, Grid, and Terminal) can be resized as you prefer by dragging their lower right corners. The Grid window cannot be larger than just enough to contain the grid.

Cursor Position

In the bottom left corner of the page, a small box always shows the current coordinates of the cursor and the current numerical value of the cell it is in. Although the cursor cannot be moved by clicking in a running program, clicking a cell will still update the contents of this box.

Syntax Coloring and Flow Visualization

Add context-aware colors to the grid to help you visualize. May slightly lag input when updating.

Grid Size

You can use the Grid Size Dialog to resize the grid in any mode. You can give the grid any number of rows or columns. Resizing the grid will never destroy any part of the program currently on the grid without confirming with you first.

Input Box

Open the Input Box Window and type anything you want into the box if you would rather feed a fixed input to your program when it runs than provide interactive input through the terminal. As with most Befunge implementations, if your program tries to read more input than this box contains, it will receive a -1 as EOF instead. Clear the box to return to interactive input mode.

Import Program

From this dialog, you can load the programs that are saved in your browser cache. Importing a program will overwrite the contents of the grid and possibly try to resize it as well. Save your work before doing this! You can also individually delete the programs on this list from your cache if you do not need them.

There are a number of example programs already pre-loaded into your cache. Take a look at these examples to get a better idea of how the language works.

You can also open a plaintext program saved on your filesystem using the button so labeled.

Export URL

You can share the URL from the export URL box to allow anyone to see or edit your program. The link will also preserve your current grid size settings.

If you select Save to Address Bar, your browser will be redirected to the link, thereby saving it in your browser history. (This will destroy any breakpoints you had set.)

If you select Save to My Browser, the program will be permanently saved in the cache of this browser on this device and will appear as a loadable option in the import dialog.

If you select Save Plaintext to My Computer, a file will be downloaded to your computer containing a plaintext version of the program. It will also contain any annotations. You will need to delete these manually to run the program in another interpreter, but the file will open just fine in jsFunge.

Annotations

Use the annotations dialog to add comments to your code. The annotation will be attached to whichever cell is selected when the button is pressed. The cell will be marked with a small green box in the corner and the annotation will appear in the title text (that appears when you hover over a cell) and, if the cell is selected, in the box in the bottom left corner. If you export an annotated program to a URL, the annotations will be exported with it. To remove an annotation from a cell, simply attach a blank (empty) annotation to it.

Settings

Global options are set in this window.

The Befunge-97 instructions checkbox toggles the availability of the hex number instructions a through f and the single character mode instruction ' (single quote)

The Non-blocking interactive keyboard I/O checkbox toggles a mode in which the key code of any non-special key pressed while a program is running is appended to the input buffer and the ~ command never blocks for input (instead pushing -1 if the buffer is empty). This makes realtime interactive programs possible. Note that in this mode, ~ will be reading key codes, not characters typed, and it will only ever read the last 4 keys pressed, so if you do not poll it fast enough, you may miss some keystrokes.

The Skip non-commands while running checkbox will make a running program leap from one command to the next, skipping over whitespace and anything not in the Befunge instruction set. This makes execution faster but cursor movement somewhat harder to follow.

The Reflow color map when a p could change flow checkbox will cause a reflow of syntax coloring and flow visualization on every alteration of the grid by a running program by the p command that could potentially alter the future behavior of the program. Useful for programs that edit themselves to alter their own control flow. This option can slightly reduce the running speed of such a program.

The Reflow color map every cycle while running (very slow) checkbox forces a reflow of syntax coloring and flow visualization on every major cycle of a running program. This can make clear which parts of a program are purely for initialization (as they become unreachable after they are executed). However, this option significantly lowers the speed of a running program.

The Suppress errors checkbox prevents non-fatal errors from being logged to the terminal.


Edit Mode Features

While typing on the grid, the cursor will always move in the direction selected on the toolbar, wrapping around the edges of the grid as needed. Typing Backspace will move the cursor in the opposite direction before clearing the cell. Certain other keys have variant behavior depending on the Typing Mode.

Code Typing Mode

Select Code Typing Mode by choosing Code on the toolbar.

In Code Typing Mode, typing any of the characters <,>,^, or v will change the typing direction and then move in that direction. Typing " will toggle on String Typing Mode.

String Typing Mode

Select String Typing Mode by choosing String on the toolbar.

In String Typing Mode, the cursor will continue in the current direction regardless of what is typed. Typing " will toggle on Code Typing Mode.

Insert Typing Mode

Select Insert Typing Mode by choosing Insert on the toolbar or by pressing the Insert key.

When Insert Typing Mode is off, typing on a cell replaces its contents. Hitting Delete behaves the same as hitting Space.

When Insert Typing Mode is on, typing on a cell shifts everything in the current row or column in the current typing direction, placing the typed character in the newly vacated cell. But the grid has a fixed size, so a character must be overwritten somewhere in that row or column. In this mode, the last space character in that direction is overwritten. If there are no space characters in the current typing direction, attempting to type in Insert Typing Mode will fail to avoid accidentally destroying parts of your program. However, you can still accidentally destroy significant whitespace using this mode. Be careful!

In Insert Typing Mode, pressing Delete will not move the cursor, but instead will shift the entire row/column in the current direction backwards towards the cursor. Pressing Backspace will both move the cursor backward and shift the row/column backwards towards it, overwriting the previous character.

Always check the current typing direction before typing in Insert Typing Mode!

Keyboard Shortcuts

A number of quick keyboard shortcuts are available while editing the grid.

  • Home  Move cursor to the first column of the current row
  • End  Move cursor to the last column of the current row
  • Page Up  Move cursor to the first row of the current column
  • Page Down  Move cursor to the last row of the current column
  • Insert  Toggle Insert Typing Mode
  • Shift+[Any Cursor Key] Set the current typing direction
  • Alt+Shift+R  Switch to Run Mode and start the program running
  • Alt+Shift+S  Open the Export URL dialog

Text Editing Window

Select the Text Window (Grid) option from the toolbar to transform the grid into a simple textbox containing your program.

In the plaintext editing window, you can select all the text in the program, copy it, and paste it elsewhere for safe-keeping or to try out another interpreter. You can also replace the program by pasting in programs from other sources. Any changes made to the text here will be loaded into the grid when you switch back to the Grid Editing Window. Using any of the grid-specific features (like the Export URL and Grid Size dialogs) will automatically switch back to the Grid Editing Window for you.

If the contents of the textbox (not counting trailing whitespace) will not fit in the grid at its current dimensions, switching back to the Grid Editing Window will give you the option to resize the grid to fit it.

Note that if your program is annotated, the annotations will also appear here below a line of semicolons. You can edit all annotations here easily. You could add new annotations here if you wanted, though it is not particularly convenient to do so.

Clipboard

Use the clipboard window (Clipboard (Ctrl+click on grid)) to manipulate subgrids. This is a very complicated and powerful feature. Here is how you use it:

First, ensure that the cursor is in the location you want to the top left corner of the selection to be. Then click the Set top left corner of selection to cursor location button. Then, ensure the cursor is in the location you want the bottom right corner of the selection to be and click the Set bottom right corner of selection to cursor location button. This will both enable the fine selection adjustment controls and reveal the selection transformation controls while the unselected regions are grayed out in the Grid window.

Note that because the Befunge playfield is a torus, the bottom right corner of the selection can be above and/or to the left of the top left corner!

Tip: Clicking on the top left corner grid cell, dragging to the bottom right corner cell, and releasing will skip these two steps and open the window with all features already enabled. Likewise, holding the ctrl key when clicking or long-pressing a grid cell will set the clicked cell to the lower right corner and the cursor location as the top left corner.

The fine selection adjustment controls will allow you to independently move the bounds of the selection bounding box in either direction so that your selection contains exactly the intended cells. Use the displayed row and column counts if you need to ensure the selection is square.

The selection transformation controls provide a number of ways to manipulate the selection:

In the middle is a textbox containing a textual representation of the current selection. Edits to this textbox will be mirrored to the grid and vice versa. Because the contents of the box will always be cropped to the selection size, you never need to worry about accidentally overwriting unselected parts of the grid. You can paste text representations of programs that contain annotations and the annotations corresponding to cells in the cropped selection will be added as well.

The long skinny buttons with arrows translate the selection one cell in the indicated direction by swapping it with the section of the next row or column in that direction. This may cause the surrounding grid to be rearranged in unexpected but entirely intended ways.

The square buttons around the textbox will apply the seven non-identity transformations of the dihedral group of the square. Transformations that would swap the dimensions of the selection (transposes and 90 degree rotations) are only allowed for square selections. Because certain operations in Befunge-93 lack these symmetries, some of these transformations can change the semantics of the transformed subprogram. You will be warned when a transformation is likely to alter semantics.

The Export selection to new tab button will open a new tab and load a new instance of the app containing only the selected subprogram.

The Copy selection to clipboard button will put a trimmed version of the selection including annotations into your clipboard. This is a much more convenient text representation of the selection than the one you would get by selecting and copying the text in the selection textbox.

Run Mode Features

In Run Mode, you cannot edit the contents of the grid nor can you set the location of the cursor. However, there are some things you can do here that you cannot do in Edit Mode.

Breakpoints

Set a breakpoint by double-clicking or long-pressing on a cell. The cell will turn crimson when it is a breakpoint. Breakpoints persist even if you switch to Edit Mode and back, though they will not be visible in Edit Mode. There is no problem with toggling a breakpoint while a program is running.

When the cursor of a running program reaches a breakpoint cell, the program will pause automatically.

Cursor Tracing Mode

Turn Cursor Tracing Mode on by clicking the Trace Cursor Movement icon on the toolbar. In this mode, while a program is running, the cursor will recolor each cell it touches in a progression of hues. This will allow you to see the execution paths of a program even when the speed is set too high to watch each move the cursor makes. These colors will persist until you next start the program again, even if you turn Cursor Trace Mode off and on again or switch to edit mode and back again (even though either of these actions will temporarily hide the colors).

Note that Cursor Tracing Mode and Flow Visualization mode cannot both be used at the same time for reasons that should be obvious, although one can switch between the two modes freely. What's the difference between them? Flow Visualization shows all the possible paths the IP could follow and colors the entire path between consecutive branches the same color, while Cursor Tracing shows only the path the IP actually followed colored with a smooth gradient to make direction of motion clearer.

Keyboard Shortcuts

A number of keyboard shortcuts are available in Run Mode.

  • Alt+Shift+E  Halt and reset the program and switch to Edit Mode
  • Alt+Shift+S  Open the Export URL dialog
  • Alt+Shift+C  Immediately halt and reset the program

All of these shortcuts will work even while the program is waiting for interactive input in the terminal.

About jsFunge IDEClose
jsFunge IDE logo

jsFunge IDE 0.1

A Befunge 93 Editor, Interpreter and Debugger

Copyright © 2011 Fabien LOISON

Updated 2021 David Rutter

Original version of this software: http://software.flogisoft.com/jsfunge

This software makes use of xterm.js: License and Copyright

This software makes use of a version of local-echo modified by David Rutter: License

This software makes use of file-saver: License

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

InputClose
Set grid dimensions: X
CancelOK
SettingsClose
Befunge-97 instructions
Non-blocking interactive keyboard I/O
Skip non-commands while running
Reflow color map when a p could change flow
Reflow color map every cycle while running (very slow)
Suppress errors
AnnotationsClose
Attach annotation to selected cell
ClipboardClose
Set top left corner of selection to cursor location Set bottom right corner of selection to cursor location
Fine Selection Adjustment:
🠽
🠿
🠼
🠾
🠽
🠿
🠼
🠾
 
 
Deselect

Flip selection across main diagonal
Flip selection horizontally
Flip selection across anti-diagonal
Flip selection vertically
Rotate selection 90° counterclockwise
Rotate selection 180 degrees
Rotate selection 90° clockwise
🠽
🠿
🠼
🠾
Copy selection to clipboardExport selection to new tab