Grammar synthesis