Refinement of DevCPP.GetCode

Refinement of DevCPP.GetCode

Postby Zorko » Thu Apr 19, 2018 3:53 pm

I suggest this refinement of DevCPP.GetCode. This will make the check of syntax more correct. I used {code} here because [ code ] is a forum tag.

Code: Select all
MODULE PrivTestCodeProc; IMPORT SYSTEM;

PROCEDURE {code} Proc1 ,,,,,,,, "", "", "", 9,  "", "",,,,,,,, ; (* <= now it compiles! *)
PROCEDURE {code} Proc2 12 34;                                    (* <= error "," comma missing *)
PROCEDURE {code} Proc3 "12" "34";                                (* <= error ";" semicolon missing *)

END PrivTestCodeProc.


The improvement based on the clarification of Josef Templ that it is undesirable to check semicolon inside GetCode.

I suggest a few things:

1. Allowing empty string as a part of a code procedure body does not make sense. It's not even ASCIIZ string! Therefore, when empty string is encountered in the description of a code procedure, I propose to mark it by error "63 illegal value of constant".

2. We must make sure that after comma the following literal (sym = number OR sym = string) always follows. Comma or something else (not number and not string) after comma are not allowed and must be marked as error "13 factor starts with incorrect symbol".

Code procedures with empty body still possible.

The code changes as follows:

GetCode.png

This piece of code in text format:

Code: Select all
         LOOP
            IF sym = number THEN ...
            ELSIF sym = string THEN c := DevCPS.intval - 1 (*exclude 0X*);
               IF c = 0 (*empty string*) THEN err(63) END; EnsureLen(n + c);
               FOR i := 0 TO c - 1 DO s[n + i] := DevCPS.str[i] END;
               DevCPS.Get(sym); INC(n, c)
            END ;
            IF sym = comma THEN DevCPS.Get(sym); IF (sym # number) & (sym # string) THEN err(13) END
            ELSIF (sym = number) OR (sym = string) THEN err(comma)
            ELSE EXIT
            END
         END;
Last edited by Zorko on Fri Apr 20, 2018 12:18 pm, edited 2 times in total.
Zorko
 
Posts: 11
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Refinement of DevCPP.GetCode

Postby Zorko » Thu Apr 19, 2018 5:52 pm

And even it's not all. Because it is still possible to write this, and it will be accepted by GetCode:

Code: Select all
PROCEDURE {code} Proc , 1 ;


To correct this situation, I propose to add another check before entering the processing cycle:

Code: Select all
      PROCEDURE GetCode;
      ...
      BEGIN
         n := 0; NEW(s, 64); IF sym = comma THEN err(13) END;
         LOOP
         ...
Zorko
 
Posts: 11
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Refinement of DevCPP.GetCode

Postby Josef Templ » Thu Apr 26, 2018 2:01 pm

In principle, I agree that a code procedure with multiple commas without any string or number in between
should be marked as a syntax error.

However, since the compiler allowed this for several decades, there may be code out there that is using
this syntax. Changing this in the compiler bears the danger of making existing code invalid,
which is only justified if there is a significant advantage on the other side.

I am not sure that the fix brings an advantage large enough to justify possible incompatibilities.

- Josef
Josef Templ
 
Posts: 195
Joined: Tue Sep 17, 2013 6:50 am

Re: Refinement of DevCPP.GetCode

Postby Zinn » Tue May 01, 2018 6:58 pm

Josef Templ wrote:> I am not sure that the fix brings an advantage large enough to justify possible incompatibilities.

Yes, every change is a risk. It is the same situation as adding detecting IN errors in the past. Getting better error detections is an advantage. We should keep this solution for the next round of change. It is not urgent. So we can wait. But the last succession should be discard. An empty parameter should allow as it is now. That minimise the problem with incompatibilities.
- Helmut

Supplement: I have done a mistake. Both changes are useful. I add it in the CPC-Edition (not uploaded) for testing and found no problems.
Last edited by Zinn on Mon May 07, 2018 5:51 am, edited 1 time in total.
Zinn
 
Posts: 58
Joined: Mon Nov 24, 2014 10:47 am

Re: Refinement of DevCPP.GetCode

Postby Zorko » Tue May 01, 2018 7:05 pm

I'm sure that if there is somewhere code that uses this incorrect syntax (with multiple commas) then this code is worthy of minor correction. In any case this situation will not create any serious problems. Agree with me, please. :-)
Zorko
 
Posts: 11
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Refinement of DevCPP.GetCode

Postby Zorko » Tue May 01, 2018 7:09 pm

Helmut, I totally agreed with you. An empty parameter should allow as it is now. My corrections do not affect the empty parameters. It only strengthens the checking of incorrect syntax in declaration of code procedures (empty strings, multiple and missed commas).
Zorko
 
Posts: 11
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Refinement of DevCPP.GetCode

Postby Josef Templ » Wed May 02, 2018 5:08 am

Zinn wrote:
Josef Templ wrote:> I am not sure that the fix brings an advantage large enough to justify possible incompatibilities.

Yes, every change is a risk. It is the same situation as adding detecting IN errors in the past. Getting better error detections is an advantage. We should keep this solution for the next round of change. It is not urgent. So we can wait. But the last succession should be discard. An empty parameter should allow as it is now. That minimise the problem with incompatibilities.
- Helmut


Helmut, what do you mean with 'But the last succession should be discard.'?
Can you give an example.

- Josef
Josef Templ
 
Posts: 195
Joined: Tue Sep 17, 2013 6:50 am

Re: Refinement of DevCPP.GetCode

Postby Josef Templ » Wed May 02, 2018 5:12 am

Zorko wrote:I'm sure that if there is somewhere code that uses this incorrect syntax (with multiple commas) then this code is worthy of minor correction. In any case this situation will not create any serious problems. Agree with me, please. :-)


If there is any problem, it would would be detected by the the compiler and it would be easy to fix.
Therefore I agree that there is only a small problem with this change.

How is this handled in the oberoncore version?

- Josef
Josef Templ
 
Posts: 195
Joined: Tue Sep 17, 2013 6:50 am

Re: Refinement of DevCPP.GetCode

Postby Zorko » Wed May 02, 2018 5:57 pm

OberonCore did not accept any of our improvements of GetCode. It applies to the removal of the limit for the size of a code procedure (my correction) and the ability to specify several strings in a code procedure (the correction proposed by Josef).

Accordingly, I am sure that they will not accept this correction too.

Did they know about the proposed modification? Yes, it is certain. There is simply a great deal of conservatism about the changes, especially relating to the compiler or the kernel.
Zorko
 
Posts: 11
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: Refinement of DevCPP.GetCode

Postby Josef Templ » Fri May 11, 2018 9:05 am

Please have a look at http://blackboxframework.org/unstable/issue-%23186/blackbox-1.7.2-a1.1021.zip for a
version of BlackBox that contains an improved DevCPP.GetCode procedure.
It reports syntax errors according to the spec and it allows arbitrary constant expressions
not just integer and string literals.

The topic is discussed in the center forum at https://forum.blackboxframework.org/viewtopic.php?f=40&t=715.

For the changes see https://redmine.blackboxframework.org/projects/blackbox/repository/diff?utf8=%E2%9C%93&rev=b78e384b028bb74be095e1dcd3449b7756f7082e&rev_to=a8b5479d55774c467572f100314900a4d9f1453b.

- Josef
Josef Templ
 
Posts: 195
Joined: Tue Sep 17, 2013 6:50 am

Next

Return to Bug

Who is online

Users browsing this forum: No registered users and 0 guests

cron