Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Forth is a stack-based language from 1970, invented by Chuck Moore, in which programs are built by defining new words from a dictionary of existing ones and data flows through an explicit stack instead of named variables. Its tiny footprint made it the language of choice for spacecraft instruments, Sun's OpenBoot firmware, and the Open Firmware standard still lurking in boot ROMs. Modern development happens mostly in Gforth, the GNU implementation of ANS Forth. Forth rewires how you think about composition and state, and the fastest way to feel it is to run it: this page executes your Forth source in a live terminal where words like ACCEPT genuinely block for your typed input.
( Define new words from smaller ones )
: square ( n -- n^2 ) dup * ;
: cube ( n -- n^3 ) dup square * ;
: greet ( -- )
." What is your name? "
pad 80 accept
cr ." Hello, " pad swap type ." !" cr ;
: table ( n -- )
1+ 1 do
i . ." squared: " i square . ." cubed: " i cube . cr
loop ;
greet
." Powers table:" cr
4 table
bye
Forth appears in programming-languages courses as the canonical concatenative language, in embedded and firmware engineering where Open Firmware and FreeBSD's old boot loader used it, and in resource-constrained retro platforms where a full compiler will not fit. Students use this page to internalize stack manipulation words like dup, swap, and rot before writing larger definitions, and language implementers study it because a Forth interpreter is a classic weekend project. It also attracts code golfers and recreational programmers who enjoy factoring problems into tiny composable words.
Yes. The word ACCEPT reads a line into a buffer, blocking the live terminal until you press Enter: pad 80 accept fills the scratch buffer and leaves the character count on the stack, which you then print with type. Single characters can be read with KEY, enabling simple interactive menus and games.
The page executes source with Gforth, the GNU project's ANS Forth system, so standard core words, DO loops, CREATE/DOES>, and the usual string words behave per the ANS standard. Gforth-specific conveniences are also present. End scripts with bye so the interpreter exits cleanly instead of waiting for more input.
Forth uses reverse Polish notation: operands go on the stack first, then the word that consumes them, so 3 4 + leaves 7. There is no operator precedence and no parentheses because evaluation order is literally the order you write. The stack-effect comments like ( n -- n^2 ) are the community's convention for documenting what each word consumes and produces.
main.fthtext/x-forthaccept / key: greet ." Hello from Forth!" CR ;
: welcome ." Welcome to XCODX Compiler!" CR ;
greet
welcome
5 3 + ." Sum of 5+3 = " . CR