[net.bugs.4bsd] pc doesn't allow an ``others'' clause in outputs

chris@umcp-cs.UUCP (Chris Torek) (11/05/84)

Index: ucb/pc/src 4.2BSD Fix

Description:
	While not strictly a bug, the lack of a specifier for a
	default case label can be quite a pain.  The changes included
	here are straight from Cornell; though their changes were
	for version 2.0, the code has been tested in version 3.0
	and appears to work.

Repeat-By:
	program main (input, output);
	var i : integer;
	begin
		read (i);
		case i of
			1 : writeln ('one');
			2 : writeln ('two');
			others : writeln ('neither one nor two');
		end;
	end.

Fix:
	Apply the appended diff listings.

Chris

RCS file: RCS/hash.c,v
retrieving revision 1.1
diff -c1 -r1.1 hash.c
*** /tmp/,RCSt1004856	Mon Nov  5 01:52:22 1984
--- hash.c	Mon Nov  5 01:18:54 1984
***************
*** 63,64
  	"external",	YEXTERN,
  	0

--- 63,65 -----
  	"external",	YEXTERN,
+ 	"others",	YOTHERS,
  	0
RCS file: RCS/pas.y,v
retrieving revision 1.1
diff -c1 -r1.1 pas.y
*** /tmp/,RCSt1004861	Mon Nov  5 01:52:27 1984
--- pas.y	Mon Nov  5 01:18:37 1984
***************
*** 67,68
  	YCASELAB	YILLCH		YEXTERN		YLAST
  

--- 67,69 -----
  	YCASELAB	YILLCH		YEXTERN		YLAST
+ 	YOTHERS
  
***************
*** 542,543
  		= $$ = tree4(T_CSTAT, lineof($1), NIL, $2);
  		|

--- 543,547 -----
  		= $$ = tree4(T_CSTAT, lineof($1), NIL, $2);
+ 		|
+ 	YOTHERS ':' stat
+ 		= $$ = tree4(T_OTHERCASE, lineof($2), NIL, $3);
  		|
RCS file: RCS/pccaseop.c,v
retrieving revision 1.1
diff -c1 -r1.1 pccaseop.c
*** /tmp/,RCSt1004866	Mon Nov  5 01:52:35 1984
--- pccaseop.c	Mon Nov  5 01:18:46 1984
***************
*** 47,49
       *		[3]	list of cased statements:
!      *			cstat	[0]	T_CSTAT
       *				[1]	lineof ":"

--- 47,49 -----
       *		[3]	list of cased statements:
!      *			cstat	[0]	T_CSTAT  or  T_OTHERCASE
       *				[1]	lineof ":"
***************
*** 68,69
      long	*casep;
      struct ct	*ctab;

--- 68,70 -----
      long	*casep;
+     long	*othercase;
      struct ct	*ctab;
***************
*** 155,156
      count = 0;
      for ( cstatlp = tcase[3] ; cstatlp != NIL ; cstatlp = cstatlp[2] ) {

--- 156,158 -----
      count = 0;
+     othercase = NIL;
      for ( cstatlp = tcase[3] ; cstatlp != NIL ; cstatlp = cstatlp[2] ) {
***************
*** 160,161
  	}
  	line = cstatp[1];

--- 162,171 -----
  	}
+ 	if ( cstatp[0] == T_OTHERCASE ) {
+ 	    if ( othercase != NIL ) {
+ 		error("Too many 'others' cases; only one allowed");
+ 	    } else {
+ 		othercase = cstatp;
+ 	    }
+ 	    continue;
+ 	}
  	line = cstatp[1];
***************
*** 195,197
      }
-     noreach = nr;
  	/*

--- 205,206 -----
      }
  	/*
***************
*** 197,199
  	/*
! 	 *	default action is to call error
  	 */

--- 206,209 -----
  	/*
! 	 *	default action is to call error,
! 	 *	unless there is an ``others:'' label.
  	 */
***************
*** 200,206
      putlab( ctab[0].clabel );
