In reverse Polish notation, the operators follow their operands. For example, to add 3 and 4 together, the expression is 3 4 + rather than 3 + 4. The expression 3 − 4 + 5 in conventional notation is 3 4 − 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it.
The concept of a stack, a last-in/first-out construct, is integral to the left-to-right evaluation of RPN. In the example 3 4 -, first the 3 is put onto the stack, then the 4; the 4 is now on top and the 3 below it. The subtraction operator removes the top two items from the stack, performs 3 - 4, and puts the result of -1 onto the stack.
The common terminology is that added items are pushed on the stack and removed items are popped.
The advantage of reverse Polish notation is that it removes the need for order of operations and parentheses that are required by infix notation and can be evaluated linearly, left-to-right. For example, the infix expression (3 × 4) + (5 × 6) becomes 3 4 × 5 6 × + in reverse Polish notation.
(Source: "Reverse Polish notation." Wikipedia)
This application is a command-line interface calculator that utilizes the concept of Reverse Polish Notation (RPN) to calculate mathematical expressions. The application is built with Node.js, tested with Jest, and follows ESLint rules for code quality.
The application is designed to be a CLI tool, as RPN inputs are naturally linear and work well with a command-line interface. Node.js was used due to its excellent support for command-line applications and I/O operations. Jest was used for testing due to its comprehensive feature set and simplicity. ESLint was used to ensure a consistent code style and catch potential errors early. While the testing for this calculator is sufficient for basic operation, not all of the features are fully tested for error handling and precise cases.
- Run 'npm install' to install necessary dependencies.
- Run 'npm start' or 'node cliInterface.js' in terminal to begin.
- Enter numbers and/or valid operations (+, -, *, /) on a single line with spaces between each input, or on separate lines without spaces.
- Comprehensive testing suite using Jest. Run 'npm test' to execute.
- Stack tracking. Enter 'stack' during operation to see your current number stack.
- Stack manipulation. Enter 'clear' to remove all inputs. Enter 'back' to remove the most recent input.
- Calculation History. Enter 'history' to view all performed calculations for the current session.
- Error handling. Erroneous inputs are handled as to not interrupt user flow.
Developed By | Github | |
---|---|---|
PJ Bannon |