ham@polya.Stanford.EDU (Peter R. Ham) (01/17/89)
I'm trying to add the new keyword "shared" as a storage class specifier for the front end. In c-parse.y there's a table of keywords. The comment says that I keyword cannot be added by hand, instead the program "perfect-hash" must be used? Where is this program? Does anyone understand this comment? The function "grokdeclarator" in c-decl.c is also really confusing to me. Peter -- Peter Ham PO Box 3430 (415) 321-5746 MS Computer Science Student Stanford, CA ham@polya.stanford.edu Stanford University 94309
schmidt@glacier.ics.uci.edu (Doug Schmidt) (01/17/89)
In article <HAM.89Jan16190223@polya.Stanford.EDU> ham@polya.Stanford.EDU (Peter R. Ham) writes: > >I'm trying to add the new keyword "shared" as a storage class specifier >for the front end. > >In c-parse.y there's a table of keywords. The comment says that I keyword >cannot be added by hand, instead the program "perfect-hash" must be used? > >Where is this program? Does anyone understand this comment? That program is available via ftp from ics.uci.edu (128.195.0.1) in ~ftp/pub/gperf.tar.1.3.Z, and a beta version of it is in the libg++ 1.32 distribution. However, here is a quick table for you: you'll have to decide what attributes to give to ``shared,'' I just made a quick guess. Let me know if there are any problems with this. Doug ---------------------------------------- /* C code produced by gperf version 1.4 */ /* Command-line: gp -k1,2,$ -o -t gnuc.input */ struct resword { char *name; short token; enum rid rid; }; #define MIN_WORD_LENGTH 2 #define MAX_WORD_LENGTH 9 #define MIN_HASH_VALUE 4 #define MAX_HASH_VALUE 59 /* 37 keywords 56 is the maximum key range */ inline static int hash (str, len) register char *str; register int len; { static int cval[] = { 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 15, 59, 0, 0, 35, 5, 0, 10, 10, 5, 20, 59, 0, 15, 30, 0, 0, 59, 59, 15, 0, 0, 0, 0, 45, 40, 35, 59, 59, 59, 59, 59, 59, }; return (len + cval[str[1]] + cval[str[0]] + cval[str[len - 1]]); } inline static int is_reserved_word (str, len) register char *str; register int len; { static struct resword wordlist[] = { { "",},{ "",},{ "",},{ "",}, { "auto", SCSPEC, RID_AUTO }, { "union", UNION, NORID }, { "struct", STRUCT, NORID }, { "do", DO, NORID }, { "volatile", TYPE_QUAL, RID_VOLATILE }, { "void", TYPESPEC, RID_VOID }, { "short", TYPESPEC, RID_SHORT }, { "double", TYPESPEC, RID_DOUBLE }, { "default", DEFAULT, NORID }, { "unsigned", TYPESPEC, RID_UNSIGNED }, { "goto", GOTO, NORID }, { "",}, { "shared", SCSPEC, RID_SHARED }, { "",},{ "",}, { "else", ELSE, NORID }, { "break", BREAK, NORID }, { "return", RETURN, NORID }, { "",}, { "int", TYPESPEC, RID_INT }, { "",},{ "",}, { "inline", SCSPEC, RID_INLINE }, { "",}, { "for", FOR, NORID }, { "long", TYPESPEC, RID_LONG }, { "float", TYPESPEC, RID_FLOAT }, { "signed", TYPESPEC, RID_SIGNED }, { "",}, { "asm", ASM, NORID }, { "enum", ENUM, NORID }, { "",}, { "sizeof", SIZEOF, NORID }, { "",}, { "register", SCSPEC, RID_REGISTER }, { "case", CASE, NORID }, { "const", TYPE_QUAL, RID_CONST }, { "static", SCSPEC, RID_STATIC }, { "if", IF, NORID }, { "continue", CONTINUE, NORID }, { "",},{ "",}, { "extern", SCSPEC, RID_EXTERN }, { "",},{ "",}, { "__alignof", ALIGNOF, NORID }, { "",}, { "typeof", TYPEOF, NORID }, { "typedef", SCSPEC, RID_TYPEDEF }, { "",},{ "",}, { "while", WHILE, NORID }, { "switch", SWITCH, NORID }, { "",},{ "",}, { "char", TYPESPEC, RID_CHAR }, }; 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].name; 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.