Added the merge step in grammar extraction.