Refactor lex into a 'stage' of compilation