Improve error messages for invalid ubiquitous tokens
Clean up prepare_grammar function