tokenname.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* T O K E N D E F I N I T I O N S */
  2. #include "Lpars.h"
  3. #include "idf.h"
  4. #include "tokenname.h"
  5. /* To centralize the declaration of %tokens, their presence in this
  6. file is taken as their declaration. The Makefile will produce
  7. a grammar file (tokenfile.g) from this file. This scheme ensures
  8. that all tokens have a printable name.
  9. Also, the "symbol2str.c" file is produced from this file.
  10. */
  11. struct tokenname tkspec[] = { /* the names of the special tokens */
  12. {IDENT, "identifier"},
  13. {STRING, "string"},
  14. {INTEGER, "integer"},
  15. {REAL, "real"},
  16. {0, ""}
  17. };
  18. struct tokenname tkcomp[] = { /* names of the composite tokens */
  19. {LESSEQUAL, "<="},
  20. {GREATEREQUAL, ">="},
  21. {NOTEQUAL, "<>"},
  22. {UPTO, ".."},
  23. {BECOMES, ":="},
  24. {0, ""}
  25. };
  26. struct tokenname tkidf[] = { /* names of the identifier tokens */
  27. {AND, "and"},
  28. {ARRAY, "array"},
  29. {BEGIN, "begin"},
  30. {CASE, "case"},
  31. {CONST, "const"},
  32. {DIV, "div"},
  33. {DO, "do"},
  34. {DOWNTO, "downto"},
  35. {ELSE, "else"},
  36. {END, "end"},
  37. {FILE, "file"},
  38. {FOR, "for"},
  39. {FUNCTION, "function"},
  40. {GOTO, "goto"},
  41. {IF, "if"},
  42. {IN, "in"},
  43. {LABEL, "label"},
  44. {MOD, "mod"},
  45. {NIL, "nil"},
  46. {NOT, "not"},
  47. {OF, "of"},
  48. {OR, "or"},
  49. {PACKED, "packed"},
  50. {PROCEDURE, "procedure"},
  51. {PROGRAM, "program"},
  52. {RECORD, "record"},
  53. {REPEAT, "repeat"},
  54. {SET, "set"},
  55. {THEN, "then"},
  56. {TO, "to"},
  57. {TYPE, "type"},
  58. {UNTIL, "until"},
  59. {VAR, "var"},
  60. {WHILE, "while"},
  61. {WITH, "with"},
  62. {0, ""}
  63. };
  64. struct tokenname tkstandard[] = { /* standard identifiers */
  65. /* These are the only standard identifiers entered here, because
  66. * they can get a variable number of arguments, and there are
  67. * special syntaxrules in the grammar for them
  68. */
  69. {READ, "read"},
  70. {READLN, "readln"},
  71. {WRITE, "write"},
  72. {WRITELN, "writeln"},
  73. {0, ""}
  74. };
  75. /* Some routines to handle tokennames */
  76. reserve(resv)
  77. register struct tokenname *resv;
  78. {
  79. /* The names of the tokens described in resv are entered
  80. as reserved words.
  81. */
  82. register struct idf *p;
  83. while( resv->tn_symbol ) {
  84. p = str2idf(resv->tn_name, 0);
  85. if( !p ) fatal("out of Memory");
  86. p->id_reserved = resv->tn_symbol;
  87. resv++;
  88. }
  89. }