I want to be able to turn the strings for example: '(* (+ int (+ int real)) int)'
into a nested list where the brackets are start/end of lists, looking like this(in this case)
['*', ['+', 'int', ['+', 'int', 'real']], 'int']
I have tried with the following code but it doesn't work
def bracketCheck(el):
if el == ')' or el == '(':
return False
else:
return True
def stringIntoList(lst):
lst1 = ''
lst2 = []
for i in range(0, len(lst)-1):
if bracketCheck(lst[i]):
lst1 += lst[i]
elif lst[i] == '(':
b = stringIntoList(lst[i:])
elif lst[i] == ')':
lst2.append(lst1)
lst2.append(b)
lst1 = ''
return lst2