Modeling the system behavior
In the last section, we confirmed the system requirements. Let's now design the logic for processing the arithmetic expression. The components of the system are shown in Figure 2.1:
The components shown in the preceding figure work together as follows:
- The user enters an arithmetic expression at the command-line input and presses the Enter key.
- The user input is scanned in its entirety and stored in a local variable.
- The arithmetic expression (from the user) is scanned. The numbers are stored as tokens of the
Numeric
type. Each arithmetic operator is stored as a token of that appropriate type. For example, the+
symbol will be represented as a token of typeAdd
, and the number1
will be stored as a token of typeNum
with a value of1
. This is done by theLexer
(orTokenizer
) module. - An Abstract Syntax Tree (AST) is constructed from the...