Forth Briefing

Forth is: a dictionary of words

Dictionary: lists of words (vocabularies)

Words:

bulletall execute as routines
bulletare functional: pass input and return data on a stack
bulletcan be interpreted or compiled

Categories of words:

bulletArithmetic

( a b ® c )  +
a + b ®
c

Stack 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)

bulletStack operations

( a b ® b a ) SWAP
( a ®
a a ) DUP
( a ®
) DROP

bulletMemory

( address ® data ) @ "fetch"
( data address ® )  ! "store"
( data ® )  ,  compile top of stack to dictionary
( data ® ) C, compile least-significant byte of top stack item

bulletI/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
bulletCompiling words execute only in compile state:

Structured control:

IF ELSE THEN
BEGIN UNTIL
BEGIN WHILE REPEAT
DO LOOP
DO +LOOP

bulletDefining words establish word classes:

compile: 1 CONSTANT one         global constant
execute: one (
® 1 )            places 1 on top of stack

compile: VARIABLE var               global variable
execute: var (
® address )  address points to value of var

compile:  : 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

bullet

searches dictionary for words in vocabulary stack order

bullet

defining-words switch interpreter to compile mode

bullet

incremental compilation allows bottom-up code implementation

: foo 1 BEGIN DUP .  1+  DUP 10 = UNTIL DROP ;

foo outputs 1 through 10.

bullet

word names: up to 31 ASCII characters; space(s) is only delimiter

Forth Project Development

bullet

Forth words (predefined) and application words (user-defined) are all part of the dictionary:

® open language
® highly extensible:

bullet

new word definitions extend dictionary

bullet

new defining words extend compilation capability

bullet

MPE Cross-Compiler:

bullet

stable

bullet

no known faults

bullet

source-code provided

bullet

EPROM emulator available

bullet

Innovatia IMPEL

bullet

stable, fault-free Forth-83

bullet

in use for over 10 years

bullet

target processor: any with 6502 instruction set

bullet

Typical Innovatia product application code

bullet

uses only Forth defining words (basic Forth programming)

bullet

modifications:
  
at high functional level
   easy to bench-test software changes

Home Up