Forth Programming

Other Free Books!
Free Computer Books Alliance
Agile Programming
3D Rendering
3D Graphics Libraries
Remember that these titles are copyright © the author or the publisher. The author / publisher has generously allowed them to be available for free online. Please respect the terms and conditions of the copyright.


A Beginner's Guide To Forth J.V. Noble
Programming Forth Stephen Pelc
Thinking Forth Leo Brodie

Non-Book Resources

Forth is a programming language and programming environment, initially developed by Charles H. Moore at the US National Radio Astronomy Observatory in the early 1970s. It was formalized in 1977 and standardized by ANSI in 1994. Forth is sometimes spelled in all capital letters following the customary usage during its earlier years, although the name is not an acronym.

A procedural, stack-oriented and reflective programming language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers.

Forth is so named because "the file holding the interpreter was labeled FORTH, for 4th (next) generation software - but the operating system restricted file names to 5 characters."Moore's use of the phrase 4th (next) generation software appears to predate the definition of fourth-generation programming languages; he saw Forth as a successor to compile-link-go third-generation programming languages, or software for "4th generation" hardware, not a 4GL as the term has come to be used.

Forth offers a standalone programming environment consisting of a stack-oriented, interactive, incremental interpreter and compiler. Programming in Forth is an interactive, iterative process. A Forth system consists of words (the term used for Forth subroutines); new words are defined in terms of old words, and there is no distinction made between the words that define the Forth language and those that the programmer creates. A typical Forth package consists of a pre-compiled kernel of the core words, which the programmer uses to define new words for the application. The completed application can be saved as an image, with the new words already compiled. Generally programmers extend the initial core with words that are useful to the types of applications that they write, and save this as their working foundation.

Forth uses separate stacks for storage of subroutine parameters and subroutine activation records. The parameter or data stack (commonly referred to as the stack) is used to pass data to words and to store the results the words return. The linkage or return stack (commonly referred to as the rstack) is used to store return addresses when words are nested (the equivalent of a subroutine call), and store local variables. There are standard words to move data between the stacks, and to load and store variables on the stack.

The logical structure of Forth resembles a virtual machine. Forth, especially early versions, implements an inner interpreter tracing indirectly threaded machine code, giving compact and fast high-level code that can be compiled rapidly. Many modern implementations generate optimized machine code like other language compilers.