Serialize grammar.