home *** CD-ROM | disk | FTP | other *** search
- /*
- * 68K/386 32-bit C compiler.
- *
- * copyright (c) 1996, David Lindauer
- *
- * This compiler is intended for educational use. It may not be used
- * for profit without the express written consent of the author.
- *
- * It may be freely redistributed, as long as this notice remains intact
- * and sources are distributed along with any executables derived from them.
- *
- * The author is not responsible for damages, either direct or consequential,
- * that may arise from use of this software.
- *
- * v1.5 August 1996
- * David Lindauer, gclind01@starbase.spd.louisville.edu
- *
- * Credits to Mathew Brandt for original K&R C compiler
- *
- */
- #include <stdio.h>
- #include <malloc.h>
- #include "expr.h"
- #include "c.h"
- #include "gen.h"
- #include "cglbdec.h"
-
- #define KWHASHSIZE 253
-
- extern int prm_cplusplus,prm_cmangle;
-
- static HASHREC **hashtable=0;
-
- struct kwblk {
- struct kwblk *next;
- char *word;
- short stype;
- char iscplusplus;
- } keywords[] = {
-
- {0,"int", kw_int}, {0,"char", kw_char}, {0,"long", kw_long},
- {0,"float", kw_float}, {0,"double", kw_double}, {0,"return", kw_return},
- {0,"struct", kw_struct}, {0,"union", kw_union}, {0,"typedef", kw_typedef},
- {0,"enum", kw_enum}, {0,"static", kw_static}, {0,"auto", kw_auto},
- {0,"sizeof", kw_sizeof}, {0,"do", kw_do}, {0,"if", kw_if},
- {0,"else", kw_else}, {0,"for", kw_for},{0,"switch", kw_switch},
- {0,"while", kw_while},{0,"short", kw_short}, {0,"extern", kw_extern},
- {0,"case", kw_case}, {0,"goto", kw_goto}, {0,"default", kw_default},
- {0,"register", kw_register}, {0,"unsigned", kw_unsigned},
- {0,"break", kw_break}, {0,"continue", kw_continue}, {0,"void", kw_void},
- {0,"volatile", kw_volatile}, {0,"const", kw_const},
- {0,"public",kw_public,1}, {0,"private",kw_private,1},
- {0,"protected",kw_protected,1}, { 0, "class", kw_class,1 },
- {0,"friend",kw_friend,1}, {0,"this",kw_this,1}, {0,"operator",kw_operator,1},
- {0,"new",kw_new,1}, {0,"delete",kw_delete,1},{0,"inline",kw_inline,1},
- {0,"try",kw_try,1}, {0,"catch",kw_catch,1}, {0,"template",kw_template,1},
- {0,"throw",kw_throw,1},
- #ifdef i386
- {0,"_interrupt", kw__interrupt},{0,"_genbyte", kw__genword },
- {0,"_EAX", kw__EAX}, {0,"_ECX", kw__ECX},{0,"_EDX", kw__EDX},
- {0,"_EBX", kw__EBX},{0,"_ESP", kw__ESP},{0,"_EBP", kw__EBP},
- {0,"_ESI", kw__ESI},{0,"_EDI", kw__EDI},
- #else
- {0,"_trap", kw__trap,}, {0,"_interrupt", kw__interrupt},
- {0,"_abs", kw__abs }, {0,"_genword", kw__genword },
- {0,"_D0",kw__D0},{0,"_D1",kw__D1},{0,"_D2",kw__D2},{0,"_D3",kw__D3},
- {0,"_D4",kw__D4},{0,"_D5",kw__D5},{0,"_D6",kw__D6},{0,"_D7",kw__D7},
- {0,"_A0",kw__A0},{0,"_A1",kw__A1},{0,"_A2",kw__A2},{0,"_A3",kw__A3},
- {0,"_A4",kw__A4},{0,"_A5",kw__A5},{0,"_A6",kw__A6},{0,"_A7",kw__A7},
- {0,"_FP0",kw__FP0},{0,"_FP1",kw__FP1},{0,"_FP2",kw__FP2},{0,"_FP3",kw__FP3},
- {0,"_FP4",kw__FP4},{0,"_FP5",kw__FP5},{0,"_FP6",kw__FP6},{0,"_FP7",kw__FP7},
- #endif
- {0, 0, 0} };
-
- void kwini(void)
- {
- struct kwblk *q = keywords;
- if (!hashtable) {
- hashtable = (HASHREC *)malloc(KWHASHSIZE * sizeof(HASHREC *));
- memset(hashtable,0,KWHASHSIZE * sizeof(HASHREC *));
- while (q->word) {
- AddHash(q,hashtable,KWHASHSIZE);
- q++;
- }
- }
- }
- int searchkw(void)
- {
- char *id = lastid;
- struct kwblk **kwbp;
- if (prm_cmangle)
- id++;
- kwbp = LookupHash(id,hashtable,KWHASHSIZE);
-
- if (kwbp) {
- if (!prm_cplusplus && (*kwbp)->iscplusplus)
- return 0;
- return lastst = (*kwbp)->stype;
- }
- return(0);
- }