ED-Eiffel: Prefix Calculator Example
(mos's homepage)


Consider the problem of implementing an interpreter for prefix expressions (e.g.: + 1 * 2 3, which is equivalent to infix expression: 1 + 2 * 3). This interpreter should accept typical arithmetic operators (addition, subtraction, multiplication, and division), and be applied to both numbers and strings (when applicable). It should also be modular by allowing adding new types of operands, and new operations.

The implemented solution uses visitors for semantic analysis and interpretation, and also a binary method for interpretation. All of them implemented with external dispatch.

External dispatch solution:

(Source code)       (Compiled Eiffel code)

Inheritance class diagram:


(mos at ua.pt) University of Aveiro, DETI/IEETA