Much like English, commands and data are "words" of one or more characters, separated by one or more spaces
There are no particular limits to the characters that make up a valid word
Examples: swap ! @ C@ 123 2*
Words are case-sensitive
Numbers
Numbers are signed 16-bit integers
The number base is set with the words binary, decimal, or hex
All function parameters are passed in and out using the parameter stack
The size of the parameter stack is theoretically unlimited, but implemented with a limit of 16 integers
Functions use reverse Polish, or postfix notation (data precedes operation)
Command Line
A command line is a stream of words and numbers, terminated with <cr> (the "enter" or "return" key)
Each character is echoed to the sender as it is received
The practical limit for the length of a command line is 64 characters
The Interpreter
The interpreter finds the first space-delimited word, then:
Tries to find the word in the dictionary
If found, it executes the function associated with that word and continues to look for more words
If not found, it tries to convert the word to a number, using the current number base.
If successful, it pushes the number on the parameter stack, and continues to look for more words
If it isn't a valid number, an error is declared and the interpreter stops
The results of this simple syntax are:
There are very few rules
There are few reserved or special characters
The ASCII interface allows for interactive testing and easy logging
There is no presedence of operation
The code to implement the interpreter is small and fast,
Hands On
Get the "ok" prompt by hitting <enter> several times
ok
ok
ok
Multiply two numbers and show the result
ok 3 4 * . 12
ok
In the example above, "3" puts 3 on the stack, "4" puts 4 on the stack, "*" multiplies the top two stack items and replaces them with the result. "." prints the top stack item.