Flattening the grammar for easier output