Utils: Extract expression evaluation loop to Expression.cpp

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I22e7577f47cabb3fce68e90bbd71331d78b09590
diff --git a/src/Expression.cpp b/src/Expression.cpp
index 43fcaf7..b3f21d9 100644
--- a/src/Expression.cpp
+++ b/src/Expression.cpp
@@ -17,6 +17,7 @@
 
 #include "Expression.hpp"
 
+#include <iostream>
 #include <stdexcept>
 
 namespace expression
@@ -76,4 +77,40 @@
             throw std::invalid_argument("Unrecognised operation");
     }
 }
+
+int evaluate(int substitute, std::vector<std::string>::iterator& curr,
+             std::vector<std::string>::iterator&& end)
+{
+    bool isOperator = true;
+    std::optional<Operation> next = Operation::addition;
+
+    for (; curr != end; curr++)
+    {
+        if (isOperator)
+        {
+            next = expression::parseOperation(*curr);
+            if (!next)
+            {
+                break;
+            }
+        }
+        else
+        {
+            try
+            {
+                int constant = std::stoi(*curr);
+                substitute = evaluate(substitute, *next, constant);
+            }
+            catch (const std::invalid_argument&)
+            {
+                std::cerr << "Parameter not supported for templates " << *curr
+                          << "\n";
+                continue;
+            }
+        }
+        isOperator = !isOperator;
+    }
+
+    return substitute;
+}
 } // namespace expression