28{
34 typedef typename compositor_t::function function_t;
35
36 T x = T(1);
37 T y = T(2);
38
39 compositor_t compositor;
40
41 symbol_table_t& symbol_table = compositor.symbol_table();
42 symbol_table.add_constants();
43 symbol_table.add_variable("x",x);
44 symbol_table.add_variable("y",y);
45
46 compositor.add(
47 function_t("f")
48 .var("x")
49 .expression( "sin(x / pi)" ));
50
51 compositor.add(
52 function_t("g")
53 .vars("x", "y")
54 .expression( "3*[f(x) + f(y)]" ));
55
56 std::string expression_string = "g(1 + f(x), f(y) / 2)";
57
58 expression_t expression;
59 expression.register_symbol_table(symbol_table);
60
61 parser_t parser;
62
63 if (!parser.compile(expression_string,expression))
64 {
65 printf("Error: %s\tExpression: %s\n",
66 parser.error().c_str(),
67 expression_string.c_str());
68
69 for (std::size_t i = 0; i < parser.error_count(); ++i)
70 {
71 const err_t error = parser.get_error(i);
72
73 printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
74 static_cast<unsigned int>(i),
75 static_cast<unsigned int>(error.token.position),
77 error.diagnostic.c_str(),
78 expression_string.c_str());
79 }
80
81 return;
82 }
83
84 const T result = expression.value();
85
86 printf("%s = %e\n", expression_string.c_str(), result);
87}
std::string to_str(error_mode mode)