two major changes here. have added more parser control flow, and have made index and tokens into global variables to reduce control flow headaches