I am stumped at creating a formula (for a coded math problem evaluator) that finds what is within the parenthesis. It gets tricky when you have () within (), as it recognizes wrong.
It finds the first instance of a left parenthesis, and the first instance of a right parenthesis, and spits out what is in-between, then repeats
Here are some examples:
(x)(y) - works - (x) and (y)
(x(y)) - doesn't work - recognizes it as (x(y) and (y))
(x)(y)(z) - works - (x) and (y) and (z)
(x(y)(z)) - doesn't work - recognizes it as (x(y) and (y)(z) and (z))
(x(y(z))) - doesn't work - recognizes it as (x(y(z) (y(z)) (z)))
Can anyone think of a formula that will recognize it correctly?
1.First question, feel free to change the tags
2.To make it easier (if you want)
use lp1 = first left parenthesis, use rp2 = second right parenthesis, etc
3. Please ask any questions, sorry if I am not very clear (don't know how to explain it)
Hint: Start from $0$, $+1$ for every left-bracket and $-1$ for every right bracket. Whenever it reaches $0$, you've found a complete expression. Recursively parse that expression and the remaining expression.