home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / mawk11as.zip / KW.C < prev    next >
C/C++ Source or Header  |  1991-12-18  |  2KB  |  81 lines

  1.  
  2. /********************************************
  3. kw.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13.  
  14. /* $Log:    kw.c,v $
  15.  * Revision 5.1  91/12/05  07:56:12  brennan
  16.  * 1.1 pre-release
  17.  * 
  18. */
  19.  
  20.  
  21. /* kw.c */
  22.  
  23.  
  24. #include "mawk.h"
  25. #include "symtype.h"
  26. #include "parse.h"
  27. #include "init.h"
  28.  
  29.  
  30. static struct kw {
  31. char *text ;
  32. short kw ;
  33. }  keywords[] = {
  34.  
  35. "print", PRINT,
  36. "printf", PRINTF,
  37. "do" , DO ,
  38. "while" , WHILE ,
  39. "for" , FOR ,
  40. "break" , BREAK ,
  41. "continue" , CONTINUE ,
  42. "if" , IF ,
  43. "else", ELSE ,
  44. "in" , IN ,
  45. "delete", DELETE ,
  46. "split" , SPLIT ,
  47. "match" , MATCH_FUNC ,
  48. "BEGIN" , BEGIN,
  49. "END" ,   END ,
  50. "exit" , EXIT ,
  51. "next" , NEXT ,
  52. "return", RETURN,
  53. "getline", GETLINE,
  54. "sub" , SUB,
  55. "gsub", GSUB,
  56. "function", FUNCTION,
  57. (char *) 0 , 0 } ;
  58.  
  59. /* put keywords in the symbol table */
  60. void kw_init()
  61. { register struct kw *p = keywords ;
  62.   register SYMTAB *q ;
  63.  
  64.   while ( p->text )
  65.   { q = insert( p->text ) ;
  66.     q->type = ST_KEYWORD ;
  67.     q->stval.kw = p++ -> kw ;
  68.   }
  69. }
  70.  
  71. /* find a keyword to emit an error message */
  72. char *find_kw_str( kw_token )
  73.   int kw_token ;
  74. { struct kw *p ;
  75.  
  76.   for( p = keywords ; p->text ; p++ )
  77.         if ( p->kw == kw_token )  return p->text ;
  78.   /* search failed */
  79.   return (char *) 0 ;
  80. }
  81.