tokens.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
  4. Tokens used by the compiler
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit tokens;
  19. interface
  20. uses
  21. globtype;
  22. const
  23. tokenidlen=14;
  24. tokheader=#8'Free Pascal Compiler -- Token data'#13#10#26;
  25. type
  26. ttoken=(NOTOKEN,
  27. { operators, which can also be overloaded }
  28. _PLUS,
  29. _MINUS,
  30. _STAR,
  31. _SLASH,
  32. _EQUAL,
  33. _GT,
  34. _LT,
  35. _GTE,
  36. _LTE,
  37. _SYMDIF,
  38. _STARSTAR,
  39. _OP_IS,
  40. _OP_AS,
  41. _OP_IN,
  42. _ASSIGNMENT,
  43. { special chars }
  44. _CARET,
  45. _UNEQUAL,
  46. _LECKKLAMMER,
  47. _RECKKLAMMER,
  48. _POINT,
  49. _COMMA,
  50. _LKLAMMER,
  51. _RKLAMMER,
  52. _COLON,
  53. _SEMICOLON,
  54. _KLAMMERAFFE,
  55. _POINTPOINT,
  56. _DOUBLEADDR,
  57. _EOF,
  58. _ID,
  59. _NOID,
  60. _REALNUMBER,
  61. _INTCONST,
  62. _CSTRING,
  63. _CCHAR,
  64. { C like operators }
  65. _PLUSASN,
  66. _MINUSASN,
  67. _ANDASN,
  68. _ORASN,
  69. _STARASN,
  70. _SLASHASN,
  71. _MODASN,
  72. _DIVASN,
  73. _NOTASN,
  74. _XORASN,
  75. { Normal words }
  76. _AS,
  77. _AT,
  78. _DO,
  79. _IF,
  80. _IN,
  81. _IS,
  82. _OF,
  83. _ON,
  84. _OR,
  85. _TO,
  86. _AND,
  87. _ASM,
  88. _DIV,
  89. _END,
  90. _FAR,
  91. _FOR,
  92. _MOD,
  93. _NEW,
  94. _NIL,
  95. _NOT,
  96. _SET,
  97. _SHL,
  98. _SHR,
  99. _TRY,
  100. _VAR,
  101. _XOR,
  102. _CASE,
  103. _CVAR,
  104. _ELSE,
  105. _EXIT,
  106. _FAIL,
  107. _FILE,
  108. _GOTO,
  109. _NAME,
  110. _NEAR,
  111. _READ,
  112. _SELF,
  113. _THEN,
  114. _TRUE,
  115. _TYPE,
  116. _UNIT,
  117. _USES,
  118. _WITH,
  119. _ALIAS,
  120. _ARRAY,
  121. _BEGIN,
  122. _BREAK,
  123. _CDECL,
  124. _CLASS,
  125. _CONST,
  126. _FALSE,
  127. _INDEX,
  128. _LABEL,
  129. _RAISE,
  130. _UNTIL,
  131. _WHILE,
  132. _WRITE,
  133. _DOWNTO,
  134. _EXCEPT,
  135. _EXPORT,
  136. _INLINE,
  137. _OBJECT,
  138. _PACKED,
  139. _PASCAL,
  140. _PUBLIC,
  141. _RECORD,
  142. _REPEAT,
  143. _RESULT,
  144. _STATIC,
  145. _STORED,
  146. _STRING,
  147. _SYSTEM,
  148. _ASMNAME,
  149. _DEFAULT,
  150. _DISPOSE,
  151. _DYNAMIC,
  152. _EXPORTS,
  153. _FINALLY,
  154. _FORWARD,
  155. _IOCHECK,
  156. _LIBRARY,
  157. _MESSAGE,
  158. _PRIVATE,
  159. _PROGRAM,
  160. _STDCALL,
  161. _SYSCALL,
  162. _VIRTUAL,
  163. _ABSOLUTE,
  164. _ABSTRACT,
  165. _CONTINUE,
  166. _EXTERNAL,
  167. _FUNCTION,
  168. _OPERATOR,
  169. _OVERRIDE,
  170. _POPSTACK,
  171. _PROPERTY,
  172. _REGISTER,
  173. _RESIDENT,
  174. _SAFECALL,
  175. _ASSEMBLER,
  176. _INHERITED,
  177. _INTERFACE,
  178. _INTERRUPT,
  179. _NODEFAULT,
  180. _OTHERWISE,
  181. _PROCEDURE,
  182. _PROTECTED,
  183. _PUBLISHED,
  184. _THREADVAR,
  185. _DESTRUCTOR,
  186. _INTERNPROC,
  187. _OPENSTRING,
  188. _CONSTRUCTOR,
  189. _INTERNCONST,
  190. _SHORTSTRING,
  191. _FINALIZATION,
  192. _SAVEREGISTERS,
  193. _IMPLEMENTATION,
  194. _INITIALIZATION,
  195. _RESOURCESTRING
  196. );
  197. tokenrec=record
  198. str : string[tokenidlen];
  199. special : boolean;
  200. keyword : tmodeswitch;
  201. encoded : longint;
  202. end;
  203. ttokenarray=array[ttoken] of tokenrec;
  204. ptokenarray=^ttokenarray;
  205. tokenidxrec=record
  206. first,last : ttoken;
  207. end;
  208. ptokenidx=^ttokenidx;
  209. ttokenidx=array[2..tokenidlen,'A'..'Z'] of tokenidxrec;
  210. var tokeninfo:ptokenarray;
  211. tokenidx:ptokenidx;
  212. procedure inittokens;
  213. procedure donetokens;
  214. {$ifndef TP}
  215. {$define IncludeTokens}
  216. {$i tokendat.pas}
  217. {$endif not TP}
  218. implementation
  219. uses globals;
  220. {$ifndef TP}
  221. {$undef IncludeTokens}
  222. {$define IncludeCreateTokenIndex}
  223. {$i tokendat.pas}
  224. {$endif not TP}
  225. procedure inittokens;
  226. {$ifdef TP}
  227. var
  228. f:file;
  229. header:string;
  230. a:longint;
  231. {$endif TP}
  232. begin
  233. {$ifdef TP}
  234. assign(f,exepath+'tokens.dat');
  235. reset(f,1);
  236. {We are not sure that the msg file is loaded!}
  237. if ioresult<>0 then
  238. begin
  239. close(f);
  240. { Very nice indeed !!! PM }
  241. writeln('Fatal: File tokens.dat not found.');
  242. halt(3);
  243. end;
  244. blockread(f,header,1);
  245. blockread(f,header[1],length(header));
  246. blockread(f,a,sizeof(a));
  247. if (header<>tokheader) or (a<>sizeof(ttokenarray)) then
  248. begin
  249. close(f);
  250. writeln('Fatal: File tokens.dat corrupt.');
  251. halt(3);
  252. end;
  253. new(tokeninfo);
  254. blockread(f,tokeninfo^,sizeof(ttokenarray));
  255. new(tokenidx);
  256. blockread(f,tokenidx^,sizeof(tokenidx^));
  257. close(f);
  258. {$else not TP}
  259. tokeninfo:=@arraytokeninfo;
  260. new(tokenidx);
  261. create_tokenidx;
  262. {$endif not TP}
  263. end;
  264. procedure donetokens;
  265. begin
  266. {$ifdef TP}
  267. dispose(tokeninfo);
  268. {$else TP}
  269. tokeninfo:=nil;
  270. {$endif TP}
  271. dispose(tokenidx);
  272. end;
  273. end.
  274. {
  275. $Log$
  276. Revision 1.13 1999-09-03 08:37:34 pierre
  277. * tokens.dat only used for TP, and also removed from
  278. compiler dependencies
  279. Revision 1.12 1999/09/02 18:47:49 daniel
  280. * Could not compile with TP, some arrays moved to heap
  281. * NOAG386BIN default for TP
  282. * AG386* files were not compatible with TP, fixed.
  283. Revision 1.11 1999/08/04 13:03:17 jonas
  284. * all tokens now start with an underscore
  285. * PowerPC compiles!!
  286. Revision 1.10 1999/08/03 22:03:39 peter
  287. * moved bitmask constants to sets
  288. * some other type/const renamings
  289. Revision 1.9 1999/07/22 09:38:01 florian
  290. + resourcestring implemented
  291. + start of longstring support
  292. Revision 1.8 1999/07/10 10:26:21 peter
  293. * merged
  294. Revision 1.7.2.1 1999/07/10 10:03:18 peter
  295. * fixed initialization/finalization in fpc mode
  296. * allow $TARGET also in search paths
  297. Revision 1.7 1999/05/24 08:55:30 florian
  298. * non working safecall directiv implemented, I don't know if we
  299. need it
  300. Revision 1.6 1999/04/28 06:02:19 florian
  301. * changes of Bruessel:
  302. + message handler can now take an explicit self
  303. * typinfo fixed: sometimes the type names weren't written
  304. * the type checking for pointer comparisations and subtraction
  305. and are now more strict (was also buggy)
  306. * small bug fix to link.pas to support compiling on another
  307. drive
  308. * probable bug in popt386 fixed: call/jmp => push/jmp
  309. transformation didn't count correctly the jmp references
  310. + threadvar support
  311. * warning if ln/sqrt gets an invalid constant argument
  312. Revision 1.5 1999/04/06 11:22:01 peter
  313. * more use of ttoken
  314. Revision 1.4 1999/04/01 22:07:53 peter
  315. * universal string names (ansistr instead of stransi) for val/str
  316. Revision 1.3 1999/02/22 20:13:41 florian
  317. + first implementation of message keyword
  318. Revision 1.2 1999/02/05 12:51:21 florian
  319. + openstring id is now supported
  320. Revision 1.1 1998/12/11 00:04:02 peter
  321. + globtype,tokens,version unit splitted from globals
  322. }