Skip to content

exception on simple calculatorexample #103

Description

@PaltryProgrammer

Greetings & Kind Regards Thank You for providing cparse

Compiled C++20 Visual C++ 2022
The code below copied from README.md threw an exception on calculator::calculate("-pi+1", &vars) Please see GIF attached. It seems op of '-' is an "Invalid operator" according to calculator::toRPN(const char* expr, TokenMap vars, const char* delim, const char** rest, Config_t config) Please advise Thank You Kindly
exception

#include <iostream>
#include "shunting-yard.h"

int main() {
  TokenMap vars;
  vars["pi"] = 3.14;
  std::cout << calculator::calculate("-pi+1", &vars) << std::endl;

  // Or if you want to evaluate an expression
  // several times efficiently:
  calculator c1("pi-b");
  vars["b"] = 0.14;
  std::cout << c1.eval(vars) << std::endl; // 3
  vars["b"] = 2.14;
  std::cout << c1.eval(vars) << std::endl; // 1

  return 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions