Comments (7)
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.
@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.
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.
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.
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.
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.
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)
- exception on simple calculatorexample
- Segmentation fault on bad inputs
- group/vector operation possible? Naive iteration can be expensive when number of elements is huge HOT 5
- terminating with uncaught exception of type syntax_error: Invalid operator: - HOT 4
- Token names cannot have UTF8 characters HOT 4
- Project doesn't install anything HOT 10
- Syntax errors cause crashes HOT 21
- Hexadecimal number computation HOT 4
- calculator ignores variable HOT 3
- Consider adding a namespace to cparse code HOT 6
- Program treats "." in numeric "0.x" as an operator and throw an exception! HOT 5
- Thread Safety HOT 4
- Is not operator supported? HOT 1
- Warning c4099 is everywhere. HOT 3
- Invalid operators, but with ALL operators HOT 1
- It doesn't compile in Windows and Linux, am I doing something wrong? HOT 3
- Buffer-overflow (out-of-bounds read) occured in two positions HOT 1
- cparse/builtin-features/operators.inc HOT 9
- Solved. Errors with Linux emulator using GCC. HOT 22
- TokenMap value change to None,when using getChild() HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cparse.