recursive parsing parenthesis with explanation

632 Views Asked by At

I came across an explanation where (()())() gives you the sequence 0,1,2,1,2,1,0,1,0 using recursive parsing. Can someone give me a detailed explanation of how this works?

1

There are 1 best solutions below

2
On

If your example is (()())() then you start at 0

0 = split  
( = +1
) = -1
 +1 +1 -1 +1 -1 -1 +1 -1
0  1  2  1  2  1  0  1  0
^                 ^     ^
 Split the parenthesis here

You get (()()) ()