Putting it all together
We have seen in previous sections how to design and write code for the various processing modules of our project. We will now tie all of them together in a main()
function that serves as the command-line application. This main()
function will do the following:
- Display prompts with instructions for the user to enter an arithmetic expression.
- Accept an arithmetic expression in the command-line input from the user.
- Instantiate
Parser
(returns aParser
object instance). - Parse the expression (returns the AST representation of the expression).
- Evaluate the expression (computes the mathematical value of the expression).
- Display the result to the user in the command-line output.
- Invoke
Parser
and evaluate the mathematical expression.
The code for the main()
function is as follows:
src/main.rs
fn main() { println!("Hello! Welcome to Arithmetic expression ...