Forth Syntax

Most of the Forth language has a very simple syntax of any computer language. Basically you have two things: words and numbers. There are also two modes of operation. Most of the time you'll be in an interpreter, but you can use the compiler to create new words as well.

Most words take their data from the stack (which is where numbers are placed when they are encountered), but you will also encounter some parsing words which take data from the input stream. (The details of this will be covered later)

Note: there is also a special class of words known as macros. These can only be used when defining new words, so we won't worry about them now. We'll take a closer look at them later in this tutorial.

Words are executed in the order they appear in the code. The following statement, for example, could appear in a Forth program:

WAKE.UP EAT.BREAKFAST WORK EAT.DINNER PLAY SLEEP

Notice that WAKE.UP has a dot between the WAKE and UP. The dot has no particular meaning to the Forth compiler. I simply used a dot to connect the two words together to make one word, and to make that word easier for a human to read. Forth word's names can use any combination of letters, numbers, or punctuation. We will encounter words with names like:

." #s swap ! @ dup . *

These are all called words. The word $%%-GL7OP is a legal Forth name, although not a very good one. It is up to the programmer to name words in a sensible manner. In general, Forth (and RetroForth in particular) give the programmer ultimate freedom to make whatever design decisions are appropriate, and does not get in the way of making bad decisions.

Now it is time to start RetroForth and begin experimenting. One of Forth's greatest strengths is its interactive, immediate nature.