🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4564

Re: Modula 2 keywords

#4564
From: Doug Schmidt
Date: Fri, 13 Jan 1989 01:24
128 lines
3351 bytes
Oops, there was a typo in the previous listing, the "DO" was printed
as "DO "!  Thanks to Thomas Kaule for pointing this out.

Here's the ``correct'' (hopefully) version:

Doug

----------------------------------------
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 14
#define MIN_HASH_VALUE 2
#define MAX_HASH_VALUE 79
/*
40 keywords
78 is the maximum key range
*/

static int hash (str, len)
register char	*str;
register int	len;
{
	static int cval[] = {
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  35,  25,  40,  10,   0,
		  20,  79,  20,  20,  79,  79,   0,  15,   0,   0,
		  10,  15,   0,  10,   5,   0,   0,  20,  15,   0,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,  79,  79,
		  79,  79,  79,  79,  79,  79,  79,  79,
	};
	register int hval;

	switch (hval = len) {
		default:
		case 2:
			hval += cval[str[1]];
		case 1:
			hval += cval[str[0]];
			hval += cval[str[len - 1]];
		case 0:
			return (hval);
	}
}

int in_word_set (str, len)
register char *str;
register int len;
{
	static char * wordlist[] = {
		 "", "",
		 "OR", 
		 "",
		 "ELSE", 
		 "UNTIL", 
		 "RETURN", 
		 "TO", 
		 "NOT", 
		 "TYPE", 
		 "",
		 "REPEAT", 
		 "DO", 
		 "END", 
		 "LOOP", 
		 "",
		 "RECORD", 
		 "POINTER", 
		 "SET", 
		 "PROCEDURE", 
		 "DEFINITION", 
		 "MODULE", 
		 "IN", 
		 "FOR", 
		 "EXIT", 
		 "ELSIF", 
		 "EXPORT", 
		 "BY", 
		 "MOD", 
		 "THEN", 
		 "BEGIN", 
		 "", "",
		 "DIV", 
		 "QUALIFIED", 
		 "", "", "",
		 "VAR", 
		 "FROM", 
		 "ARRAY", 
		 "",
		 "OF", 
		 "", "",
		 "WHILE", 
		 "IMPORT", 
		 "",
		 "AND", 
		 "IMPLEMENTATION", 
		 "CONST", 
		 "", "", "", "", "", "", "", "", "",
		 "", "",
		 "IF", 
		 "",
		 "WITH", 
		 "", "", "", "", "", "", "", "", "",
		 "", "", "", "", "",
		 "CASE", 
	};

	if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
		register int key = hash (str, len);

		if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) {
			register char *s = wordlist[key];

			return (*s == *str && ! strcmp (str + 1, s + 1));
		}
	}
	return (0);
}
--
schmidt@ics.uci.edu (ARPA) |   Per me si va nella citta' dolente.
office: (714) 856-4043     |   Per me si va nell'eterno dolore.
                           |   Per me si va tra la perduta gente.
                           |   Lasciate ogni speranza o voi ch'entrate.
Technical Details
Message-ID: <3995@paris.ics.uci.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!nosc!ucsd!orion.cf.uci.edu!uci-ics!siam.ics.uci.edu!schmidt
References: <3486@paris.ics.uci.edu> <3741@paris.ics.uci.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!nosc!ucsd!orion.cf.uci.edu!uci-ics!siam.ics.uci.edu!schmidt
From: schmidt@siam.ics.uci.edu (Doug Schmidt)
Newsgroups: comp.lang.modula2
Subject: Re: Modula 2 keywords
Keywords: keywords
Message-ID: <3995@paris.ics.uci.edu>
Date: 13 Jan 89 01:24:36 GMT
References: <3486@paris.ics.uci.edu> <3741@paris.ics.uci.edu>
Sender: news@paris.ics.uci.edu
Reply-To: Doug Schmidt <schmidt@siam.ics.uci.edu>
Organization: University of California, Irvine - Dept of ICS
Lines: 128