Today your challenge is to produce all possible full parenthesizations of an expression.
Your input is a single line of printable ASCII containing one or more terms separated by operators. The input might also contains spaces - you must ignore these. A term is
[a-zA-Z0-9], an operator is
[^ ()a-zA-Z0-9]. You may assume that the input is always valid.
Output all possible ways to fully parenthesize the given expression, separated by newlines with an optional trailing newline.
- Parenthesize terms - only parenthesize around operators.
- Reorder the terms.
- Output any spaces.
N N a * b (a*b) x_x_0 (x_(x_0)) ((x_x)_0) a * b|c|d (a*(b|(c|d))) (a*((b|c)|d)) ((a*b)|(c|d)) ((a*(b|c))|d) (((a*b)|c)|d)
Smallest code in bytes wins.