# Calculate arithmetic problem from text

**URL:** https://discussions.unity.com/t/calculate-arithmetic-problem-from-text/157404
**Category:** Questions & Answers
**Created:** [January 18, 2016, 11:04am UTC](https://discussions.unity.com/t/calculate-arithmetic-problem-from-text/157404 "2016-01-18T11:04:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![NoName115](https://avatars.discourse-cdn.com/v4/letter/n/e274bd/32.png) [@NoName115](https://discussions.unity.com/u/NoName115)
#### Post date: [January 18, 2016, 11:04am UTC](https://discussions.unity.com/t/calculate-arithmetic-problem-from-text/157404/1 "2016-01-18T11:04:47Z")

</div>

Is there any simple way,function or dictionary that can solve simple math problem (2 + 5 \* 8), and give me result in C#?? But if something like this exist in JavaScript, i am free to use it.  
Or i need code my own calculator?

---

<div class="post-metadata">

### Author: ![Pangamini](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pangamini/32/83036_2.png) [@Pangamini](https://discussions.unity.com/u/Pangamini)
#### Post date: [January 18, 2016, 11:42am UTC](https://discussions.unity.com/t/calculate-arithmetic-problem-from-text/157404/2 "2016-01-18T11:42:12Z")

</div>

You could write your own stack based expression interpreter, which is really not that complicated. You could even make this interpreter to create a .net DynamicMethod by emitting IL code, practially creating a code at runtime, making its execution super fast (provided you want to evaluate the same expression more than once).

Another option would be to use lua interpreter, or another language (for my ingaeme console i internally use Boo compiler, the same language that was recently dropped support for by unity).

But if you want to exercise yourself, trying to write your own stack based expression evaluator is not that much work

Note: CLI language compilers usually emit assemblies, which cannot be unloaded once loaded. This can be an advantage when you call the same expression more times (basically you create and load a DLL at runtime), but if you need to evaluate different string every frame, this will soon fill the memory
