i
to 0.i
is less than the length of the formula:
a. If the current character is '(', push a new empty count map onto the stack.
b. If the current character is an uppercase letter, parse the element name and count. Update the count in the current scope.
c. If the current character is ')', pop the top count map off the stack, multiply its counts by the number following the ')', and add these counts to the next count map on the stack.