Page 2 of 3

Re: KeyWord

Posted: Sat Dec 15, 2018 11:04 am
by Robert
As far as I can tell the only keywords are "VAR", "IN", & "OUT".

"ABSTRACT", EXTENSIBLE", & "LIMITED" are reserved words, which "cannot be used as identifiers" (paragraph 3.5).
So the ObxKW module looks illegal, and should be rejected by the compiler.

If (I haven't tested it myself) adding the line in luowy's post of 3-Dec-2017 implements that behaviour I would support it.

Re: KeyWord

Posted: Sat Dec 15, 2018 11:13 am
by Robert
If in module ObxKW I replace "ABSTRACT" by "EMPTY" it still compiles. So the problem (if it is a problem) is more general than currently reported.

Re: KeyWord

Posted: Sat Dec 15, 2018 1:28 pm
by Josef Templ
How can a name (NEW) be a standard procedure AND a reserved word at the same time?
It can be either the one or the other, but not both. Or can it?

- Josef

Re: KeyWord

Posted: Sat Dec 15, 2018 3:18 pm
by Robert
Josef Templ wrote:How can a name (NEW) be a standard procedure AND a reserved word at the same time?
It can be either the one or the other, but not both. Or can it?
VAR, IN, & OUT are both keywords & reserved words, so maybe there is no problem with NEW being two things. But NEW is not a reserved word (see para 3.5), so this question does not arise.

In the module

Code: Select all

MODULE  RdcReserved;

PROCEDURE  Do*;
  VAR
    xxx  :  INTEGER;
  BEGIN
  END  Do;

END  RdcReserved.
I have replaced the identifier "xxx" with all the reserved words, and those that currently compile ok are: ABSTRACT, EMPTY, EXTENSIBLE, LIMITED.

Those that cause 1 (or more) compilation errors are: ARRAY, BEGIN, BY, CASE, CLOSE, CONST, DIV, DO, ELSE, ELSIF, END, EXIT, FOR, IF, IMPORT, IN, IS, LOOP, MOD, MODULE, NIL, OF, OR, OUT, POINTER, PROCEDURE, RECORD, REPEAT, RETURN, THEN, TO, TYPE, UNTIL, VAR, WHILE, WITH.

Re: KeyWord

Posted: Sat Dec 15, 2018 3:29 pm
by Robert
cfbsoftware wrote:The fact that NEW has a split personality being both a predefined object and a keyword makes it an exception ...
NEW appears to be a predeclared identifier, a standard procedure, and a method attribute.

It does not appear to be a keyword or a reserved word.

Re: KeyWord

Posted: Sat Dec 15, 2018 7:07 pm
by Josef Templ
Robert, what is the difference between a reserved word and a keyword?

- Josef

Re: KeyWord

Posted: Sat Dec 15, 2018 7:54 pm
by Robert
Do searches in the Language Report:

- "keyword" only appears in paragraph 10.1 to describe "IN", "OUT", or "VAR"

- "reserved" only appears in paragraph 3.5 and describes "ABSTRACT", ..., "WITH".

Re: KeyWord

Posted: Sat Dec 15, 2018 10:28 pm
by cfbsoftware
Josef Templ wrote:How can a name (NEW) be a standard procedure AND a reserved word at the same time?
It can be either the one or the other, but not both. Or can it?
NEW isn't both 'at the same time' - it can be context sensitive. Consider this example:

Code: Select all

MODULE CfbNew;

TYPE
  T = RECORD i: INTEGER END;

VAR
  ptr: POINTER TO ARRAY OF CHAR;
  i: INTEGER;

PROCEDURE P0;
BEGIN
  NEW(ptr, 10)
END P0;

PROCEDURE (VAR t: T) P(x: INTEGER), NEW;
BEGIN
END P;

PROCEDURE NEW(VAR i: INTEGER);
BEGIN
  i := 0
END NEW;

BEGIN
  NEW(i);
  NEW(ptr, 10)
END CfbNew.
Now move the declaration of procedure NEW above procedure P. This only goes to show that the decision to reuse the name of a standard procedure (identifier) as an attribute (reserved word) was not a good one. The way NEW works (or more to the point - doesn't work) should not be used as an example of how the rest of the language should work. If anything needs to be fixed it is NEW but it is probably way too late to put that genie back into the bottle.

Re: KeyWord

Posted: Sun Dec 16, 2018 9:13 am
by Robert
cfbsoftware wrote:This only goes to show that the decision to reuse the name of a standard procedure (identifier) as an attribute (reserved word) was not a good one.
In don't really understand why this conclusion follows. The conclusion I draw is that it is unhelpful for a programmer to redefine any of the predeclared identifiers. If I had called the procedure ASSERT or ORD rather than NEW I would regard that as a bad idea.

Calling it ORD I would loose a useful language feature. Calling it NEW I loose two. Isn't the genie the fact that predeclared identifiers can be redefined at all?

Re: KeyWord

Posted: Sun Dec 16, 2018 3:23 pm
by Josef Templ
Robert wrote:Do searches in the Language Report:

- "keyword" only appears in paragraph 10.1 to describe "IN", "OUT", or "VAR"

- "reserved" only appears in paragraph 3.5 and describes "ABSTRACT", ..., "WITH".
There is no distinction between a keyword and a reserved word here.
It is used as a synonym. Keyword is just a slightly shorter and less precise word.

- Josef