Forth (programming language)

Forth is an imperative, stack-based programming language. A Forth system includes an operating system for process and a development environment for the creation of Forth programs. Therefore, it is called an actually implemented Forth on a computer, a Forth system. Many versions generate today, as in other programming languages ​​, highly optimized machine code.

Genesis

Charles H. Moore Forth developed in the years before 1969 from a self-written mini- interpreter. This interpreter already contained many properties of the later programming, but was dependent on an underlying operating system. Moore used it as a macro language for programs that he wrote in FORTRAN, ALGOL, PL / I and Assembler. The computer technology that period changed just by large computers working in batch mode to mini computers that would allow also interactive work. Moore wrote in 1968 in addition to his actual work for an IBM 1130 minicomputer finally a chess program, which he had previously coded in Algol, in his interpreter language. The chess program was much simpler to port and Moore called his language now for the first time FORTH. Originally the language FOURTH should read because it was actually intended for the fourth-generation computers, which were expected to be sold as a microcomputer. The operating system on which Moore programmed, but only the file name with a length of five letters was about why they chose the homophone FORTH.

The peculiarity of a comprehensive solution of the programming language and operating system can be well explained by the Genesis out. Moore had to control the 11- meter radio telescope of the National Radio Astronomy Observatory ( NRAO ) at Kitt Peak in Arizona two Honeywell computer without adequate software, a 16 kB DDP -116 and a 32 kB H316. He had set out to program all necessary components themselves, which are necessary for convenient programming and safe operation of the computer. These include an operating system, a high-level language and development environment. All these components have been realized within a single program - the Forth system. Both computers were responsible for the control of the telescope and its scientific instruments, they supervised the positioning and tracking, collecting and recording data on magnetic tape, and supported an interactive graphics terminal ( Tektronix 4002A ) on the analysis of the recorded data, the astronomers and as could print hard copy. The multi-tasking nature of the system allowed the simultaneous expiration of these functions without causing interference occurred or run-time conflicts. Overall, the system worked so well that astronomers from around the world were interested in it and wanted to have a copy. Its use spread quickly, and 1976 Forth was adopted as the standard language by the International Astronomical Union.

The procedure of a so-called "all-in -one solution " but has remained a special path of Forth. Even programming languages ​​such as Smalltalk or Self go (usually ) not so far as to replace the operating system. Although this would be possible, usually one wishes portability. The programming language Oberon, which was developed as part of the Ceres - system, is independent of this available. Like Forth, only the programming / operating system package EUMEL and ELAN got lost. Normally, the above components are designed and developed separately.

Forth system

A complete Forth system can be realized with only a few kilobytes of memory. This property was at the time when extremely important because the computer at that time had relatively little RAM available. In addition, the actual core of the Forth system is very small and the rest of the system is already defined itself in Forth. A port of the Forth system to other processors is considerably easier. This positive property has provided a relatively large spread in the late 1970s Forth.

Today this makes forth to a high level language which is particularly suitable for programming the various micro-controller. For the development of combined systems but it used in which the intermediate code pre-compiled on a host PC and is merely the result of the client is stored in the microcontroller. This allows some of the interactive features of the Forth system accounts and the source code can be commented comprehensive.

The essential elements of the internal Forth architecture are the two stack (data stack and return stack ), a set of registers and the dictionary, which can be simulated independently of the hardware and a jump table that associates the token with the each function to call. The data word stored on the stack is called a cell, wherein said 16, 32 or 64 bits can be large. Moreover, the dictionary can be divided into a plurality of vocabularies as desired. The Forth system itself is implemented as a virtual machine. All statements and mathematical expressions are formulated in Reverse Polish Notation (RPN ). This follows simply from the fact that the Forth system first checks for each input value, if it is present in the dictionary. If this is the case, the corresponding function is called, which can then access all the entries made so far. If the value is not present in the dictionary, it is interpreted as a numerical value or character string. The following entries have not yet been read in both cases at this time and therefore on the program execution still no effect. One can therefore also, as is usual at the time of formation of the input data stream easily realized by a sequential medium such as a punched card or a magnetic tape stack.

Forth has two main features that distinguish it from many other programming systems of his time:

  • Forth from the start was Public Domain
  • Forth is self- compiling, allowing them the user direct access to the compiler, so that the command structure can be extended

