/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)keywords.c 1.4 (Berkeley) %G%";
private String reserved
[] ={
"alias", "and", "assign", "at", "call", "catch", "cont",
"debug", "delete", "div", "down", "dump", "edit", "file", "func",
"gripe", "help", "if", "ignore", "in",
"list", "mod", "next", "nexti", "nil", "not", "or",
"print", "psym", "quit", "rerun", "return", "run",
"sh", "skip", "source", "status", "step", "stepi",
"stop", "stopi", "trace", "tracei", "up",
"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);
keyword("c", CONT
, true);
keyword("d", DELETE
, true);
keyword("h", HELP
, true);
keyword("e", EDIT
, true);
keyword("l", LIST
, true);
keyword("n", NEXT
, true);
keyword("p", PRINT
, true);
keyword("q", QUIT
, true);
keyword("s", STEP
, true);
keyword("st", STOP
, true);
keyword("j", STATUS
, true);
keyword("t", WHERE
, true);
* 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 the keyword associated with the given string.
private Keyword
kwlookup (n
)
while (k
!= nil
and k
->name
!= n
) {
* Return the token associated with a given keyword string.
* We assume that tokens cannot legitimately be nil (0).
public Token
findkeyword(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
));