Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

package logo

usage

create local instance of expression parser.

final expressionparser expressionparser = expressionparser();

then you can calculate your “string” expression like:

final string exp = "-2 + 5 + 10 * 2";
final double? result = expressionparser.calculate(); // result would be 23

when we call calculate, it checks the validness of expression automatically.
so, we needn’t to do some manual checking here. (if expression is invalid, then result would be null)

but in anyways, if you wanna check the validness of expression manually, you can do it, like:

final bool isvalid = expressionparser.isinvalidoperation(exp) // would be false

check official example to see the ui implementation of mate

explanation

parser divides string expression as parts (stores them in custom expression class), then loops through the parts and takes sum of them.
if string expression is "2+5" then parts would be: ["2", "+5"]. so the sum of parts would be 2+(+5) –> 7.

let’s see with default expression: "-2 + 5 + 10 * 2".
in this case, parts would be: ["-2", "+5", "10*2"]. we got "10*2" at the end of the part, because of operation priority.
so, the final result would be: -2+(+5)+(10*2) –> 3+20 –> 23.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.