Problem:
Implement a parser to take a string and compute its numerical value using the given rules. Operators should be applied in order of precedence from left to right. An exception to this is brackets which are used to explicitly denote precedence by grouping parts of an expression that should be evaluated first.
Rules a = ‘+’, b = ‘-’, c = ‘*’, d = ‘/’, e = ‘(’, f = ‘)’
Acceptance Criteria
Input: “3a2c4”
Result: 20
Input: “32a2d2"
Result: 17
Input: “500a10b66c32”
Result: 14208
Input: “3ae4c66fb32"
Result: 235
Input: “3c4d2aee2a4c41fc4f”
Result: 990
- Clone this project
git clone https://github.com/codeitlikemiley/arithmetic-parser
cd arithmetic-parser
- Run the program
cargo run
A prompt should launch in your terminal
If you type in the string you want to calculate e.g. 3a2c4 and it should return 20
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `/Users/uriah/Code/arithmetic_parser/target/debug/arithmetic_parser`
arithmetic-parser> 3a2c4
Result: 20
arithmetic-parser> _
- Build for release
cargo build --release
cd target/release
./arithmetic_parser
an prompt should launch in your terminal If you type in the string you want to calculate e.g. 3a2c4 and it should return 20
arithmetic-parser> 3a2c4
Result: 20
arithmetic-parser> _
- Run test cases
cargo test
output:
Finished test [unoptimized + debuginfo] target(s) in 0.00s
Running unittests src/main.rs (/Users/uriah/Code/arithmetic_parser/target/debug/deps/arithmetic_parser-821f89864bc36f83)
running 4 tests
test tests::test_division_by_zero ... ok
test tests::test_unmatched_opening_parenthesis ... ok
test tests::test_evaluate_expression ... ok
test tests::test_unmatched_parenthesis ... ok
- You can either download the binary file (MacOS Only) from release page from source or build it yourself if your on Linux or Windows
2 . Give it permission to run
Go to System Settings > Security & Privacy
- you will be prompted to enter your password
- if asked to delete the installer, click move to trash
- open your terminal and type in
arithmetic-parser