From the very beginning: this "parser" is wrong; so I don't want even to get into the detail of your problem.
You are not even close to starting a parser project yet. This is not how parsers work: they should be totally abstracted from any UI. You could collect all the problems in some data collection until it makes sense to continue parsing. You can even stop on the first unrecoverable problem if the input code and stop. But look what you are doing: showing
MessageBox
of every problem. Just imagine yourself to be a user of such "parser". More importantly, the bigger system hosting your parser, most likely, won't be even aware of the concept of
MessageBox
or any UI elements at all.
Also, you approach to a parse is totally ad-hoc, not using any regular approach. I can imagine someone doing a parser from scratch (because I did so, as well as many other people), but you don't have sufficient understanding yet, so your attempt already leads you nowhere. For example, you could formalize the notion of BNF syntax definition in your code and translate BNF into the parsing code. Instead, you need to read about the design of parsers (there are different well-known types of them) from some book on parsers. If this is your school assignment, could it be safe to assume that you had some lectures, seminars or learning courses covering this topic? :-)
Also, you could use on of available
compier-compilers, but I'm not sure if it can be compatible with your assignment:
http://en.wikipedia.org/wiki/Compiler-compiler[
^].
See also:
http://en.wikipedia.org/wiki/Parsing[
^],
http://en.wikipedia.org/wiki/Comparison_of_parser_generators[
^].
—SA