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. #include "error.h"
  13. /* To centralize the declaration of %tokens, their presence in this
  14. file is taken as their declaration. The Makefile will produce
  15. a grammar file (tokenfile.g) from this file.
  16. Moreover, rather than looking up a symbol in all these lists
  17. to find its printable name, a fast version of symbol2str() is
  18. generated from these tables.
  19. Consequenty some of these tables are not referenced explicitly
  20. in the C text any more. To save space and to avoid lint confusion,
  21. these have been made pseudo-invisible by #ifdefs.
  22. */
  23. #ifdef ____
  24. struct tokenname tkspec[] = { /* the names of the special tokens */
  25. {IDENTIFIER, "identifier"},
  26. {TYPE_IDENTIFIER, "type_identifier"},
  27. {STRING, "string"},
  28. {WCHAR, "wchar"},
  29. {FILESPECIFIER, "filespecifier"},
  30. {INTEGER, "integer"},
  31. {FLOATING, "floating"},
  32. {0, ""}
  33. };
  34. #endif /* ____ */
  35. #ifdef ____
  36. struct tokenname tkcomp[] = { /* names of the composite tokens */
  37. {PLUSAB, "+="},
  38. {MINAB, "-="},
  39. {TIMESAB, "*="},
  40. {DIVAB, "/="},
  41. {MODAB, "%="},
  42. {LEFTAB, "<<="},
  43. {RIGHTAB, ">>="},
  44. {ANDAB, "&="},
  45. {XORAB, "^="},
  46. {ORAB, "|="},
  47. {NOTEQUAL, "!="},
  48. {AND, "&&"},
  49. {PLUSPLUS, "++"},
  50. {MINMIN, "--"},
  51. {ARROW, "->"},
  52. {LEFT, "<<"},
  53. {LESSEQ, "<="},
  54. {EQUAL, "=="},
  55. {GREATEREQ, ">="},
  56. {RIGHT, ">>"},
  57. {OR, "||"},
  58. {ELLIPSIS, "..."},
  59. {0, ""}
  60. };
  61. #endif /* ____ */
  62. struct tokenname tkidf[] = { /* names of the identifier tokens */
  63. {AUTO, "auto"},
  64. {BREAK, "break"},
  65. {CASE, "case"},
  66. {CONST, "const"},
  67. {CONTINUE, "continue"},
  68. {DEFAULT, "default"},
  69. {DO, "do"},
  70. {ELSE, "else"},
  71. {ENUM, "enum"},
  72. {EXTERN, "extern"},
  73. {FOR, "for"},
  74. {GOTO, "goto"},
  75. {IF, "if"},
  76. {LONG, "long"},
  77. {REGISTER, "register"},
  78. {RETURN, "return"},
  79. {SHORT, "short"},
  80. {SIGNED, "signed"},
  81. {SIZEOF, "sizeof"},
  82. {STATIC, "static"},
  83. {STRUCT, "struct"},
  84. {SWITCH, "switch"},
  85. {TYPEDEF, "typedef"},
  86. {UNION, "union"},
  87. {UNSIGNED, "unsigned"},
  88. {VOLATILE, "volatile"},
  89. {WHILE, "while"},
  90. {VOID, "void"},
  91. {CHAR, "char"},
  92. {INT, "int"},
  93. {FLOAT, "float"},
  94. {DOUBLE, "double"},
  95. {0, ""}
  96. };
  97. #ifdef ____
  98. struct tokenname tkfunny[] = { /* internal keywords */
  99. {LNGDBL, "long double"},
  100. {ULONG, "unsigned long"},
  101. {ARRAY, "array"},
  102. {FUNCTION, "function"},
  103. {POINTER, "pointer"},
  104. {FIELD, "field"},
  105. {GLOBAL, "global"},
  106. {FORMAL, "formal"},
  107. {LABEL, "label"},
  108. {ERRONEOUS, "erroneous"},
  109. {PARCOMMA, "parcomma"},
  110. {INITCOMMA, "initcomma"},
  111. {CAST, "cast"},
  112. {CASTAB, "castab"},
  113. {ADDRESSOF,"unary &"},
  114. {POSTINCR, "postfix ++"},
  115. {POSTDECR, "postfix --"},
  116. {INT2INT, "int2int"},
  117. {INT2FLOAT, "int2float"},
  118. {FLOAT2INT, "float2int"},
  119. {FLOAT2FLOAT, "float2float"},
  120. {0, ""}
  121. };
  122. #endif /* ____ */
  123. void reserve(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. }