Forth is: a dictionary of words
Dictionary: lists of words (vocabularies)
Words:
all execute as routines are functional: pass input and return data on a stack can be interpreted or compiled
Categories of words:
| Arithmetic |
( a b ® c ) +
a + b ® cStack notation:
Inside ( ) are comments that do not execute - used for showing stack activity
b is item on top of stack before + executes
a is second item on stack
c is item on top of stack after + executes
( a b ® f ) =
a = b returns boolean flag, f, as true (non-zero)
a ¹ b returns false flag (zero)
| Stack operations |
( a b ® b a ) SWAP
( a ® a a ) DUP
( a ® ) DROP
| Memory |
( address ® data ) @ "fetch"
( data address ® ) ! "store"
( data ® ) , compile top of stack to dictionary
( data ® ) C, compile least-significant byte of top stack item
| I/O Forth has a "getline" function Input/output streams vectored from/to I/O sources/sinks of ASCII text Number/text conversion words ( n ® ) . "Dot" outputs number n on stack to output stream | |
| Compiling words execute only in compile state: |
Structured control:
IF ELSE THEN
BEGIN UNTIL
BEGIN WHILE REPEAT
DO LOOP
DO +LOOP
| Defining words establish word classes: |
compile: 1 CONSTANT one global constant
execute: one ( ® 1 ) places 1 on top of stackcompile: VARIABLE var global variable
execute: var ( ® address ) address points to value of varcompile: : foo {words} ; define foo as a word
execute: : pushes return pointer on return stack, executes {words}, and ; pops return stack to continue execution of calling thread
ANATOMY OF A DEFINING WORD

All words with the same compile-time routine (same defining word) are executed at run-time by the same run-time routine.
VOCABULARIES give words context: a kind of object structuring.

Word lists are vocabularies
Executing + from INTEGER vocabulary does integer add.
Forth Interpreter
|
searches dictionary for words in vocabulary stack order | |
|
defining-words switch interpreter to compile mode | |
|
incremental compilation allows bottom-up code implementation |
: foo 1 BEGIN DUP . 1+ DUP 10 = UNTIL DROP ;
foo outputs 1 through 10.
|
word names: up to 31 ASCII characters; space(s) is only delimiter |
Forth Project Development
|
Forth words (predefined) and application words (user-defined) are all part of the dictionary: |
® open language
® highly extensible:
new word definitions extend dictionary
new defining words extend compilation capability
|
MPE Cross-Compiler: |
stable
no known faults
source-code provided
EPROM emulator available
|
Innovatia IMPEL |
stable, fault-free Forth-83
in use for over 10 years
target processor: any with 6502 instruction set
|
Typical Innovatia product application code |
uses only Forth defining words (basic Forth programming)
modifications:
at high functional level
easy to bench-test software changes