To expand on
chromatic's comment about "too much statefulness", a parser like this would be built something similar to how strtok() works in C. Basically, you create a regex that contains a list of all valid tokens and you iterate over it with /G. The problem here is that "list of all valid tokens" bit. Because, frankly, some tokens are only tokens in the context of other tokens (usually before, but sometimes after or even elsewhere). So, another approach is to start defining patterns. For example,
/(class)\s+(\S+)\s*;(.*)endclass/ (or somesuch). Except, that now becomes recursive and you still have the problem of defining all the legal patterns and keeping track of all the state.
The pattern approach is probably what I'd start out with if I was undertaking your project and I really didn't feel that I could use a grammar. Do you have a grammar for the original language? Not all languages (for example, Perl) have a grammar.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?