home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / SOURCE / SEARCHKW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-06  |  3.6 KB  |  101 lines

  1. /*
  2.  * 68K/386 32-bit C compiler.
  3.  *
  4.  * copyright (c) 1996, David Lindauer
  5.  * 
  6.  * This compiler is intended for educational use.  It may not be used
  7.  * for profit without the express written consent of the author.
  8.  *
  9.  * It may be freely redistributed, as long as this notice remains intact
  10.  * and sources are distributed along with any executables derived from them.
  11.  *
  12.  * The author is not responsible for damages, either direct or consequential,
  13.  * that may arise from use of this software.
  14.  *
  15.  * v1.5 August 1996
  16.  * David Lindauer, gclind01@starbase.spd.louisville.edu
  17.  *
  18.  * Credits to Mathew Brandt for original K&R C compiler
  19.  *
  20.  */
  21. #include        <stdio.h>
  22. #include                <malloc.h>
  23. #include        "expr.h"
  24. #include        "c.h"
  25. #include        "gen.h"
  26. #include        "cglbdec.h"
  27.  
  28. #define KWHASHSIZE 253
  29.  
  30. extern int prm_cplusplus,prm_cmangle;
  31.  
  32. static HASHREC **hashtable=0;
  33.     
  34. struct kwblk {
  35.                 struct kwblk *next;
  36.         char            *word;
  37.         short              stype;
  38.                 char        iscplusplus;
  39.         }       keywords[] = {
  40.  
  41.         {0,"int", kw_int}, {0,"char", kw_char}, {0,"long", kw_long},
  42.         {0,"float", kw_float}, {0,"double", kw_double}, {0,"return", kw_return},
  43.         {0,"struct", kw_struct}, {0,"union", kw_union}, {0,"typedef", kw_typedef},
  44.         {0,"enum", kw_enum}, {0,"static", kw_static}, {0,"auto", kw_auto},
  45.         {0,"sizeof", kw_sizeof}, {0,"do", kw_do}, {0,"if", kw_if},
  46.         {0,"else", kw_else}, {0,"for", kw_for},{0,"switch", kw_switch},
  47.         {0,"while", kw_while},{0,"short", kw_short}, {0,"extern", kw_extern},
  48.         {0,"case", kw_case}, {0,"goto", kw_goto}, {0,"default", kw_default},
  49.         {0,"register", kw_register}, {0,"unsigned", kw_unsigned},
  50.         {0,"break", kw_break}, {0,"continue", kw_continue}, {0,"void", kw_void},
  51.                 {0,"volatile", kw_volatile}, {0,"const", kw_const},
  52.                 {0,"public",kw_public,1}, {0,"private",kw_private,1},
  53.                 {0,"protected",kw_protected,1}, { 0, "class", kw_class,1 },
  54.                 {0,"friend",kw_friend,1}, {0,"this",kw_this,1}, {0,"operator",kw_operator,1},
  55.                 {0,"new",kw_new,1}, {0,"delete",kw_delete,1},{0,"inline",kw_inline,1},
  56.                 {0,"try",kw_try,1}, {0,"catch",kw_catch,1}, {0,"template",kw_template,1},
  57.                 {0,"throw",kw_throw,1},
  58. #ifdef i386
  59.                 {0,"_interrupt", kw__interrupt},{0,"_genbyte", kw__genword },
  60.                 {0,"_EAX", kw__EAX}, {0,"_ECX", kw__ECX},{0,"_EDX", kw__EDX},
  61.                 {0,"_EBX", kw__EBX},{0,"_ESP", kw__ESP},{0,"_EBP", kw__EBP},
  62.                 {0,"_ESI", kw__ESI},{0,"_EDI", kw__EDI},
  63. #else
  64.                 {0,"_trap", kw__trap,}, {0,"_interrupt", kw__interrupt},
  65.                 {0,"_abs", kw__abs }, {0,"_genword", kw__genword },
  66.                 {0,"_D0",kw__D0},{0,"_D1",kw__D1},{0,"_D2",kw__D2},{0,"_D3",kw__D3},
  67.                 {0,"_D4",kw__D4},{0,"_D5",kw__D5},{0,"_D6",kw__D6},{0,"_D7",kw__D7},
  68.                 {0,"_A0",kw__A0},{0,"_A1",kw__A1},{0,"_A2",kw__A2},{0,"_A3",kw__A3},
  69.                 {0,"_A4",kw__A4},{0,"_A5",kw__A5},{0,"_A6",kw__A6},{0,"_A7",kw__A7},
  70.                 {0,"_FP0",kw__FP0},{0,"_FP1",kw__FP1},{0,"_FP2",kw__FP2},{0,"_FP3",kw__FP3},
  71.                 {0,"_FP4",kw__FP4},{0,"_FP5",kw__FP5},{0,"_FP6",kw__FP6},{0,"_FP7",kw__FP7},
  72. #endif
  73.         {0, 0, 0} };
  74.  
  75. void kwini(void) 
  76. {
  77.     struct kwblk *q = keywords;
  78.     if (!hashtable) {
  79.       hashtable = (HASHREC *)malloc(KWHASHSIZE * sizeof(HASHREC *));
  80.       memset(hashtable,0,KWHASHSIZE * sizeof(HASHREC *));
  81.         while (q->word) {
  82.             AddHash(q,hashtable,KWHASHSIZE);
  83.             q++;
  84.         }
  85.     }
  86. }
  87. int searchkw(void)
  88. {
  89.     char *id = lastid;
  90.     struct kwblk    **kwbp;
  91.     if (prm_cmangle)
  92.         id++;
  93.     kwbp = LookupHash(id,hashtable,KWHASHSIZE);
  94.     
  95.     if (kwbp) {
  96.         if (!prm_cplusplus && (*kwbp)->iscplusplus)
  97.             return 0;
  98.         return lastst = (*kwbp)->stype;
  99.     }
  100.   return(0);
  101. }