There is an entire field looking at this question called "computational linguistics" http://en.wikipedia.org/wiki/Computational_linguistics. Looking at any online translation tool you can see that they still have a ways to go, but there has been a lot done on parsing English.
Stanford provides a robust English parser here http://nlp.stanford.edu:8080/parser/ with the homepage here http://nlp.stanford.edu/software/lex-parser.shtml. I would highly recommend using an established library such as this for your script rather than writing your own.