Code Monkey home page Code Monkey logo

Comments (7)

VinGarcia avatar VinGarcia commented on May 29, 2024

Hello @grazba, this is called operator precedence.

What you are saying you want is for the operator "." to have greater precedence than the operator "+" meaning it will be evaluated first, as in:

  • a*b + c*d

Where the "+" operator will be evaluated last.

In CParse the operator precedence of each operator is defined using the calculator::Default().opPrecedence API, e.g.:

OppMap_t& opp = calculator::Default().opPrecedence;
// Note: The smaller the number the smaller the precedence:
opp.add("*", 1);
opp.add("+", 2);

So in your case it is likely that the number associated with "." is greater than the number associated with "+". You will need to move one of them up or down.

There is a short section in Defining New Operations page about this. Maybe it can help you further.

In any case I hope this solves you problem, if not tell me.

from cparse.

VinGarcia avatar VinGarcia commented on May 29, 2024

@grazba, one more thing. I have had another user wanting to use Visual Studio on his project. So I wrote some documentation based on your issue and his feedbacks in the Download and Setup page. If you have some minutes could you read it and see if what I wrote makes sense?

I ask this because I don't have a VS environment to test that.

Thanks in advance =]

from cparse.

 avatar commented on May 29, 2024

yeah that's exactly what i was suspecting hence the name of the issue but i was not sure so yeah thanks i will try to fix it and close the issue when done.

For the the visual studio part , yes i will check the doc out and get back to you 👍 !

from cparse.

VinGarcia avatar VinGarcia commented on May 29, 2024

Ops, I did not notice the name hehe, sorry. In any case, this looks like the kind of problem that would be fixed by changing the precedence values. I might be wrong since these expressions are complex but if this doesn't work tell me.

Also, there is a function I use to debug this type of expressions the calculator::str() function. You can use it like this:

calculator c1("W(\"name1\").L(\"name2\") + W(\"name1\").L(\"name3\")");
std::string rpn = c1.str();
std::cout << rpn << std::endl;

The result will show the operands and operators in Reverse Polish Notation. This notation shows exactly the order that the operations will take place, e.g.:

  • a b c + -

Would be the same as:

  • a - (b + c)

I.e. each operator operates on the previous 2 operands immediately before it.

This might help to understand how the expressions are being interpreted internally.

from cparse.

 avatar commented on May 29, 2024

Thanks for the details it's pretty helpful for debugging indeed !

For the visual studio part, yes it is alright the only little detail is the note about c++ 11 support. The compiler always had issues with covering all of the standard , but since 2017 they are working hard on supporting c++ 11/14/17 and it should be 100% standard pretty soon, visual studio 2013 does support c++11 but doesn't support some features of the language in the case of CParse the only feature missing is reference qualifiers so i think the note should be check the compiler support of c++ features.

the precedence of operators did the trick everything is working smoothly, more features to add.

Thanks again !

from cparse.

VinGarcia avatar VinGarcia commented on May 29, 2024

That's good @grazba and thanks for the feedback.

But give a little more details: this problem with the reference qualifiers causes the compilation to break or it works fine? Also, sorry to bother you with these questions =P.

from cparse.

 avatar commented on May 29, 2024

with VS2013 it won't compile , but deleting the "&&" after the function name (i forgot which one it was) will make it work just fine. The feature is available since VS2015 !

Here you can find details about standard support for visual studio maybe you can link it to the users :
support for c++ 11-14-17 with visual studio

from cparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.