4 int number_from_pos(string form
, int& index
)
6 if (index
< 0 || index
>= form
.length())
11 while (isdigit(form
.at(index
)))
14 res
+= (form
[index
] - '0');
15 if (++index
>= form
.length())
23 vector
<int> parse_from_pos(string form
, vector
<element
> e
, int& index
)
28 result
.resize(e
.size());
29 tmpres
.resize(e
.size());
32 cerr
<< "Index greater than size of formula!" << endl
;
36 cerr
<< "Index is negative!" << endl
;
38 while (i
< form
.size())
44 tmpres
= parse_from_pos(form
, e
, i
);
45 // i now points at the first character *AFTER* closing parenthesis
46 if (i
< form
.size() && isdigit(form
[i
]))
48 int multiply
= number_from_pos(form
, i
);
49 mulv(tmpres
, multiply
);
60 while (i
< form
.size() && isalpha(c
= form
[i
++]))
64 if ((fi
= find_symbol(e
, z
)) != -1)
67 flag
|= (i
>= form
.size());
70 flag
|= !islower(form
[i
]);
81 int multiply
= number_from_pos(form
, i
);
82 mulv(tmpres
, multiply
);
87 tmpres
.resize(e
.size());
93 void parse(string form
, vector
<element
> e
, vector
<int>& result
)
96 result
= parse_from_pos(form
, e
, _i
);
97 if (_i
!= form
.length())
99 cerr
<< "Final index is NOT the length of formula string." << endl
;