26 #include <agrum/core/math/cocoR/Parser.h> 27 #include <agrum/core/math/cocoR/Scanner.h> 37 std::cout << std::endl;
38 std::list< FormulaPart > l;
40 l.push_front(s.top());
44 std::cout <<
"Stack: ";
45 for (
const auto& elt : l) {
46 std::cout << elt.str() <<
" ";
48 std::cout << std::endl;
53 std::cout <<
"Output: ";
54 for (
const auto& elt : v) {
55 std::cout << elt.str() <<
" ";
57 std::cout << std::endl;
62 case FormulaPart::token_function::exp: {
65 case FormulaPart::token_function::log: {
68 case FormulaPart::token_function::ln: {
71 case FormulaPart::token_function::pow: {
74 case FormulaPart::token_function::sqrt: {
77 case FormulaPart::token_function::nil: {
87 type(
token_type::NIL), number(NAN), character(
'\0'), function(nil) {
122 if (
this == &source) {
return *
this; }
133 if (
this == &source) {
return *
this; }
135 type = std::move(source.type);
136 number = std::move(source.number);
138 function = std::move(source.function);
144 std::ostringstream s;
146 case token_type::NUMBER: {
151 case token_type::PARENTHESIS:
152 case token_type::OPERATOR: {
161 case token_type::FUNCTION: {
178 auto c_str = (
unsigned char*)__formula.c_str();
179 auto scanner =
new gum::formula::Scanner(c_str, (
int)__formula.size());
180 __scanner = std::unique_ptr< gum::formula::Scanner >(scanner);
182 auto parser =
new gum::formula::Parser(scanner);
183 __parser = std::unique_ptr< gum::formula::Parser >(parser);
184 __parser->formula(
this);
275 if (
this == &source) {
return *
this; }
288 if (
this == &source) {
return *
this; }
292 __parser = std::move(source.__parser);
295 __output = std::move(source.__output);
296 __stack = std::move(source.__stack);
304 std::stack< FormulaPart > stack;
309 case FormulaPart::token_type::NUMBER: {
314 case FormulaPart::token_type::OPERATOR:
315 case FormulaPart::token_type::FUNCTION: {
322 "expecting numbers, operators or functions");
327 if (stack.size() != 1) {
330 }
else if (stack.top().type != FormulaPart::token_type::NUMBER) {
333 return stack.top().number;
340 #endif // GUM_NO_INLINE
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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)