24 #include <agrum/core/math/cocoR/Parser.h> 25 #include <agrum/core/math/cocoR/Scanner.h> 35 std::cout << std::endl;
36 std::list< FormulaPart > l;
38 l.push_front(s.top());
42 std::cout <<
"Stack: ";
43 for (
const auto& elt : l) {
44 std::cout << elt.str() <<
" ";
46 std::cout << std::endl;
51 std::cout <<
"Output: ";
52 for (
const auto& elt : v) {
53 std::cout << elt.str() <<
" ";
55 std::cout << std::endl;
60 case FormulaPart::token_function::exp: {
63 case FormulaPart::token_function::log: {
66 case FormulaPart::token_function::ln: {
69 case FormulaPart::token_function::pow: {
72 case FormulaPart::token_function::sqrt: {
75 case FormulaPart::token_function::nil: {
83 type(
token_type::NIL), number(NAN), character(
'\0'), function(nil) {
118 if (
this == &source) {
return *
this; }
129 if (
this == &source) {
return *
this; }
131 type = std::move(source.type);
132 number = std::move(source.number);
134 function = std::move(source.function);
140 std::ostringstream s;
142 case token_type::NUMBER: {
147 case token_type::PARENTHESIS:
148 case token_type::OPERATOR: {
157 case token_type::FUNCTION: {
172 auto c_str = (
unsigned char*)__formula.c_str();
173 auto scanner =
new gum::formula::Scanner(c_str, (
int)__formula.size());
174 __scanner = std::unique_ptr< gum::formula::Scanner >(scanner);
176 auto parser =
new gum::formula::Parser(scanner);
177 __parser = std::unique_ptr< gum::formula::Parser >(parser);
178 __parser->formula(
this);
269 if (
this == &source) {
return *
this; }
282 if (
this == &source) {
return *
this; }
286 __parser = std::move(source.__parser);
289 __output = std::move(source.__output);
290 __stack = std::move(source.__stack);
298 std::stack< FormulaPart > stack;
303 case FormulaPart::token_type::NUMBER: {
308 case FormulaPart::token_type::OPERATOR:
309 case FormulaPart::token_type::FUNCTION: {
316 "expecting numbers, operators or functions");
321 if (stack.size() != 1) {
324 }
else if (stack.top().type != FormulaPart::token_type::NUMBER) {
327 return stack.top().number;
334 #endif // GUM_NO_INLINE
gum is the global namespace for all aGrUM entities
std::string func2str(FormulaPart::token_function func)
std::string to_string(const Formula &f)
void print_stack(std::stack< FormulaPart > s)
void print_output(std::vector< FormulaPart > v)
#define GUM_ERROR(type, msg)