Squashed 'third_party/boostorg/function_types/' content from commit ae4fde2
Change-Id: I946aaade9862a3a50fdce89fbc618c914b0edae6
git-subtree-dir: third_party/boostorg/function_types
git-subtree-split: ae4fde2e2ae88291d6d656137169ff4003d184a1
diff --git a/example/interpreter_example.cpp b/example/interpreter_example.cpp
new file mode 100644
index 0000000..9e6118b
--- /dev/null
+++ b/example/interpreter_example.cpp
@@ -0,0 +1,56 @@
+
+// (C) Copyright Tobias Schwinger
+//
+// Use modification and distribution are subject to the boost Software License,
+// Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
+
+//------------------------------------------------------------------------------
+
+#include <string>
+#include <iostream>
+#include <stdexcept>
+
+#include "interpreter.hpp"
+
+void echo(std::string const & s)
+{
+ std::cout << s << std::endl;
+}
+
+void add(int a, int b)
+{
+ std::cout << a + b << std::endl;
+}
+
+void repeat(std::string const & s, int n)
+{
+ while (--n >= 0) std::cout << s;
+ std::cout << std::endl;
+}
+
+int main()
+{
+ example::interpreter interpreter;
+
+ interpreter.register_function("echo", & echo);
+ interpreter.register_function("add", & add);
+ interpreter.register_function("repeat", & repeat);
+
+ std::string line = "nonempty";
+ while (! line.empty())
+ {
+ std::cout << std::endl << "] ", std::getline(std::cin,line);
+
+ try
+ {
+ interpreter.parse_input(line);
+ }
+ catch (std::runtime_error &error)
+ {
+ std::cerr << error.what() << std::endl;
+ }
+ }
+
+ return 0;
+}
+