/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)keywords.c 1.3 %G%";
private String reserved
[] ={
"alias", "and", "assign", "at", "call", "catch", "cont",
"debug", "delete", "div", "dump", "edit", "file", "func",
"gripe", "help", "if", "ignore", "in",
"list", "mod", "next", "nexti", "nil", "not", "or",
"print", "psym", "quit", "run",
"sh", "skip", "source", "status", "step", "stepi",
"stop", "stopi", "trace", "tracei",
"use", "whatis", "when", "where", "whereis", "which",
"INT", "REAL", "NAME", "STRING",
"LFORMER", "RFORMER", "#^", "->"
* The keyword table is a traditional hash table with collisions
#define HASHTABLESIZE 503
typedef unsigned int Hashvalue
;
private Keyword hashtab
[HASHTABLESIZE
];
#define hash(n) ((((unsigned) n) >> 2) mod HASHTABLESIZE)
* Enter all the reserved words into the keyword table.
for (i
= ALIAS
; i
<= WHICH
; i
++) {
keyword(reserved
[ord(i
) - ord(ALIAS
)], i
, false);
keyword("set", ASSIGN
, false);
* Deallocate the keyword table.
register Keyword k
, nextk
;
for (i
= 0; i
< HASHTABLESIZE
; i
++) {
* Enter a keyword into the name table. It is assumed to not be there already.
* The string is assumed to be statically allocated.
private keyword(s
, t
, isalias
)
* Return the string associated with a token corresponding to a keyword.
public String
keywdstring(t
)
return reserved
[ord(t
) - ord(ALIAS
)];
* Find a keyword in the keyword table.
* We assume that tokens cannot legitimately be nil (0).
public Token
findkeyword(n
)
while (k
!= nil
and k
->name
!= n
) {
public enter_alias(newcmd
, oldcmd
)
error("\"%s\" is not a command", ident(oldcmd
));
keyword(ident(newcmd
), t
, true);
for (i
= 0; i
< HASHTABLESIZE
; i
++) {
for (k
= hashtab
[i
]; k
!= nil
; k
= k
->chain
) {
printf("%s\t%s\n", ident(k
->name
), keywdstring(k
->toknum
));
printf("%s\n", keywdstring(t
));