663 B
663 B
Fifth
A simple stack-based language called Fifth
Usage
python fifth.py
Commands
PUSH <n>- push integer onto stackPOP- remove top elementSWAP- swap top two elementsDUP- duplicate top element+,-,*,/- arithmetic operationsEXIT- 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