Fix for global variables to be treated correctly even if not placed at very beginning of sketch

Hi!

I noticed that global variables were acting a bit strange if they are not placed at the very beginning of the sketch (i.e. before setup() and draw()).

I find myself quite commonly putting globals in-between class declarations and such, just to try out ideas. The previous code was not handling these globals correctly, and was treating them like any other number to tweak: this meant that these global values were not available to the rest of the code logic at compile. 

This is my fix. It counts the number of { and } that appear and keeps track of the scope level for every character in the code. There's a better explanation in the code comments.

Note that my solution doesn't check to see if { and } appear within commented sections of the code. If any do, then my solution will fail, and globals could be wrongly treated again. This is fixable, it just takes more effort :)