New parser state machine

Parser now uses nested function calls, instead of processing each token
one at a time.