New Micros, inc offers new MCORE board with FORTH



Max-FORTH IN A NUTSHELL

Max-FORTH closely follows the basic human methodology for dealing with language. Learning a “human” language starts with understanding a few simple word. (I.e.: YES, NO, STOP, GO, etc.). Next, phrases are made from those words. The meanings of phrases are named, and new words are born. Then, larger, more complex concepts are built from these simple beginnings.  Complicated words are defined in terms of simpler words. Using the basics, larger and larger concepts are built as vocabulary grows. (E.g. from the few words given above, STOP GO STOP means JERK.)

Suggesting the closeness of this linkage, the program segments in Max-FORTH are called words and are kept in a structure, called the dictionary. The dictionary is a linked list with all known words in the language. Max-FORTH provides a starter set of over 300 words. These are the basics, just enough to begin describing a programming task comfortably. Each word has a very precise meaning, not at all ambiguous. To learn Max-FORTH, a few of these words must be understood. From these simple words, low level phrases can be described. The phrases are given names.  Newly defined words can be used in more complex definitions by their name. As the programming task progresses, the number of known words grows. While the later words can be more complex, they are generally easier to understand in terms of named purpose, more like the natural language equivalent.

The last word added to the dictionary fully describes the program to be run. It does so in terms of words already known, which are further described by other, underlying words, etc. The pyramiding structure of lower words can be followed backwards until segments “understandable” by the CPU (i.e.: machine code) are reached. Those machine-coded words were provided in the basic word set already defined in Max-FORTH (The process of descending, from compiled word-pointer, to the next compiled word-pointer, until finding machine code, is called threading.)

A Max-FORTH programmer describes the programming problem by adding new definitions (or words, for short) to the dictionary.  They are defined in terms of the words already built into the language, which the machine knows how to translate. The new words are added to the linked list. They become part of the language, describing the problem in terms the computer “understands”. As words are added, the dictionary grows. Each added word describes another part of the program more succinctly. A word in Max-FORTH can be evoked by stating its name interactively. When the program is finished the whole program has one name. The program can be invoked by entering its name.

To facilitate dedicated applications, a word can also be started when the computer is reset. An autostarted word has a special demarcation, a recognition pattern and a pointer left in memory, which indicates to the Operating System it should be run.  Max-FORTH itself is autostarted in this manner, by the Operating System, if no other autostarted word is found.

Most programs for dedicated applications, are endless loops. The endless loop of the Max-FORTH  development language is called the Outer Interpreter. This structure initializes the system, then, repeatedly accepts an input line, translates it, returns for another line, etc.

The syntax of Max-FORTH  is remarkable simple. The language is practically free form. The syntax is simply stated: Everything input to the Outer Interpreter is either a word or a number. If the input is not a known word or translatable as a number, it is an error. (The strings found meaningless are echoed back, followed by a question-mark.) Words and numbers are delimited by spaces.

It would be easy to be misled to believe there is more syntax associated with the Outer Interpreter. There is not. Words sometimes have actions in themselves which gives the appearance of syntax. For instance, comments appear to have a syntax. They start with a “(“ and end with a “)”. A casual reader of Max-FORTH  code will be happily able to read most listings, by knowing the things between free standing “(“ and “)”s are comments. It is not an action of the language that renders them as an uninterpreted string, but rather the action of the word “(“ which throws away the input stream until its matching “)” is found. Thus, the Outer Interpreter only sees the “(“, executes it and continues on. The rest of the comment is bypassed as surely as if it were never there.

The feel of syntax, then, comes not from the language interpreter itself, but from the individual words as they are translated. Knowing the specific action of the words is important, then. The most important are the defining words that allow compilation of new definitions. Using the provided words correctly will allow the language to be extended. Words that extend the language are called defining words.

Max-FORTH is both an interpreter and a compiler. This is facilitated by the Outer Interpreter’s two states:

Interpretation Mode and Compilation Mode. Instructions can be entered to be run “on the fly”. This immediate “translation and execution” is done in the Interpretation Mode. In the Compilation Mode, the Outer Interpreter “translates”, but, generally, does not “execute” the functions found. If the word has no markings as a word to be executed immediately, the Outer Interpreter defers execution by storing them as executable tokens in memory.

The word that switches the Outer Interpreter from Interpretation Mode to Compilation Mode is “:” (pronounced “colon”). The word that switches it out of Compilation Mode is “;” (pronounced semicolon). When a “:” is interpreted in the input stream, its execution has several effects. The Outer Interpreter is switched to Compilation Mode. Also, the input stream is searched for a string for use as a name for a new definition. This string is used to create a dictionary entry for the new word.

This dictionary entry is called a “head”. Linkages are added to the head to allow it to be found in memory. This head will be used for comparison with the input stream by the Outer Interpreter to tell if the new definition is being referenced in the input stream. After changing the Outer Interpreter’s state, making the head, and doing some minor error checking, “:” starts the code section of the new word by laying in a pointer to a routine that can translate the two byte tokens. It then returns control back to the Outer Interpreter. The input stream pointer is moved past the string. The Outer Interpreter continues to evaluate the input stream.

Words now found will not be immediately executed. They are compiled as tokens into the code section, or “body”, of the new definition being formed. Most functions compile into one 16-bit memory “word” (two bytes). This means compiled Max-FORTH code is very compact. A pointer to the “code” of the word to be later executed is compiled into the next available two-byte spot in the dictionary. This pointer is called the compiled words Code-Field Address. This is a lower level linkage than the dictionary structure, which points to names. Here, the function is referenced by a physical memory address.

This compilation process continues until the word “;” is encountered. The word “;” is from a special class of words which has a precedence flag set, telling the Outer Interpreter not to defer execution, but to run the word whenever found. This allows “;” to run, turning off the Compilation Mode, finishing up the definition, doing some error checking, and enabling the new definition to be found as a new word in the language.

Functions set between a “:” and a “name-string” on the starting end, with a “;” at the end, are compiled into new definitions.  After the word has been created, its function can be invoked by including its “name-string” in the input stream with the Outer Interpreter in Compilation Mode. If the outer Interpreter is in Compilation Mode, i.e.: making a newer word, including a word’s name in the input stream will cause the previously defined function to be added to a newer words definition. So begins the pyramiding of words upon words until a whole program is described by one word which references all other word definitions required.

For more information on the Max-FORTH language, refer to the Max-FORTH User’s Manual, order number UM-MAX.

 

FORTH compatible hardware

The Forth Webring
[Prev] [Random] [List Sites] [Next] [Next 5]
 WebRing Home - About - Privacy
80x51 by eenexus
[ Join Now | Ring Hub | Random | << Prev | Next >> ]

 

 

 

 

.

21433922041