Interpreter Design Pattern


GoF Statement: Defines a representation of a grammar for a language along with an interpreter that uses the representation to interpret sentences in the language.
Category: Behavioral
UML Diagram:  

Description of the Demonstration:

The "language" being interpreted in this demonstration is that of Roman Numerals. InterpreterMain creates an instance of RNInterpreter, which in turn creates instances of each of the subclasses. A Roman numeral is passed to the RNInterpreter which knows how to parse it and call the appropriate sub-class to handle each "token" in order to translate the Roman numeral into a base-10 Arabic numeral.


Code:

Click here to download a zip file containing all the source files and an executable of the Demonstration. See the _ReadMe.txt file in the zip.