In fact, ToExpression converts the entire string to an expression, as you expected. In the following example
In[1]:= ToExpression["a=1;b=2"] Out[1]= 2 In[2]:= a Out[2]= 1
you can see that the first part of a=1 was correctly evaluated as part of the CompoundExpression .
You may need to convert expressions separated by semicolons to a list of expressions. You can use StringSplit for this:
In[3]:= ToExpressionList[s_String] := ToExpression /@ StringSplit[s, ";"] In[4]:= ToExpressionList["x;y"] Out[4]= {x,y}
Edit: It looks like you are trying to use a semicolon as a separator.In Mathematica list you will need to use , for this. So, you can also achieve what you want by replacing with ; into your string and then apply ToExpression afterwards:
In[20] := ToExpression @ StringReplace[ "{f[{-1 + x, y}]; f[{1 + x, y}]; f[{x, 1 + y}]}", ";" -> "," ] Out[20] = {f({x-1,y}),f({x+1,y}),f({x,y+1})}
source share