tokenname.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. {WCHAR, "wchar"},
  28. {FILESPECIFIER, "filespecifier"},
  29. {INTEGER, "integer"},
  30. {FLOATING, "floating"},
  31. {0, ""}
  32. };
  33. #endif /* ____ */
  34. #ifdef ____
  35. struct tokenname tkcomp[] = { /* names of the composite tokens */
  36. {PLUSAB, "+="},
  37. {MINAB, "-="},
  38. {TIMESAB, "*="},
  39. {DIVAB, "/="},
  40. {MODAB, "%="},
  41. {LEFTAB, "<<="},
  42. {RIGHTAB, ">>="},
  43. {ANDAB, "&="},
  44. {XORAB, "^="},
  45. {ORAB, "|="},
  46. {NOTEQUAL, "!="},
  47. {AND, "&&"},
  48. {PLUSPLUS, "++"},
  49. {MINMIN, "--"},
  50. {ARROW, "->"},
  51. {LEFT, "<<"},
  52. {LESSEQ, "<="},
  53. {EQUAL, "=="},
  54. {GREATEREQ, ">="},
  55. {RIGHT, ">>"},
  56. {OR, "||"},
  57. {ELLIPSIS, "..."},
  58. {0, ""}
  59. };
  60. #endif /* ____ */
  61. struct tokenname tkidf[] = { /* names of the identifier tokens */
  62. {AUTO, "auto"},
  63. {BREAK, "break"},
  64. {CASE, "case"},
  65. {CONST, "const"},
  66. {CONTINUE, "continue"},
  67. {DEFAULT, "default"},
  68. {DO, "do"},
  69. {ELSE, "else"},
  70. {ENUM, "enum"},
  71. {EXTERN, "extern"},
  72. {FOR, "for"},
  73. {GOTO, "goto"},
  74. {IF, "if"},
  75. {LONG, "long"},
  76. {REGISTER, "register"},
  77. {RETURN, "return"},
  78. {SHORT, "short"},
  79. {SIGNED, "signed"},
  80. {SIZEOF, "sizeof"},
  81. {STATIC, "static"},
  82. {STRUCT, "struct"},
  83. {SWITCH, "switch"},
  84. {TYPEDEF, "typedef"},
  85. {UNION, "union"},
  86. {UNSIGNED, "unsigned"},
  87. {VOLATILE, "volatile"},
  88. {WHILE, "while"},
  89. {VOID, "void"},
  90. {CHAR, "char"},
  91. {INT, "int"},
  92. {FLOAT, "float"},
  93. {DOUBLE, "double"},
  94. {0, ""}
  95. };
  96. #ifdef ____
  97. struct tokenname tkfunny[] = { /* internal keywords */
  98. {LNGDBL, "long double"},
  99. {ULONG, "unsigned long"},
  100. {ARRAY, "array"},
  101. {FUNCTION, "function"},
  102. {POINTER, "pointer"},
  103. {FIELD, "field"},
  104. {GLOBAL, "global"},
  105. {FORMAL, "formal"},
  106. {LABEL, "label"},
  107. {ERRONEOUS, "erroneous"},
  108. {PARCOMMA, "parcomma"},
  109. {INITCOMMA, "initcomma"},
  110. {CAST, "cast"},
  111. {CASTAB, "castab"},
  112. {ADDRESSOF,"unary &"},
  113. {POSTINCR, "postfix ++"},
  114. {POSTDECR, "postfix --"},
  115. {INT2INT, "int2int"},
  116. {INT2FLOAT, "int2float"},
  117. {FLOAT2INT, "float2int"},
  118. {FLOAT2FLOAT, "float2float"},
  119. {0, ""}
  120. };
  121. #endif /* ____ */
  122. reserve(resv)
  123. register struct tokenname resv[];
  124. {
  125. /* The names of the tokens described in resv are entered
  126. as reserved words.
  127. */
  128. while (resv->tn_symbol) {
  129. struct idf *idf = str2idf(resv->tn_name, 0);
  130. if (idf->id_reserved)
  131. fatal("maximum identifier length insufficient");
  132. idf->id_reserved = resv->tn_symbol;
  133. resv++;
  134. }
  135. }