Forth (programming language): Difference between revisions

Content deleted Content added
That jojo (talk | contribs)
Overview: Updated description of forth’s stack as implicit rather than explicit. The stack is never mentioned by name in the source code, it is part of the model of operation that the programmer is assumed to understand.
Tags: Mobile edit Mobile web edit
m Overview: formatting fix
Line 61:
Forth emphasizes the use of small, simple functions called ''words''. Words for bigger tasks call upon many smaller words that each accomplish a distinct sub-task. A large Forth program is a hierarchy of words. These words, being distinct modules that communicate implicitly via a stack mechanism, can be prototyped, built and tested independently. The highest level of Forth code may resemble an English-language description of the application. Forth has been called a ''meta-application language'': a language that can be used to create [[Domain-specific language|problem-oriented languages]].<ref>{{cite book |last=Brodie |first=Leo |title=Starting Forth |edition=2nd |year=1987 |publisher=Prentice-Hall |isbn=978-0-13-843079-5 |url=https://www.forth.com/starting-forth/index.html}}</ref>
 
Forth relies on implicit use of a [[stack (abstract data structuretype)|data stack]] and [[reverse Polish notation]] which is commonly used in calculators from [[Hewlett-Packard]]. In RPN, the operator is placed after its operands, as opposed to the more common [[infix notation]] where the operator is placed between its operands. Postfix notation makes the language easier to parse and extend; Forth's flexibility makes a static [[Backus-Naur form|BNF]] grammar inappropriate, and it does not have a monolithic compiler. Extending the compiler only requires writing a new word, instead of modifying a grammar and changing the underlying implementation.
 
Using RPN, one can get the result of the mathematical expression <code>(25 * 10 + 50)</code> this way: