Coding by minimal linear grammars