flueke / mvme

mvme - mesytec VME data acquisition
GNU General Public License v3.0
11 stars 7 forks source link

exprtk-0.0.3 in mvme #15

Open flueke opened 1 week ago

flueke commented 1 week ago

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 https://github.com/flueke/mvme/issues/13#issuecomment-2485893788

ArashPartow commented 1 week ago

@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 commented 1 week ago

@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 commented 1 week ago

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_string1should be fine, but expression_string2will result in an error when settings_t::e_commutative_check is disabled.