!     putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_CASERNG" );
!     putRV( 0 , cbn , exprnlp -> value[ NL_OFFS ] ,
! 		    exprnlp -> extra_flags , P2INT );
!     putop( P2CALL , P2INT );
!     putdot( filename , line );
  	/*

--- 210,226 -----
      putlab( ctab[0].clabel );
!     if ( othercase == NIL ) {
! 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_CASERNG" );
! 	putRV( 0 , cbn , exprnlp -> value[ NL_OFFS ] ,
! 			exprnlp -> extra_flags , P2INT );
! 	putop( P2CALL , P2INT );
! 	putdot( filename , line );
!     } else {
! 	level++;
! 	statement( othercase[3] );
! 	nr = (nr && noreach);
! 	noreach = 0;
! 	level--;
! 	putjbr( endlabel );
!     }
!     noreach = nr;
  	/*
RCS file: RCS/tree.h,v
retrieving revision 1.1
diff -c1 -r1.1 tree.h
*** /tmp/,RCSt1004871	Mon Nov  5 01:52:40 1984
--- tree.h	Mon Nov  5 01:18:49 1984
***************
*** 84
  #define T_LAST 81

--- 84,85 -----
  #define T_LAST 81
+ #define T_OTHERCASE 82

-- 
(This mind accidently left blank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

guido@mcvax.UUCP (Guido van Rossum) (11/06/84)

In article <721@umcp-cs.UUCP> chris@umcp-cs.UUCP (Chris Torek) writes:
>	While not strictly a bug, the lack of a specifier for a
>	default case label can be quite a pain.  The changes included
>	here are straight from Cornell; though their changes were
>	for version 2.0, the code has been tested in version 3.0
>	and appears to work.

It's a long time since I've flamed, but this one really gets me crazy.

A CHANGE TO THE LANGUAGE presented as a simple bug fix!

I hope this fix is ignored by every system administrator on the net,
if they care at all for the languages they're supporting.

In one newsgroup (net.lang.c) long discussions are going on about
whether to add a statement to jump out of nested loops, and here,
without any prior discussion, is presented the code to change "Pascal".

Don't you dare call it Pascal any longer, my dear!

Hmm, you wouldn't read on anyhow, I guess; I sent the real hot flames
to Chris himself.

--
	Guido van Rossum, "Stamp Out BASIC" Committee, CWI, Amsterdam
	guido@mcvax.UUCP

"Immorality may be something, but it does not take the place of virtue
and three square meals a day."

jaap@haring.UUCP (11/07/84)

In article <721@umcp-cs.UUCP> chris@umcp-cs.UUCP (Chris Torek) writes:
>>	While not strictly a bug, the lack of a specifier for a
>>	default case label can be quite a pain.  The changes included
>>	here are straight from Cornell; though their changes were
>>	for version 2.0, the code has been tested in version 3.0
>>	and appears to work.

Guido writes in <6141@mcvax,UUCP>:
>A CHANGE TO THE LANGUAGE presented as a simple bug fix!

This reminds me of this huge program I once installed. It was written
in pascal and supposed to be very portable.

The way it was written (actually generated from another program)
depended on a default case label. So you got this new pass of pc to
install first...

salkind@cmcl2.UUCP (Lou Salkind) (11/08/84)

You can also (in 4.2bsd) simply use pxp -O instead of hacking up the pc
compiler to accept the others clause.  That is what TeX does.

hans@log-hb.UUCP (Hans Albertsson) (11/09/84)

[]
I WILL add the fix, with the added optional name OTHERWISE for the OTHERS
clause, together with the case ignoring fix of some time ago. It won't be
stored as "pc", though, but under a separate name. Pascal seems a good name,
as does StandardPascal.. It is closer to the ISO standard than pc is.
In my book, the OTHERS addition DOES qualify as a "simple bug fix".
And "pc" is a crock of sheep dip.
-- 
Hans Albertsson, USENET/uucp: {decvax,philabs}!mcvax!enea!log-hb!hans
Real World:  TeleLOGIC AB, Box 1001, S-14901 Nynashamn,SWEDEN

bllklly@uwmacc.UUCP (Bill Kelly) (11/09/84)

In article <6141@mcvax.UUCP> guido@mcvax.UUCP (Guido van Rossum) writes
in reference to adding an "others" clause to Pascal case statements:
>
>I hope this fix is ignored by every system administrator on the net,
>if they care at all for the languages they're supporting.
>
>Don't you dare call it Pascal any longer, my dear!

I hate to disillusion you, but by your definition, the language pc compiles
wasn't Pascal before!  There are at least a dozen major deviations from
Nicklaus & Wirth spelled out in the pc manual, plus a list of non-standard
predefined functions 2 pages long.  Most of the deviations don't change the
syntax of the language as the others clause does, but they sure have the
same effect on portability!  I think the real question is writability.
Most compiler writers found this feature important enough to break the
standard.

Don Knuth commented on this topic.  His TeX program is written in a
language preprocessed into Pascal.  When asked why he didn't have his
preprocessor translate "others" into code obeying Nicklaus & Wirth, he said
"I thought it would be better to have someone fix the compilers."

Does anyone know whether the ANSI and ISO standards include an "others"?
-- 

Bill Kelly    "Working for paper and for iron."
{allegra, ihnp4, seismo}!uwvax!uwmacc!bllklly
1210 West Dayton St/U Wisconsin Madison/Mad WI 53706

jaap@haring.UUCP (11/10/84)

>You can also (in 4.2bsd) simply use pxp -O instead of hacking up the pc
>compiler to accept the others clause.  That is what TeX does.

Yes, I know 4.2 BSD pascal has the -O option (I don't know why they didn't
call it -others, but it would be a better choice -:)), but that is not
the point.

Whenever I'm trying to boot a program which is supposed to be "Very
portable" among a lot of systems, so it even limits the line lengths
of the input to the compiler to the old fashioned card reader, I don't
want to now about an obscure option in a certain compiler on an obscure system.
The language used just happens to be "standard pascal", which doesn't has
the construct used.

Allowing the "default case" in pascal is not a bug fix, but a
change in the language specs to get some job to be done.


jaap akkerhuis	Centrum voor Wiskunde en Informatica	mcvax!jaap

      	 	Never take a standard for granted