main loop

main state machine based on :
http://www.w3.org/TR/2011/WD-html5-20110405/tokenization.html