Page 1 of 2

Refinement of DevCPP.GetCode

Posted: Thu Apr 19, 2018 3:53 pm
by Zorko
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;

Re: Refinement of DevCPP.GetCode

Posted: Thu Apr 19, 2018 5:52 pm
by Zorko
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
			...

Re: Refinement of DevCPP.GetCode

Posted: Thu Apr 26, 2018 2:01 pm
by Josef Templ
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

Re: Refinement of DevCPP.GetCode

Posted: Tue May 01, 2018 6:58 pm
by Zinn
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.

Re: Refinement of DevCPP.GetCode

Posted: Tue May 01, 2018 7:05 pm
by Zorko
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. :-)

Re: Refinement of DevCPP.GetCode

Posted: Tue May 01, 2018 7:09 pm
by Zorko
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).

Re: Refinement of DevCPP.GetCode

Posted: Wed May 02, 2018 5:08 am
by Josef Templ
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

Re: Refinement of DevCPP.GetCode

Posted: Wed May 02, 2018 5:12 am
by Josef Templ
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

Re: Refinement of DevCPP.GetCode

Posted: Wed May 02, 2018 5:57 pm
by Zorko
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.

Re: Refinement of DevCPP.GetCode

Posted: Fri May 11, 2018 9:05 am
by Josef Templ
Please have a look at http://blackboxframework.org/unstable/i ... 1.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/vie ... f=40&t=715.

For the changes see https://redmine.blackboxframework.org/p ... a4d9f1453b.

- Josef