turner-townsend-backend-ass.../fifth
2025-08-30 11:58:19 +01:00
..
fifth.py add tests, update readme, requirements, move into subdir 2025-08-30 11:58:19 +01:00
README.md add tests, update readme, requirements, move into subdir 2025-08-30 11:58:19 +01:00
requirements.txt add tests, update readme, requirements, move into subdir 2025-08-30 11:58:19 +01:00
test_fifth.py add tests, update readme, requirements, move into subdir 2025-08-30 11:58:19 +01:00

Fifth

A simple stack-based language called Fifth

Usage

python fifth.py

Commands

  • PUSH <n> - push integer onto stack
  • POP - remove top element
  • SWAP - swap top two elements
  • DUP - duplicate top element
  • +, -, *, / - arithmetic operations
  • EXIT - quit

Example

stack is []
PUSH 3
stack is [3]
PUSH 11
stack is [3, 11]
+
stack is [14]
DUP
stack is [14, 14]
PUSH 2
stack is [14, 14, 2]
*
stack is [14, 28]
SWAP
stack is [28, 14]
/
stack is [2]
+
ERROR: two numbers required
POP
stack is []
EXIT

Tests

pip install pytest
pytest -v test_fifth.py

Requirements

  • Python 3.10+
  • pytest