Forth (programming language): Difference between revisions

Content deleted Content added
m Overview: formatting fix
m Facilities: formatting fix
Line 110:
 
==Facilities==
Forth's [[Formal grammar|grammar]] has no official specification. Instead, it is defined by a simple algorithm. The interpreter reads a line of input from the user input device, which is then parsed for a word using spaces as a [[delimiter]]; some systems recognise additional [[Whitespace (computer science)character|whitespace]] characters. When the interpreter finds a word, it looks the word up in the ''dictionary''. If the word is found, the interpreter executes the code associated with the word, and then returns to parse the rest of the input stream. If the word isn't found, the word is assumed to be a number and an attempt is made to convert it into a number and push it on the stack; if successful, the interpreter continues parsing the input stream. Otherwise, if both the lookup and the number conversion fail, the interpreter prints the word followed by an error message indicating that the word is not recognised, flushes the input stream, and waits for new user input.<ref name="6dQ7P">{{harvnb|Brodie|1987|p=14}}</ref>
 
The definition of a new word is started with the word <code>:</code> (colon) and ends with the word <code>;</code> (semi-colon). For example,