Programming in Forth

The programming in Forth is fundamentally different from other languages. In Forth there is no difference between integrated and programmed functions (see g words ). There expire no immediate routines, the language is instead extended to include additional words. The start of a program corresponds in Forth recall of a word, which thus represents the main routine of the program. Since the compiler is extended by the fact by defining words that occur in the development environment and thus manipulate the intermediate code directly, which leads to a flexibility that has been achieved with any other high-level language before.

Example of a UPN expression

For the calculation of the expression ( 5 3) * (7 2 ) is entered, the following sequence in Forth:

5 3 2 7 *. The processing of the expression takes place already when reading. The input string is divided spaces in words. The word " 5" is usually not in the dictionary, it is interpreted as a number, set the corresponding value on the value stack. The same is true for the word " three ". The word is now following " " is, however, exists in the dictionary. It is therefore called the function. This function takes the top two values ​​from the stack, adds them, and pushes the result back on the stack. Small " " function is usually implemented in the respective machine language. On the stack is now the number 8, the next word is "7", it is the number 7 on the stack. Followed by the word " two ", in this case the number of lands 2 on the stack. Next, again the word " ", whereby the addition function is called again. on the stack is now uppermost, the number 9, including the number 8 Then the word "*" read that is linked in the dictionary with the multiplication function. This function takes the top two numbers from the stack and puts their product on it. The multiplication function can be depending on the Forth system as machine code or turn already implemented in Forth. The next word read is now ". ". This word takes the top value ( now the number 72) from the stack and outputs it to the display device.

Words for stack operations

Forth is suitable for interactive development of control systems, which allow for different processes, such as:

The earliest known uses were controls for radio telescopes and observatories for astronomy and space, other applications in scientific and technological matters were added later.

Forth implementations and derived languages

The porting of Forth on the Apple II personal computer in the 1970s, led by the programmer John T. Draper, so he developed the Easy Writer word processor. A graphics-capable extension of Forth for the Apple II was GraFORTH. ASYST was an extension of Forth for measuring and controlling of personal computers.

Factor is a building on the Forth programming language, but focuses more on application development than on the low-level functionality of Forth. A modern application of Forth is the concept of Open Firmware (IEEE -1275 ).

A further development of Forth is Inter Press from Xerox, which in turn developed the Adobe page description language PostScript. The PDF later also developed by Adobe leans Although strongly PostScript to (and could thus be regarded as the great-grandson of Forth ), but is in contrast to PostScript and Forth not a complete programming language.

  • Amforth - for the Atmel ATMega microcontrollers (GPL )
  • AmrFORTH - 8051 Tethered Forth for Windows / OSX / Linux / * BSD
  • KForth - Small Forth interpreter written in C
  • PropForth - for the Parallax Propeller microcontroller
  • Reverse Polish Lisp ( RPL) - for HP48/49-Taschenrechner
  • Herkforth - a colorForth for Linux / PPC
  • Computer Intelligence Forth - a program written in assembler ISO Forth
  • PFE - Portable Forth Environment
  • Pug - a development environment for the Apple Macintosh, based on Forth
  • Reva - for x86 processors (32-bit, multi -platform compliant )
  • SP- Forth - Open Source Forth for Win32 and Linux
  • MVP Forth - source code available, of Mountain View Press
  • VolksFORTH - a system of Forth eV Society
  • Win32Forth - Public Domain, for Windows ( 32-bit)
  • Delta Forth. NET - Forth compiler for the NET platform.
  • EForth - Learning system for computer science
  • Swift Forth and SwiftX - professional FORTH for PC and microcontroller
  • IForth - Shareware, multi-platform capable compiler for 32 and 64 bit
  • ColorForth - for the PC, Floppy-Image-Extracter/Source-Reader.
  • BigFORTH - x86 native code Forth with GUI MINOS
  • Gforth - GNU Forth, multi-platform capable interpreter ( 32-bit)
  • VFX Forth - professional, cross-platform Forth compiler
  • Retro Forth - Public Domain, for DOS, Linux, FreeBSD, Windows or standalone
  • PForth - PD portable Forth in 'C' for embedded systems or desktop.
343317
de