A graph is convenient for a human and awkward for a model that reads sequences. SMILES solves that by flattening the graph into a string. The rules are few.
Atoms are written in order along a path through the molecule. A bond is implied between consecutive atoms unless stated otherwise. A branch is opened with an opening parenthesis and closed with a closing parenthesis, so the atoms inside the parentheses hang off the atom that precedes the opening parenthesis. A ring is written by labelling the two atoms that close it with the same digit, which tells the reader that those two atoms are bonded even though they are far apart in the string.
For ethanol, \(\mathrm{CCO}\), the string reads as a carbon bonded to a carbon bonded to an oxygen. For acetic acid, \(\mathrm{CC(=O)O}\), the third atom is a carbon that carries a branch: the \(\mathrm{=O}\) inside the parentheses is a double-bonded oxygen hanging off it, and the final \(\mathrm{O}\) continues the main chain. For benzene, \(\mathrm{c1ccccc1}\), the two \(\mathrm{1}\) labels close a six-membered ring; the lowercase letters signal aromatic carbons.
Two things follow. First, one molecule has many valid SMILES strings, because you may start the walk at any atom and go around a ring in either direction. Second, a string that looks perfectly well-formed can still describe something impossible, such as a carbon with five bonds — the syntax does not enforce the chemistry. Both facts matter later, when a model is asked to produce strings rather than read them.