#include <list>
#include <vector>
#include <map>
#include <functional>
#include <iostream>
#include <algorithm>
#include <initializer_list>

class program {
	typedef std::list <int> args_t;
	typedef std::function<int(int,int)> op_t;
	typedef std::vector <op_t> code_t;
	
	args_t args;
	code_t code;
	
	public:
	
	void compile (const std::string& expr) {
	  static std::map <char, op_t> op_map = {
	  	{'+', std::plus<int>() }
	   ,{'-', std::minus<int>() }
	  };
	
	  for (auto c: expr) {
	    isdigit(c) ? 
	    	args.push_back (c-'0') 
	      : code.push_back (op_map[c]);
	  }
	}

	int next_arg () {
		int arg = *args.begin (); args.pop_front();
		return arg;
	}

	int run () {
	  for (auto op: code) {
		int lhs = next_arg();
	  	int rhs = next_arg();
	    args.push_front (op (lhs, rhs));
	  }
	  return next_arg();
	}
};

int main()
{

  program p;
  p.compile ("7+3-2+5");
  int result = p.run ();
  std::cout << result; // 13
}
