A chemical formula can be viewed as a recursively grouped expression. Reading left to right, an element symbol creates a count of one unless followed by a positive integer subscript. A closed parenthetical or bracketed group forms a subexpression whose complete count vector is multiplied by the following subscript.
Adduct separators create components that are evaluated and then added, with any leading component coefficient applying to the whole component. A robust grammar should reject invalid states: unknown element symbols, unmatched marks, empty groups, zero or negative subscripts, and unconsumed trailing text. Case cannot be normalized casually because C, Co, and CO have different meanings.
Charge annotations require separate syntax; the 4 in NH4+ counts hydrogen, while the plus sign describes net charge. Square brackets are especially context-dependent because they may group a coordination complex or introduce an isotope label. Accepted notation must therefore be documented.
The numerical layer introduces another choice. Standard atomic weights describe terrestrial isotope-abundance averages, and some are intervals rather than single universal values. Representative abridged values are suitable for typical stoichiometry, provided the dataset and rounding convention are known.
Monoisotopic and nominal masses are different functions over the same formula and need different source data. Some inputs cannot resolve to one answer. Structural isomers share a composition vector and hence a molar mass.
A polymer with unspecified n describes a family of vectors. Mixtures, uncertain solvates, and nonstoichiometric phases need additional composition information. Ion calculations at very high precision may further require explicit treatment of electron removal or addition.