Open flueke opened 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.
@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
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.
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.3Do 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