Reorder grammar rules logically