This function in standard Python is a building block for custom REPLs:
```python
from codeop import compile_command
print("Repl in (Circuit-)Python")
ns = {}
PS1="<<< "
PS2=",,, "
command = ""
while True:
line = input(PS2 if command else PS1)
if command:
command = command + "\n" + line
else:
command = line
try:
if (code := compile_command(command)):
command = ""
exec(code, ns)
except Exception as e:
command = ""
print(e)
```