factor out all the grammar stuff into a separate file