tokenname.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* TOKEN NAME DEFINITIONS */
  7. #include "idf.h"
  8. #include "arith.h"
  9. #include "LLlex.h"
  10. #include "tokenname.h"
  11. #include "Lpars.h"
  12. /* To centralize the declaration of %tokens, their presence in this
  13. file is taken as their declaration. The Makefile will produce
  14. a grammar file (tokenfile.g) from this file.
  15. Moreover, rather than looking up a symbol in all these lists
  16. to find its printable name, a fast version of symbol2str() is
  17. generated from these tables.
  18. Consequenty some of these tables are not referenced explicitly
  19. in the C text any more. To save space and to avoid lint confusion,
  20. these have been made pseudo-invisible by #ifdefs.
  21. */
  22. #ifdef ____
  23. struct tokenname tkspec[] = { /* the names of the special tokens */
  24. {IDENTIFIER, "identifier"},
  25. {TYPE_IDENTIFIER, "type_identifier"},
  26. {STRING, "string"},
  27. {FILESPECIFIER, "filespecifier"},
  28. {INTEGER, "integer"},
  29. {FLOATING, "floating"},
  30. {0, ""}
  31. };
  32. #endif /* ____ */
  33. #ifdef ____
  34. struct tokenname tkcomp[] = { /* names of the composite tokens */
  35. {NOTEQUAL, "!="},
  36. {AND, "&&"},
  37. {PLUSPLUS, "++"},
  38. {MINMIN, "--"},
  39. {ARROW, "->"},
  40. {LEFT, "<<"},
  41. {LESSEQ, "<="},
  42. {EQUAL, "=="},
  43. {GREATEREQ, ">="},
  44. {RIGHT, ">>"},
  45. {OR, "||"},
  46. {0, ""}
  47. };
  48. #endif /* ____ */
  49. struct tokenname tkidf[] = { /* names of the identifier tokens */
  50. {ASM, "asm"},
  51. {AUTO, "auto"},
  52. {BREAK, "break"},
  53. {CASE, "case"},
  54. {CONTINUE, "continue"},
  55. {DEFAULT, "default"},
  56. {DO, "do"},
  57. {ELSE, "else"},
  58. {ENUM, "enum"},
  59. {EXTERN, "extern"},
  60. {FOR, "for"},
  61. {GOTO, "goto"},
  62. {IF, "if"},
  63. {LONG, "long"},
  64. {REGISTER, "register"},
  65. {RETURN, "return"},
  66. {SHORT, "short"},
  67. {SIZEOF, "sizeof"},
  68. {STATIC, "static"},
  69. {STRUCT, "struct"},
  70. {SWITCH, "switch"},
  71. {TYPEDEF, "typedef"},
  72. {UNION, "union"},
  73. {UNSIGNED, "unsigned"},
  74. {WHILE, "while"},
  75. {0, ""}
  76. };
  77. struct tokenname tkother[] = { /* additional keywords from the RM */
  78. {ENTRY, "entry"},
  79. {FORTRAN, "fortran"},
  80. {0, ""}
  81. };
  82. #ifdef ____
  83. struct tokenname tkfunny[] = { /* internal keywords */
  84. {CHAR, "char"},
  85. {INT, "int"},
  86. {FLOAT, "float"},
  87. {DOUBLE, "double"},
  88. {VOID, "void"},
  89. {ARRAY, "array"},
  90. {FUNCTION, "function"},
  91. {POINTER, "pointer"},
  92. {FIELD, "field"},
  93. {NEWLINE, "newline"},
  94. {GLOBAL, "global"},
  95. {IMPLICIT, "implicit"},
  96. {FORMAL, "formal"},
  97. {LABEL, "label"},
  98. {ERRONEOUS, "erroneous"},
  99. {PARCOMMA, "parcomma"},
  100. {INITCOMMA, "initcomma"},
  101. {CAST, "cast"},
  102. {POSTINCR, "postfix ++"},
  103. {POSTDECR, "postfix --"},
  104. {PLUSAB, "+="},
  105. {MINAB, "-="},
  106. {TIMESAB, "*="},
  107. {DIVAB, "/="},
  108. {MODAB, "%="},
  109. {LEFTAB, "<<="},
  110. {RIGHTAB, ">>="},
  111. {ANDAB, "&="},
  112. {XORAB, "^="},
  113. {ORAB, "|="},
  114. {INT2INT, "int2int"},
  115. {INT2FLOAT, "int2float"},
  116. {FLOAT2INT, "float2int"},
  117. {FLOAT2FLOAT, "float2float"},
  118. {0, ""}
  119. };
  120. #endif /* ____ */
  121. reserve(resv)
  122. register struct tokenname resv[];
  123. {
  124. /* The names of the tokens described in resv are entered
  125. as reserved words.
  126. */
  127. while (resv->tn_symbol) {
  128. struct idf *idf = str2idf(resv->tn_name);
  129. if (idf->id_reserved)
  130. fatal("maximum identifier length insufficient");
  131. idf->id_reserved = resv->tn_symbol;
  132. resv++;
  133. }
  134. }