Am 16.07.2019 um 22:16 schrieb Paul Gilmartin:
On Tue, 16 Jul 2019 21:37:38 +0200, Bernd Oppolzer wrote:

Am 16.07.2019 um 21:22 schrieb Seymour J Metz:
Furthermore: the more modern languages like Pascal, C and Java etc.
forbid the use of reserved symbols as variable names. This may be
restrictive, but makes the compilers much much simpler.
The cardinal sin in language design is to make the compiler simpler at the 
expense of the user. An enhancement to a language with reserved word can render 
a previously valid program invalid. Contrast this with PL/I, where several 
times keywords have been added without affecting existing code.

Yes, I agree somehow to that statement ...

A somewhat complementary sin is to enrich the facilities of the language
to the benefit of the sophisticated user but to the detriment of the naive
user.


I have tried to never do this and have all (even the simplest)
Pascal programs stay valid during my extensions.


I'll add near-ambiguities such as assignment vs. comparison and tricky
semantics of semicolon.  A co-worker once tried removing ";" from the
definition of Pascal and running a meta-parser on the BNF.  The only
further change he needed to make the syntax valid at the same Chomsky
level was to remove the null statement from the language definition.


I don't really understand this, but at the same time I'm not sure
if I need to ...


since I am working on my version of Stanford Pascal,
I sometimes felt the need for adding new keywords. I always had bad feelings
when doing this.

The compiler already had OTHERWISE (but no abbreviation to his, obviously),
EXTERNAL and FORTRAN.

I added BREAK, CONTINUE, RETURN, MODULE, LOCAL and STATIC;
this was in the years from 2011 to 2016. No more need since.

I've done many of these as predefined quasi-identifiers, similar to Pascal's
predefined standard types.  A programmer could choose to declare CONTINUE
as an identifier, overriding its predefined meaning within the block containing
the declaration.


would not work with CONTINUE, because CONTINUE in my compiler
is a real reserved word meant for loop control (same as in C, ITERATE in PL/1),
and it cannot be overridden by a variable or type definition.

If you have a program that uses CONTINUE as identifier for other things,
you need to do a global change, if you want to use my compiler.

Sorry for that ...



I've heard partisans rail that the standard types can be overridden by
local declarations.  If it bothers them, they shouldn't do it.  But I've seen:
     TYPE -32768 .. 32767 INTEGER;
to force 16-bit behavior on machines with other word sizes.  I'm
uncomfortable with that.


INTEGER in Pascal is no reserved word;
the type INTEGER is a predefined standard type (sort of BUILTIN);
the compiler enters these predefined types, variables and procedures in
a very early stage of processing into the compiler's internal lists.
It is possible to override these standard types (at level 0) by own types
with the same name and different semantics, although sort of dangerous,
because every naive reader of the program would assume the original
standard type (if he or she only sees the variable definition and not the
"special" type definition).

The correct syntax, BTW, would be

type integer = -32768 .. 32767;

some real world examples from my compiler:

type LEVRANGE = 0 .. MAXLEVEL ;
     ADDRRANGE = 0 .. MAXADDR ;
     ALNRNG = 1 .. 8 ;
     LABELRNG = 0 .. 1000 ;
     BKT_RNG = 0 .. MAX_BKT ;
     OPRANGE = 0 .. OPMAX ;

the identifiers on the right side of .. are constants defined elsewhere.

The compiler checks (if desired) if variables of these types have values
inside these ranges and throws exceptions, if not (this has some performance
drawbacks, of course, but it makes the programs much more secure).
Same goes for index range checks (bounds checks) etc.

Kind regards

Bernd



-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to