home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fchek284.zip / keywords.h < prev    next >
C/C++ Source or Header  |  1994-07-10  |  5KB  |  135 lines

  1. /* keywords.h:
  2.     Contains names and characteristics of keywords for use by
  3.     get_identifier and is_keyword in disambiguating
  4.     keywords from identifiers.
  5.  
  6.     Included by forlex.c.
  7.  
  8. Must define SPLIT_KEYWORDS if using the old forlex with keyword hashing etc.
  9.  
  10. */
  11.  
  12. #define IK 0x01    /* Allowed only in initial keyword of a statement (can be
  13.            preceded only by non-EK keywords) */
  14. #define NP 0x02    /* Never followed by ( or =  */
  15. #define MP 0x04    /* Must be followed by ( */
  16. #define NI 0x08    /* Disallowed in logical IF */
  17. #define EK 0x10    /* Cannot be followed by IK keyword: turns off initial_flag */
  18. #define TY 0x20    /* Data type name */
  19. #define NA 0x40    /* Never followed by alphabetic */
  20.  
  21.  
  22.                 /* Bisection search done at each
  23.                    length step requires fixed-length
  24.                    strings for keyword names.  Macro
  25.                    below identifies which keyword is
  26.                    the longest.
  27.                  */
  28. #define LONGEST_KEYWORD "DOUBLEPRECISION"
  29.  
  30.                 /* Number of keywords in table */
  31. #define NUM_KEYWORDS (sizeof(keywords)/sizeof(keywords[0]))
  32.  
  33.     /* Macro to determine whether a token class C is that of a data
  34.        type (for purposes of is_keyword) */
  35. #ifndef OLDDEF
  36. #define is_a_type_token(C) (((C)>=keytab_offset&&\
  37.             (C)-keytab_offset<keytab_size)?\
  38.           (keywords[keytab_index[(C)-keytab_offset]].context&TY):FALSE)
  39. #else
  40.                 /* This is a simpler defn that will work
  41.                    for is_keyword's needs. */
  42. #define is_a_type_token(C) ((C)>=tok_BYTE && ((C)<=tok_REAL))
  43. #endif
  44.  
  45.         /* Keyword list must be maintained in alphabetical
  46.            order.  New keywords can be added so long as their
  47.            context info is specified.  No other source code
  48.            changes are necessary, but of course new keywords
  49.            won't be recognized by the parser till you add
  50.            productions to fortran.y.  Also, if IK flag is not
  51.            set, is_keyword will have to look at it specially.
  52.          */
  53. PRIVATE struct {
  54.     char name[sizeof(LONGEST_KEYWORD)];
  55.     short class,        /* token class */
  56.           context;        /* local-context flags */
  57. } keywords[]={
  58. {"ACCEPT",    tok_ACCEPT,    IK | EK},
  59. {"ASSIGN",    tok_ASSIGN,    IK | NP | EK | NA},
  60. {"BACKSPACE",    tok_BACKSPACE,    IK | EK},
  61. #ifdef SPLIT_KEYWORDS
  62. {"BLOCK",    tok_BLOCK,    IK | NP | NI},
  63. #endif
  64. {"BLOCKDATA",    tok_BLOCKDATA,    IK | EK | NP | NI},
  65. {"BYTE",    tok_BYTE,    IK | NI | EK | TY},
  66. {"CALL",    tok_CALL,    IK | NP | EK},
  67. {"CHARACTER",    tok_CHARACTER,    IK | NI | EK | TY},
  68. {"CLOSE",    tok_CLOSE,    IK | EK | MP | NA},
  69. {"COMMON",    tok_COMMON,    IK | NP | NI | EK},
  70. {"COMPLEX",    tok_COMPLEX,    IK | NI | EK | TY},
  71. {"CONTINUE",    tok_CONTINUE,    IK | NP | EK | NA},
  72. {"DATA",    tok_DATA,    IK | NI | EK},
  73. {"DIMENSION",    tok_DIMENSION,    IK | NP | NI | EK},
  74. {"DO",        tok_DO,        IK | NP | NI},
  75. #ifdef SPLIT_KEYWORDS
  76. {"DOUBLE",    tok_DOUBLE,    IK | NP | NI},
  77. #endif
  78. {"DOUBLECOMPLEX",tok_DOUBLECOMPLEX,    IK | NI | EK | TY},
  79. {"DOUBLEPRECISION",tok_DOUBLEPRECISION,    IK | NI | EK | TY},
  80. {"DOWHILE",    tok_DOWHILE,    IK | NI | EK},
  81. {"ELSE",    tok_ELSE,    IK | NP | NI | NA}, /* simple ELSE only */
  82. {"ELSEIF",    tok_ELSEIF,    IK | NI | EK | NA},
  83. {"END",        tok_END,    IK | NP | NI | NA}, /* simple END only */
  84. {"ENDDO",    tok_ENDDO,    IK | NP | NI | EK | NA},
  85. {"ENDFILE",    tok_ENDFILE,    IK | EK},
  86. {"ENDIF",    tok_ENDIF,    IK | NP | NI | EK | NA},
  87. {"ENTRY",    tok_ENTRY,    IK | NP | NI | EK},
  88. {"EQUIVALENCE",    tok_EQUIVALENCE,IK | NI | EK | MP | NA},
  89. {"EXTERNAL",    tok_EXTERNAL,    IK | NP | NI | EK},
  90. {"FILE",    tok_FILE,    IK | EK},
  91. {"FORMAT",    tok_FORMAT,    IK | NI | EK | MP | NA},
  92. {"FUNCTION",    tok_FUNCTION,    NP | NI | EK},
  93. #ifdef SPLIT_KEYWORDS
  94. {"GO",        tok_GO,        IK | NP},
  95. #endif
  96. {"GOTO",    tok_GOTO,    IK | EK},
  97. {"IF",        tok_IF,        IK | NI | EK | NA},
  98. {"IMPLICIT",    tok_IMPLICIT,    IK | NP | NI},
  99. {"INCLUDE",    tok_INCLUDE,    IK | NP | NI | EK | NA},
  100. {"INQUIRE",    tok_INQUIRE,    IK | EK | MP | NA},
  101. {"INTEGER",    tok_INTEGER,    IK | NI | EK | TY},
  102. {"INTRINSIC",    tok_INTRINSIC,    IK | NP | NI | EK},
  103. {"LOGICAL",    tok_LOGICAL,    IK | NI | EK | TY},
  104. {"NAMELIST",    tok_NAMELIST,    IK | NP | NI | EK},
  105. {"NONE",    tok_NONE,    IK | NI | EK | TY | NA},
  106. {"OPEN",    tok_OPEN,    IK | EK | MP | NA},
  107. {"PARAMETER",    tok_PARAMETER,    IK | NI | EK | MP | NA},
  108. {"PAUSE",    tok_PAUSE,    IK | NP | EK},
  109. {"PRECISION",    tok_PRECISION,    IK | NI | EK | TY},
  110. {"PRINT",    tok_PRINT,    IK | EK},
  111. {"PROGRAM",    tok_PROGRAM,    IK | NP | NI | EK},
  112. {"READ",    tok_READ,    IK | EK},
  113. {"REAL",    tok_REAL,    IK | NI | EK | TY},
  114. {"RETURN",    tok_RETURN,    IK | EK},
  115. {"REWIND",    tok_REWIND,    IK | EK},
  116. {"SAVE",    tok_SAVE,    IK | NP | NI | EK},
  117. {"STOP",    tok_STOP,    IK | NP | EK},
  118. {"SUBROUTINE",    tok_SUBROUTINE,    IK | NP | NI | EK},
  119. {"THEN",    tok_THEN,    IK | NP | EK | NA},
  120. {"TO",        tok_TO,        NI | EK},
  121. {"TYPE",    tok_TYPE,    IK | EK},
  122. {"WHILE",    tok_WHILE,    NI | EK | MP | NA},
  123. {"WRITE",    tok_WRITE,    IK | EK | MP | NA},
  124. };
  125.  
  126.  
  127.         /* Lookup table to allow index in keywords table of
  128.            a given keyword to be found by its token number.
  129.            Initialized by init_keyhashtab. */
  130. PRIVATE short
  131.   keytab_offset,    /* lowest keyword token number */
  132.   *keytab_index;    /* array of keyword indices  */
  133. PRIVATE unsigned
  134.   keytab_size;        /* Number of elements in keytab_index */
  135.