Avoid infinite loops on invalid input

These (as the complete input) would never terminate:

* `)`
* `|`
* `\`