Please help me to find a easiest Algorithm for this case

The problem posed seems to be equivalent to the string product:

 "aaa".*["fffff".*["kkkkk";"lllll"];"ooooo";"gggg".*["nnnnnnn";"bbbbbbb"]]

This could be evaluated with metaprogramming after formatting the input as per expression above. See an attempt that seems to be working for type of input indicated:

str = "aaa[ fffff[kkkkk;lllll]; ooooo; gggg[nnnnnnn;bbbbbbb] ]"
s0 = filter(x -> !isspace(x), str)   # remove spaces
s0 = replace(s0,"["=>"\".*[\"")  # add quotes and string product
s0 = replace(s0,";"=>"\";\"")  # add string quotes
s0 = replace(s0,"]"=>"\"]")   # add inner quote before ]
s0 = replace(s0,"]\""=>"]")   # remove quote surplus
s0 = "\"" * s0  # add leading quote
println(s0)  # Julia REPL outputs strings in escaped form, use println to QC
eval(Meta.parse(s0))
1 Like