Forth Syntax
Forth has one of the simplest syntaxes of any computer language. The syntax can
be stated as follows, "Forth code is a bunch of words with spaces between
them."
A D V E R T I S E M E N T
This is even simpler than English! Each word is equivalent to
a function or subroutine in a language like 'C'. They 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. Forth word names can have any combination of letters,
numbers, or punctuation. We will encounter words with names like:
." #S SWAP ! @ ACCEPT . *
They 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.
|