Programming Chemical Equations

I have checked various sites about, "How to balance chemical equations thru programming by usiong python or c++ ?." They all have simple easy equations, but how do we programme Chemical Equations which consist Ions/ Hydrates. If some one knows how to do that please respond. A slight idea can help me too.