KeyWord

Re: KeyWord

Postby Robert » Sat Dec 15, 2018 11:04 am

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.
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby Robert » Sat Dec 15, 2018 11:13 am

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.
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby Josef Templ » Sat Dec 15, 2018 1:28 pm

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
User avatar
Josef Templ
 
Posts: 2011
Joined: Tue Sep 17, 2013 6:50 am

Re: KeyWord

Postby Robert » Sat Dec 15, 2018 3:18 pm

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.
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby Robert » Sat Dec 15, 2018 3:29 pm

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.
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby Josef Templ » Sat Dec 15, 2018 7:07 pm

Robert, what is the difference between a reserved word and a keyword?

- Josef
User avatar
Josef Templ
 
Posts: 2011
Joined: Tue Sep 17, 2013 6:50 am

Re: KeyWord

Postby Robert » Sat Dec 15, 2018 7:54 pm

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".
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby cfbsoftware » Sat Dec 15, 2018 10:28 pm

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.
cfbsoftware
 
Posts: 203
Joined: Wed Sep 18, 2013 10:06 pm

Re: KeyWord

Postby Robert » Sun Dec 16, 2018 9:13 am

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?
User avatar
Robert
 
Posts: 994
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: KeyWord

Postby Josef Templ » Sun Dec 16, 2018 3:23 pm

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
User avatar
Josef Templ
 
Posts: 2011
Joined: Tue Sep 17, 2013 6:50 am

PreviousNext

Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests