A collection of calculators written in COBOL, demonstrating different computational paradigms and modern features like emoji support.
This project contains three different calculator implementations:
- Basic Calculator - Traditional infix notation calculator
- RPN Calculator - Reverse Polish Notation calculator with stack-based evaluation
- Emoji RPN Calculator - Modern RPN calculator using emoji operators (➕➖✖➗)
Install GNU COBOL (GnuCOBOL) via Homebrew:
This will install:
- cobc - COBOL compiler
- Required dependencies (berkeley-db, gmp, json-c)
- Linux: Install gnucobol or open-cobol via your package manager
- Windows: Install GnuCOBOL from the official website
.
├── README.md # This file
├── calculator.cob # Basic infix calculator
├── rpn-calculator.cob # RPN calculator
├── emoji-rpn-calculator.cob # Emoji RPN calculator
├── test-rpn.cob # Test suite for RPN calculator
├── test-emoji-rpn.cob # Test suite for emoji RPN calculator
├── run-tests.sh # Test runner for RPN calculator
├── run-emoji-tests.sh # Test runner for emoji calculator
└── emoji-test.cob # Emoji support verification
Compile and run the traditional calculator:
cobc -x calculator.cob -o calculator
./calculator
Example usage:
==============================
COBOL CALCULATOR
==============================
Enter first number: 10
Enter operation (+, -, *, /): +
Enter second number: 5
Result: 0000000010.00 + 0000000005.00 = 000000000000015.00
Compile and run the RPN calculator:
cobc -x rpn-calculator.cob -o rpn-calculator
./rpn-calculator
Example usage:
==============================
RPN COBOL CALCULATOR
==============================
Enter RPN expression (e.g. 3 4 + or 10 2 /):
3 4 +
Result: +0000000007.00
Compile and run the emoji calculator:
cobc -x emoji-rpn-calculator.cob -o emoji-rpn-calculator
./emoji-rpn-calculator
Example usage:
========================================
🧮 EMOJI RPN CALCULATOR 🧮
========================================
Enter RPN expression using emoji operators:
➕ for addition ➖ for subtraction
✖ for multiply ➗ for division
Example: 3 4 ➕ or 10 2 ➗
3 4 ➕
Result: +0000000007.00 🎉
# Run test suite directly
cobc -x test-rpn.cob -o test-rpn
./test-rpn
# Or use the test runner script
chmod +x run-tests.sh
./run-tests.sh
# Run emoji test suite directly
cobc -x test-emoji-rpn.cob -o test-emoji-rpn
./test-emoji-rpn
# Or use the emoji test runner script
chmod +x run-emoji-tests.sh
./run-emoji-tests.sh
- ✅ Four basic operations (+, -, *, /)
- ✅ Decimal number support
- ✅ Division by zero protection
- ✅ Interactive loop
- ✅ Stack-based evaluation
- ✅ Complex expression support
- ✅ Space-separated input parsing
- ✅ Error handling for invalid expressions
- ✅ Comprehensive test suite (20 test cases)
- ✅ Modern emoji operators (➕➖✖➗)
- ✅ Unicode support in COBOL
- ✅ Colorful error messages with emojis
- ✅ Success celebrations (🎉)
- ✅ Full test coverage (12 test cases)
3 4 ➕ → 7 (3 + 4)
10 3 ➖ → 7 (10 - 3)
4 5 ✖ → 20 (4 * 5)
20 4 ➗ → 5 (20 / 4)
15 7 1 1 ➕ ➖ ➗ 3 ✖ 2 1 1 ➕ ➕ ➖ → 5
2 3 ➕ 4 5 ➕ ✖ → 45 ((2+3) * (4+5))
1 2 ➕ 3 ➕ 4 ➕ → 10 (((1+2)+3)+4)
Both RPN calculators include comprehensive error handling:
- Division by zero: Error: Division by zero ➗
- Insufficient operands: Error: Need 2 operands for ➕
- Stack overflow: Error: Stack overflow! 💥
- Stack underflow: Error: Stack underflow! ⚠️
- Invalid expressions: Error: Invalid RPN expression! ❌
- Data structures: Stack implementation using OCCURS clause
- String handling: Token parsing and manipulation
- Control flow: PERFORM loops and conditional logic
- Unicode support: Emoji character handling
- Modular programming: Paragraph-based subroutines
- Error handling: Comprehensive validation and messaging
- The emoji calculator generates Unicode encoding warnings during compilation, but functions correctly
- All programs compile successfully with GnuCOBOL 3.2+
- No external dependencies beyond the standard COBOL runtime
- Basic arithmetic operations
- Decimal handling
- Zero operations
- Negative numbers
- Complex expressions
- Error conditions
- All emoji operators
- Complex emoji expressions
- Error conditions with emoji messages
- Unicode character validation
To extend the calculators:
- Add new operations: Extend the PROCESS-TOKEN paragraph
- Add new tests: Follow the existing test patterns
- Add new features: Use the modular paragraph structure
This project is provided as-is for educational purposes, demonstrating COBOL programming capabilities including modern Unicode support.
- This demonstrates that COBOL, despite being from 1959, can handle modern Unicode emojis! 🎉
- The emoji calculator is likely one of the first emoji-based calculators written in COBOL
- COBOL's verbosity makes the intent very clear, even 65+ years later
- The stack-based RPN implementation showcases COBOL's data structure capabilities
Built with ❤️ and lots of COBOL verbosity