JDT |
FREE Downloads |
|
Forth |
|||||
|
Forth is a structured, imperative, stack-based, computer programming language and programming environment. 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 implementations (usually early versions or those written to be extremely portable) compile threaded code, but many implementations today generate optimized machine code like other language compilers. HistoryForth evolved from Charles H. Moore's personal programming system, which had been in continuous development since 1958. Forth was first exposed to other programmers in the early 1970s, starting with Elizabeth Rather at the US National Radio Astronomy Observatory. After their work at NRAO, Charles Moore and Elizabeth Rather formed FORTH, Inc. in 1973, refining and porting Forth systems to dozens of other platforms in the next decade. Forth is so named because in 1968 "the file holding the interpreter was labeled FOURTH, for 4th (next) generation software - but the IBM 1130 operating system restricted file names to 5 characters." Moore saw Forth as a successor to compile-link-go third-generation programming languages, or software for "fourth generation" hardware, not a fourth-generation programming language as the term has come to be used. Because Charles Moore had frequently moved from job to job over his career, an early pressure on the developing language was ease of porting to different computer architectures. A Forth system has often been used to bring up new hardware. For example, Forth was the first resident software on the new Intel 8086 chip in 1978 and MacFORTH was the first resident development system for the first Apple Macintosh in 1984. FORTH, Inc's microFORTH was developed for the Intel 8080, Motorola 6800, and Zilog Z80 microprocessors starting in 1976. MicroFORTH was later used by hobbyists to generate Forth systems for other architectures, such as the 6502 in 1978. Wide dissemination finally led to standardization of the language. Common practice was codified in the de facto standards FORTH-79 and FORTH-83 in the years 1979 and 1983, respectively. These standards were unified by ANSI in 1994, commonly referred to as ANS Forth. Forth became very popular in the 1980s because it was well suited to the small microcomputers of that time, as it is compact and portable. At least one home computer, the British Jupiter ACE, had Forth in its ROM-resident operating system. Rockwell also produced single-chip microcomputers with resident Forth kernels, the R65F11 and R65F12. OverviewA Forth environment combines the compiler with an interactive shell. The user interactively defines and runs subroutines, or "words," in a virtual machine similar to the runtime environment. Words can be tested, redefined, and debugged as the source is entered without recompiling or restarting the whole program. All syntactic elements, including variables and basic operators, appear as such procedures. Even if a particular word is optimized so as not to require a subroutine call, it is also still available as a subroutine. On the other hand, the shell may compile interactively typed commands into machine code before running them. (This behavior is common, but not required.) Forth environments vary in how the resulting program is stored, but ideally running the program has the same effect as manually re-entering the source. This contrasts with the combination of C with Unix shells, wherein compiled functions are a special class of program objects and interactive commands are strictly interpreted. Most of Forth's unique properties result from this principle. As a "jack of all trades" including interaction, scripting, and compilation, Forth was popular on computers with limited resources, such as the BBC Micro and Apple II series, and remains so in applications such as firmware and small microcontrollers. In this way, Forth is broadly comparable to BASIC, but emphasizing optimization over ease of use. Where C compilers may now generate code with more compactness and performance, Forth retains the advantage of interactivity. Certain words are predefined, including the basic arithmetic operators. Predefined words which may be used at runtime are collectively called the "kernel." When the user starts an interactive Forth environment, it typically consists of the kernel and the interpreter. The compiler comprises a set of commands within the interpreter. Most of the ANS Forth standard is devoted to defining the contents of the kernel and the interface to the compiler. The standard's main syntactic requirement is that words are executed in sequence. Here is an example of a programmer "developing" the hello world program. By convention, source code examples are written as a log, showing the programmer's input and the interpreter's response. Interpreters traditionally say "OK" after the successful completion of a command line. .( Hello, World!) Hello, World! ok : hello-world ." Hello, World!" ; ok hello-world Hello, World! ok In the first line, the text output operator .( is used interactively to immediately produce the output Hello, world!. The space after the ( lets the interpreter parse the operator as a separate word and the ) signals the end of the string. Next, the colon (:) is used to activate the compiler and store the same code, including the string itself, into the word hello-world. Finally, the programmer activates the newly defined word to verify that it produces the expected output. Many Forth systems would allow ." to be used in place of .( for consistency. Article source: http://en.wikipedia.org/wiki/Forth_programming_language Go back to Programming Articles home page
|
|