A React-based Reverse Polish Notation (RPN) calculator that uses C++ compiled to WebAssembly for high-performance mathematical expression evaluation.
- Infix to Postfix Conversion: Convert standard mathematical expressions to RPN format
- WebAssembly Powered: C++ core compiled to WASM for optimal performance
- Real-time Calculation: Instant expression evaluation
- Modern UI: Clean, responsive React interface with Tailwind CSS
- Cross-platform: Works in any modern web browser
- Windows: Chocolatey package manager
- Emscripten SDK: For compiling C++ to WebAssembly
- Node.js: Version 16 or higher
- npm or yarn: Package manager
# Run as Administrator
choco install emscripten# Clone and setup Emscripten SDK
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
emsdk install latest
emsdk activate latest
emsdk_env.batem++ -v# Navigate to your project directory and run:
em++ src/util/rpn-calc.cpp -O3 -o src/util/out/rpn.js -s EXPORT_NAME=createRPNModule -s MODULARIZE=1 -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -s "EXPORTED_FUNCTIONS=['_calculate','_formatInfix','_toPostfix','_evaluatePostfix']" -s "EXPORTED_RUNTIME_METHODS=['ccall','cwrap']"npm installnpm run devrpn-calc/
├── src/
│ ├── util/
│ │ ├── rpn-calc.cpp # C++ RPN implementation
│ │ └── out/
|__ rpn.js # Compiled WebAssembly module
│ ├── App.jsx # Main React component
│ └── main.jsx # React entry point
├── index.html
├── package.json
└── vite.config.js
npm run devnpm run buildnpm run previewThe WebAssembly module exposes the following C++ functions:
calculate(expression): Directly evaluate infix expressionformatInfix(expression): Format and validate infix expressiontoPostfix(expression): Convert infix to postfix notationevaluatePostfix(expression): Evaluate postfix expression
Enter expressions in standard mathematical notation:
4 + 7 / 2(3 + 4) * 210 - 3 * 2 + 1
The calculator will display:
- Formatted Infix: Properly spaced expression
- Postfix: RPN notation
- Result: Calculated value
When you modify rpn-calc.cpp, recompile with:
em++ src/util/rpn-calc.cpp -O3 -o src/util/rpn.js -s EXPORT_NAME=createRPNModule -s MODULARIZE=1 -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -s "EXPORTED_FUNCTIONS=['_calculate','_formatInfix','_toPostfix','_evaluatePostfix']" -s "EXPORTED_RUNTIME_METHODS=['ccall','cwrap']"-O3: Maximum optimization-s EXPORT_NAME=createRPNModule: Names the module factory-s MODULARIZE=1: Enables module pattern-s EXPORT_ES6=1: Generates ES6 module format-s USE_ES6_IMPORT_META=0: Compatibility with build toolsEXPORTED_FUNCTIONS: C++ functions exposed to JavaScriptEXPORTED_RUNTIME_METHODS: Emscripten helper functions
-
"Module not found" errors
- Verify Emscripten installation
- Check file paths in compilation command
-
WebAssembly loading failures
- Ensure
rpn.jsandrpn.wasmare in correct location - Check browser console for specific errors
- Ensure
-
Compilation errors
- Run
em++ -vto verify Emscripten installation - Check C++ code for syntax errors
- Run
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
MIT License - feel free to use this project for learning and development.
- Fork the project
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
Happy Calculating!