You are looking for an algorithm that's called a "recursive descent parser".
Doing this type of thing is an exercise that we had to do in programming
classes 35 years ago.
I'm a little bit amazed that something like this doesn't exist in the .Net
framework. Even in VBScript I think there's the "eval" function that might
have limited parsing capability. Still ... this is a good programming
exercise to learn how to write recursive functions.
If you want to create your own class function to do this go get a
fundamental programming book and study the chapters on recursion. I'd be
real surprised if you couldn't find a good writeup on how to do this.
-bwr-