Implemented State Machine

Totally refactored token parsing into a state machine. Code is more
verbose but a _lot_ less fiddly.
Fixed bugs.

Code is now generated correctly for static vars.