Arithmetic evaluation: Difference between revisions

m
(→‎{{header|Ada}}: Replaced by a version that generates syntax tree)
m (→‎{{header|Ada}}: Link fixed)
Line 9:
=={{header|Ada}}==
{{libheader|Simple components for Ada}}
The following implementation uses table-driven parsers provided by [[:Category: Simple components for Ada|Simple components for Ada]]. A parser is controlled by the tables of prefix, infix and postfix operations. Between the operations it calls ''Get_Operand'' in order to recognize expression terms. The parser communicates with its back end using the primitive operations ''Call'' and ''Enclose''. The former is used for operations, the latter is for brackets. For this example we generate the parsing tree from there. There are many other operations which are used for advanced parsing and optimization, here they are defined as trivially returning True or False.
 
A parsing tree node has one operation ''Evaluate'' in order to calculate the expression. The nodes are allocated in an arena implemented by a storage pool. The pools is organized as a stack, so that the whole tree is popped when no more needed. This is a standard technique in compiler construction.