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

exprtk-0.0.3 in mvme #15

Open
flueke opened this issue Nov 19, 2024 · 3 comments
Open

exprtk-0.0.3 in mvme #15

flueke opened this issue Nov 19, 2024 · 3 comments

Comments

@flueke
Copy link
Owner

flueke commented Nov 19, 2024

I had to revert the merge because it broke some existing user scripts in mvme. It's related to
expression/block contexts and the use/lack of semicolons.
I've created branches for 0.0.2 and 0.0.3 each containing a new exprtk_simple_example_25.cpp program:
https://github.com/flueke/exprtk/tree/SemicolonForContext-0.0.2
https://github.com/flueke/exprtk/tree/SemicolonForContext-0.0.3

Do I have to set a new option to get the old behavior back with exprtk-0.0.3?

Best,
Florian

Originally posted by @flueke in #13 (comment)

@ArashPartow
Copy link
Contributor

ArashPartow commented Nov 20, 2024

@flueke Can you please link the scripts. or paste them here.

If all that is missing are semi-colons in end user scripts, wouldn't it be easier and a more robust solution to fix the scripts by adding the semi-colons?

Do I have to set a new option to get the old behavior back with exprtk-0.0.3?

Unfortunately there's no option in the parser to revert to the old behaviour, as the previous behaviour was buggy/incorrect. Explicitly adding semi-colons in expressions correctly terminates sub-statements in the expression.

Either way do let me know how you'd like to proceed.

@flueke
Copy link
Owner Author

flueke commented Nov 20, 2024

@ArashPartow Thank you for looking into this. These are the scripts from my exprtk_simple_example_25.cpp:

   const std::string expression_string1 =
      "for (var i := 0; i < 3; i += 1) { i; };\n"
      "for (var i := 0; i < 3; i += 1) { i * i; };\n"
      "for (var i := 0; i < 3; i += 1) { i * i * i; };\n";

   const std::string expression_string2 =
      "for (var i := 0; i < 3; i += 1) { i; }\n"
      "for (var i := 0; i < 3; i += 1) { i * i; }\n"
      "for (var i := 0; i < 3; i += 1) { i * i * i; }\n";

It's only about the semicolons after the closing braces of the for loops. In all other places
we do use semicolons to correctly terminate expressions/statements.

Direct link to the code: exprtk_simple_example_25.cpp

@ArashPartow
Copy link
Contributor

ArashPartow commented Nov 20, 2024

In the current version of ExprTk when settings_t::e_commutative_check is disabled in the parser settings, as is the case in mvme, there is now an explicit check (that spans multiple areas) to ensure the block structure statements such as for/while/repeat/if etc are all correctly terminated.

This is more of a tightening up of the statement termination requirements, and is also intended to reduce any surprises if expressions are recompiled with the settings_t::e_commutative_check enabled, as it will result in an implied multiplication and a completely different outcome.

So based on the above example, I'd say expression_string1 should be fine, but expression_string2 will result in an error when settings_t::e_commutative_check is disabled.

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

No branches or pull requests

2 participants