turner-townsend-backend-ass.../fifth_stack/README.md

58 lines
681 B
Markdown
Raw Normal View History

2025-08-30 12:29:05 +01:00
# Fifth Stack
2025-08-30 11:06:09 +01:00
A simple stack-based language called Fifth
## Usage
```shell
2025-08-30 12:29:05 +01:00
python fifth_stack.py
2025-08-30 11:06:09 +01:00
```
### 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]
2025-08-30 11:06:09 +01:00
+
stack is [14]
DUP
stack is [14, 14]
PUSH 2
stack is [14, 14, 2]
*
stack is [14, 28]
SWAP
stack is [28, 14]
2025-08-30 11:06:09 +01:00
/
stack is [2]
+
ERROR: two numbers required
POP
stack is []
2025-08-30 11:06:09 +01:00
EXIT
```
## Tests
```bash
pip install pytest
2025-08-30 12:29:05 +01:00
pytest -v test_fifth_stack.py
2025-08-30 11:06:09 +01:00
```
## Requirements
- Python 3.10+
- pytest