http://www.perlmonks.org?node_id=157351


in reply to A Tricky Problem with Context

I'm not sure how well this would work, but it seems as though you could implement some sort of "multi-pass compiler" type solution.

By that I mean, have your script go through the VB script a couple of times. The first pass does what (I think) stephen is suggesting, having your script try and determine what each variable type is on any given line (or, per statement, really) and returning the reply in some sort of unique markup language that is internal to your compiler. The second pass goes through and compares the VBscript to your newly generated first pass document, and makes sure the actual sigils $, @, %, etc match what the vb script is actually doing at that point. (In fact, it might be a good idea to number each statement of the vb script as you go through it, and put the corresponding number at the beginning of the perl script line, to make sure that the compiler can determine which statements are supposed to correlate.) The third pass would go through the final perl script and clean up all of your internal stuff.

I'm certainly no expert on writing compilers/translators, so don't take my suggestion as gospel, but it sounds like it could work.

-il cylic