Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When calculating an expression, an error is reported if the expression has [] in it. #337

Closed
landonzeng opened this issue Nov 21, 2024 · 6 comments
Labels

Comments

@landonzeng
Copy link

Error in calculation of (-CWPT_007_P)+[1-(-0.3)]: Expression expected (at index 14).
image
image
image

@davideicardi
Copy link
Member

Can you post some actual text code to reproduce the problem?

@metoule
Copy link
Contributor

metoule commented Nov 22, 2024

You're using brackets as parenthesis, which is not supported:

(-23)+[1-(-0.3)]

should be

(-23)+(1-(-0.3))

@landonzeng
Copy link
Author

You're using brackets as parenthesis, which is not supported:

(-23)+[1-(-0.3)]

should be

(-23)+(1-(-0.3))

I can understand using parentheses to replace square brackets, e.g. (-23)+(1-(-0.3)), but there are square bracketed expressions in mathematical logic, which can be confusing for the user

@landonzeng
Copy link
Author

landonzeng commented Nov 25, 2024

Can you post some actual text code to reproduce the problem?

Sample code for example:

static void Main(string[] args)
{
    var interpreter = new Interpreter();
    var parameters = new[] {
        new Parameter("CWPT_007_P", 23),
        new Parameter("CWPT_007_S", -0.3),
    };
    var value= interpreter.Eval("(-CWPT_007_P)+[1-(CWPT_007_S+5)]", parameters);  
    Console.WriteLine($"value: {value}");
}

@davideicardi
Copy link
Member

I agree with you @landonzeng , but DynamicExpresso is not a math interpreter, the goal is to create a C# interpreter.
If you realy want to use DynamicExpresso for math maybe you can try to do some preprocessing first, for example replacing [ ] with ( ). But I suspect that it is not the right tool to be honest.

@landonzeng
Copy link
Author

landonzeng commented Nov 26, 2024

I agree with you @landonzeng , but DynamicExpresso is not a math interpreter, the goal is to create a C# interpreter. If you realy want to use DynamicExpresso for math maybe you can try to do some preprocessing first, for example replacing [ ] with ( ). But I suspect that it is not the right tool to be honest.

Yes, that's what I was thinking, I had to replace [] with () if I wanted to fulfil a customer request and that was it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants