Nice
The algorithms are simple.
By the way, if you're going to do this, make sure you do it line by line, in just one whole go ;D
When you hit the globals block, you would create a new variable object. When hit the end globals block, you would lock the global variable declarer
When you have a new function, you would empty the local variable stack, and start adding new local variables to it as you encounter them.
Do the same for functions.
As you encounter them, find a new name for them (A much shorter one), and change it, then store it into some sort of map/hash/dictionary