Compact the grammar at every step.