擅长:python、mysql、java
<p>你可以用<a href="http://pyparsing.wikispaces.com/" rel="noreferrer">pyparsing</a></p>
<pre><code>#!/usr/bin/env python
from pyparsing import nestedExpr
import sys
astring=sys.argv[1]
if not astring.startswith('('):
astring='('+astring+')'
expr = nestedExpr('(', ')')
result=expr.parseString(astring).asList()[0]
print(result)
</code></pre>
<p>运行它会产生:</p>
<pre><code>% test.py "foo(bar(bar(foo)))(foo1)bar1"
['foo', ['bar', ['bar', ['foo']]], ['foo1'], 'bar1']
</code></pre>