TMS Script Parser behaves different than Delphi

Hello,

I had to investigate a problem (code written by some else).
The following code does not what it should do, because the programmer did some mistakes.

    if _TestrunDate1 > _TestrunDate2 then
      if not CheckTestDataOk (_SerialNo1, 'Plausibilität', _TestrunState1, _TestrunDate1, _ItemToCheck, 1) then _Status:= false
    else
      if not CheckTestDataOk (_SerialNo2, 'Plausibilität', _TestrunState2, _TestrunDate2, _ItemToCheck, 1) then _Status:= false;

Yes, it's uggly code and hardly readable. If _TestrunDate1 is bigger than _TestrunDate2, then CheckTestDataOk will be executed twice, which was not the intention of the programmer.
So the problem must be fixed by improving the code.

But the difference between Delphi and TMS-Scripter I found out, is about how this behaves when adding a semicolon after the first occurence of "_Status:=false".

    if _TestrunDate1 > _TestrunDate2 then
      if not CheckTestDataOk (_SerialNo1, 'Plausibilität', _TestrunState1, _TestrunDate1, _ItemToCheck, 1) then _Status:= false**;**
    else
      if not CheckTestDataOk (_SerialNo2, 'Plausibilität', _TestrunState2, _TestrunDate2, _ItemToCheck, 1) then _Status:= false;

The above code (added semicolon) is still executable in TMS-Scripter, but not compilable anymore within Delphi IDE ( which is better behavoir).

Btw. I would like to upload the example-script, but it is not possible because it's not allowed. File-extensions (.psc,.sfm,.ssproj) are not allowed on your upload.

Regards,
Sam

It's different behavior indeed. The semicolon in scripter is treated differently, it's even optional, actually. In case of doubt, always use begin..end constructions to avoid mistakes and ambiguity.

For attachments, you can compress the file(s) and send the .zip file attached.

I've found results of this behavior in case statements after changing to TMS Script.

Here is a modified version of your case statements sample:

{-------------------------------------------------------------
 This script shows how case statements can include expressions 
 ------------------------------------------------------------- }

NumberStr:='';
if InputQuery('Input', 'Type an integer number from 1 to 7', 
NumberStr) then
begin
   try
      Number:=StrToFloat(NumberStr);
   except
      raise('Not a valid number');
   end;

   case Number of 
      1 : ShowMessage('One');
      1+1 : ShowMessage('Two');
      4.5/1.5 : ShowMessage('Three');
      2*2 : ShowMessage('Four');
      Length('xxxxx') : ShowMessage('Five');
      3+3, 3+4: if Number = 6 then ShowMessage('Six') 
                  else if Number = 7 then ShowMessage('Seven');
   else
      ShowMessage('You did not type an integer from 1 to 7');
   end;

end;

Ignoring the semicolon makes the error handling ShowMessage unreachable, because it is part of the last case item.
As mentioned before I can modify the code with begin..end constructs, but our system contains 10000+ script parts...
If not covered by a test its not easy to find the affected ones. As a solution I have to parse the code with an other Parser an repair it.

Can you imagine to change this behavior?

I don't think so, unfortunately. It's important to mention that TMS Scripter is around for more than 20 years. Imagine the amount of existing code that relies on existing behavior. Changing scripting behavior, or even trying to change it is very sensitive and can affect many customers. We try not to change it unless it's absolute necessary.

Of course, this behavior change should be optional like ShortBooleanEval.

It's not trivial, unfortunately, because the parser is based on a full static, text-based grammar. It's not trivial to partially modify it, there is also the semantic analysis.