Question: I've got a home automation system working in Java, and I want to add simple math capabilities such as addition, subtraction, multiplication, division, roots, and powers.

At the system current state, it can convert a phrase into tags, as shown in the following examples:

example:

```
Phrase: "what is one hundred twenty two to the power of seven"
Tagged: {QUESTION/math} {NUMBER/122} {MATH/pwr} {NUMBER/7}

```

example:

```
Phrase: "twenty seven plus pi 3 squared"
Tagged: {NUMBER/27} {MATH/add} {NUMBER/3.14159} {MATH/multiply} {MATH/pwr} {NUMBER/2}

```

This example could be just as easily converted to something like this:

```
27 + 3.14159 * 3^2

```

Each tag is an object that can be queried for it value.

**Edit: Specific question:**

So now I need a way to read that group of tags as an equation, and return a numerical result. As a last resort I could use google or wolfram alpha, but that will be slower, and I'm trying to keep the automation system completely self contained.

If you would like to see the entire source, [here it is in github.](https://github.com/Sprakle/HomeAutomation/tree/master/HomeAutomation)
Note that I have not committed the last few few changes, so some of the math related things I gave examples will not work.

Answer: 
After some more googleing (I didn't know the name for what I was doing at first) I found someone who has done something similar already:

<http://www.objecthunter.net/exp4j/>

Edit: Finished:
<https://github.com/Sprakle/HomeAutomation/blob/master/src/net/sprakle/homeAutomation/interpretation/module/modules/math/Math.java>
Ben, he's right. The parsing action that takes natural language is much more difficult. What you need to do is add math precedence to the expression. The way you do that is to put the expression in some expected form, like post/pre/in-fix and provide an evaluation algorithm(post-fix ends up being `pop(), pop(), evaluate(), push();`. This requires that you check the individual tokens against a table that investigates the intersection of the operators and operands. It isn't anything you can do quickly or easily.