scanner.pas 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements the scanner part and handling of the switches
  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. {$ifdef tp}
  19. {$F+,N+,E+,R-}
  20. {$endif}
  21. unit scanner;
  22. interface
  23. uses
  24. {$ifdef Delphi}
  25. dmisc,
  26. {$endif Delphi}
  27. globtype,version,tokens,
  28. cobjects,globals,verbose,comphook,files;
  29. const
  30. {$ifdef TP}
  31. maxmacrolen=1024;
  32. preprocbufsize=1024;
  33. {$else}
  34. maxmacrolen=16*1024;
  35. preprocbufsize=32*1024;
  36. {$endif}
  37. Newline = #10;
  38. type
  39. tcommentstyle = (comment_none,comment_tp,comment_oldtp,comment_delphi,comment_c);
  40. pmacrobuffer = ^tmacrobuffer;
  41. tmacrobuffer = array[0..maxmacrolen-1] of char;
  42. preproctyp = (pp_ifdef,pp_ifndef,pp_if,pp_ifopt,pp_else);
  43. ppreprocstack = ^tpreprocstack;
  44. tpreprocstack = object
  45. typ : preproctyp;
  46. accept : boolean;
  47. next : ppreprocstack;
  48. name : stringid;
  49. line_nb : longint;
  50. constructor init(atyp:preproctyp;a:boolean;n:ppreprocstack);
  51. destructor done;
  52. end;
  53. pscannerfile = ^tscannerfile;
  54. tscannerfile = object
  55. inputfile : pinputfile; { current inputfile list }
  56. inputbuffer, { input buffer }
  57. inputpointer : pchar;
  58. inputstart : longint;
  59. line_no, { line }
  60. lastlinepos : longint;
  61. lasttokenpos : longint; { token }
  62. lasttoken,
  63. nexttoken : ttoken;
  64. comment_level,
  65. yylexcount : longint;
  66. lastasmgetchar : char;
  67. preprocstack : ppreprocstack;
  68. invalid : boolean; { flag if sourcefiles have been destroyed ! }
  69. constructor init(const fn:string);
  70. destructor done;
  71. { File buffer things }
  72. function openinputfile:boolean;
  73. procedure closeinputfile;
  74. function tempopeninputfile:boolean;
  75. procedure tempcloseinputfile;
  76. procedure saveinputfile;
  77. procedure restoreinputfile;
  78. procedure nextfile;
  79. procedure addfile(hp:pinputfile);
  80. procedure reload;
  81. procedure insertmacro(const macname:string;p:pchar;len:longint);
  82. { Scanner things }
  83. procedure gettokenpos;
  84. procedure inc_comment_level;
  85. procedure dec_comment_level;
  86. procedure end_of_file;
  87. procedure checkpreprocstack;
  88. procedure poppreprocstack;
  89. procedure addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:tmsgconst);
  90. procedure elsepreprocstack;
  91. procedure linebreak;
  92. procedure readchar;
  93. procedure readstring;
  94. procedure readnumber;
  95. function readid:string;
  96. function readval:longint;
  97. function readcomment:string;
  98. function readstate:char;
  99. procedure skipspace;
  100. procedure skipuntildirective;
  101. procedure skipcomment;
  102. procedure skipdelphicomment;
  103. procedure skipoldtpcomment;
  104. procedure readtoken;
  105. function readpreproc:ttoken;
  106. function asmgetchar:char;
  107. end;
  108. ppreprocfile=^tpreprocfile;
  109. tpreprocfile=object
  110. f : text;
  111. buf : pointer;
  112. spacefound,
  113. eolfound : boolean;
  114. constructor init(const fn:string);
  115. destructor done;
  116. procedure Add(const s:string);
  117. procedure AddSpace;
  118. end;
  119. var
  120. c : char;
  121. orgpattern,
  122. pattern : string;
  123. current_scanner : pscannerfile;
  124. aktcommentstyle : tcommentstyle; { needed to use read_comment from directives }
  125. preprocfile : ppreprocfile; { used with only preprocessing }
  126. implementation
  127. uses
  128. {$ifndef delphi}
  129. dos,
  130. {$endif delphi}
  131. systems,symtable,switches;
  132. {*****************************************************************************
  133. Helper routines
  134. *****************************************************************************}
  135. const
  136. { use any special name that is an invalid file name to avoid problems }
  137. preprocstring : array [preproctyp] of string[7]
  138. = ('$IFDEF','$IFNDEF','$IF','$IFOPT','$ELSE');
  139. function is_keyword(const s:string):boolean;
  140. var
  141. low,high,mid : longint;
  142. begin
  143. if not (length(s) in [2..tokenidlen]) then
  144. begin
  145. is_keyword:=false;
  146. exit;
  147. end;
  148. low:=ord(tokenidx^[length(s),s[1]].first);
  149. high:=ord(tokenidx^[length(s),s[1]].last);
  150. while low<high do
  151. begin
  152. mid:=(high+low+1) shr 1;
  153. if pattern<tokeninfo^[ttoken(mid)].str then
  154. high:=mid-1
  155. else
  156. low:=mid;
  157. end;
  158. is_keyword:=(pattern=tokeninfo^[ttoken(high)].str) and
  159. (tokeninfo^[ttoken(high)].keyword in aktmodeswitches);
  160. end;
  161. {*****************************************************************************
  162. Preprocessor writting
  163. *****************************************************************************}
  164. constructor tpreprocfile.init(const fn:string);
  165. begin
  166. { open outputfile }
  167. assign(f,fn);
  168. {$I-}
  169. rewrite(f);
  170. {$I+}
  171. if ioresult<>0 then
  172. Comment(V_Fatal,'can''t create file '+fn);
  173. getmem(buf,preprocbufsize);
  174. settextbuf(f,buf^,preprocbufsize);
  175. { reset }
  176. eolfound:=false;
  177. spacefound:=false;
  178. end;
  179. destructor tpreprocfile.done;
  180. begin
  181. close(f);
  182. freemem(buf,preprocbufsize);
  183. end;
  184. procedure tpreprocfile.add(const s:string);
  185. begin
  186. write(f,s);
  187. end;
  188. procedure tpreprocfile.addspace;
  189. begin
  190. if eolfound then
  191. begin
  192. writeln(f,'');
  193. eolfound:=false;
  194. spacefound:=false;
  195. end
  196. else
  197. if spacefound then
  198. begin
  199. write(f,' ');
  200. spacefound:=false;
  201. end;
  202. end;
  203. {*****************************************************************************
  204. TPreProcStack
  205. *****************************************************************************}
  206. constructor tpreprocstack.init(atyp : preproctyp;a:boolean;n:ppreprocstack);
  207. begin
  208. accept:=a;
  209. typ:=atyp;
  210. next:=n;
  211. end;
  212. destructor tpreprocstack.done;
  213. begin
  214. end;
  215. {****************************************************************************
  216. TSCANNERFILE
  217. ****************************************************************************}
  218. constructor tscannerfile.init(const fn:string);
  219. begin
  220. inputfile:=new(pinputfile,init(fn));
  221. current_module^.sourcefiles^.register_file(inputfile);
  222. { reset localinput }
  223. inputbuffer:=nil;
  224. inputpointer:=nil;
  225. inputstart:=0;
  226. { reset scanner }
  227. preprocstack:=nil;
  228. comment_level:=0;
  229. yylexcount:=0;
  230. block_type:=bt_general;
  231. line_no:=0;
  232. lastlinepos:=0;
  233. lasttokenpos:=0;
  234. lasttoken:=NOTOKEN;
  235. nexttoken:=NOTOKEN;
  236. lastasmgetchar:=#0;
  237. invalid:=false;
  238. { load block }
  239. if not openinputfile then
  240. Message1(scan_f_cannot_open_input,fn);
  241. reload;
  242. { process first read char }
  243. case c of
  244. #26 : reload;
  245. #10,
  246. #13 : linebreak;
  247. end;
  248. end;
  249. destructor tscannerfile.done;
  250. begin
  251. if not invalid then
  252. begin
  253. if status.errorcount=0 then
  254. checkpreprocstack;
  255. { close file, but only if we are the first compile }
  256. { probably not necessary anymore with invalid flag PM }
  257. if not current_module^.in_second_compile then
  258. begin
  259. if not inputfile^.closed then
  260. closeinputfile;
  261. end;
  262. end;
  263. end;
  264. function tscannerfile.openinputfile:boolean;
  265. begin
  266. openinputfile:=inputfile^.open;
  267. { load buffer }
  268. inputbuffer:=inputfile^.buf;
  269. inputpointer:=inputfile^.buf;
  270. inputstart:=inputfile^.bufstart;
  271. { line }
  272. line_no:=0;
  273. lastlinepos:=0;
  274. lasttokenpos:=0;
  275. end;
  276. procedure tscannerfile.closeinputfile;
  277. begin
  278. inputfile^.close;
  279. { reset buffer }
  280. inputbuffer:=nil;
  281. inputpointer:=nil;
  282. inputstart:=0;
  283. { reset line }
  284. line_no:=0;
  285. lastlinepos:=0;
  286. lasttokenpos:=0;
  287. end;
  288. function tscannerfile.tempopeninputfile:boolean;
  289. begin
  290. tempopeninputfile:=inputfile^.tempopen;
  291. { reload buffer }
  292. inputbuffer:=inputfile^.buf;
  293. inputpointer:=inputfile^.buf;
  294. inputstart:=inputfile^.bufstart;
  295. end;
  296. procedure tscannerfile.tempcloseinputfile;
  297. begin
  298. inputfile^.setpos(inputstart+(inputpointer-inputbuffer));
  299. inputfile^.tempclose;
  300. { reset buffer }
  301. inputbuffer:=nil;
  302. inputpointer:=nil;
  303. inputstart:=0;
  304. end;
  305. procedure tscannerfile.saveinputfile;
  306. begin
  307. inputfile^.saveinputpointer:=inputpointer;
  308. inputfile^.savelastlinepos:=lastlinepos;
  309. inputfile^.saveline_no:=line_no;
  310. end;
  311. procedure tscannerfile.restoreinputfile;
  312. begin
  313. inputpointer:=inputfile^.saveinputpointer;
  314. lastlinepos:=inputfile^.savelastlinepos;
  315. line_no:=inputfile^.saveline_no;
  316. if not inputfile^.is_macro then
  317. parser_current_file:=inputfile^.name^;
  318. end;
  319. procedure tscannerfile.nextfile;
  320. var
  321. to_dispose : pinputfile;
  322. begin
  323. if assigned(inputfile^.next) then
  324. begin
  325. if inputfile^.is_macro then
  326. to_dispose:=inputfile
  327. else
  328. to_dispose:=nil;
  329. { we can allways close the file, no ? }
  330. inputfile^.close;
  331. inputfile:=inputfile^.next;
  332. if assigned(to_dispose) then
  333. dispose(to_dispose,done);
  334. restoreinputfile;
  335. end;
  336. end;
  337. procedure tscannerfile.addfile(hp:pinputfile);
  338. begin
  339. saveinputfile;
  340. { add to list }
  341. hp^.next:=inputfile;
  342. inputfile:=hp;
  343. { load new inputfile }
  344. restoreinputfile;
  345. end;
  346. procedure tscannerfile.reload;
  347. begin
  348. with inputfile^ do
  349. begin
  350. repeat
  351. { still more to read?, then change the #0 to a space so its seen
  352. as a seperator, this can't be used for macro's which can change
  353. the place of the #0 in the buffer with tempopen }
  354. if (c=#0) and (bufsize>0) and
  355. not(inputfile^.is_macro) and
  356. (inputpointer-inputbuffer<bufsize) then
  357. begin
  358. c:=' ';
  359. inc(longint(inputpointer));
  360. exit;
  361. end;
  362. { can we read more from this file ? }
  363. if (c<>#26) and (not endoffile) then
  364. begin
  365. readbuf;
  366. inputpointer:=buf;
  367. inputbuffer:=buf;
  368. inputstart:=bufstart;
  369. { first line? }
  370. if line_no=0 then
  371. begin
  372. line_no:=1;
  373. if cs_asm_source in aktglobalswitches then
  374. inputfile^.setline(line_no,bufstart);
  375. end;
  376. end
  377. else
  378. begin
  379. { load eof position in tokenpos/aktfilepos }
  380. gettokenpos;
  381. { close file }
  382. closeinputfile;
  383. { no next module, than EOF }
  384. if not assigned(inputfile^.next) then
  385. begin
  386. c:=#26;
  387. exit;
  388. end;
  389. { load next file and reopen it }
  390. nextfile;
  391. tempopeninputfile;
  392. { status }
  393. Message1(scan_t_back_in,inputfile^.name^);
  394. end;
  395. { load next char }
  396. c:=inputpointer^;
  397. inc(longint(inputpointer));
  398. until c<>#0; { if also end, then reload again }
  399. end;
  400. end;
  401. procedure tscannerfile.insertmacro(const macname:string;p:pchar;len:longint);
  402. var
  403. hp : pinputfile;
  404. begin
  405. { save old postion and decrease linebreak }
  406. if c=newline then
  407. dec(line_no);
  408. dec(longint(inputpointer));
  409. tempcloseinputfile;
  410. { create macro 'file' }
  411. { use special name to dispose after !! }
  412. hp:=new(pinputfile,init('_Macro_.'+macname));
  413. addfile(hp);
  414. with inputfile^ do
  415. begin
  416. setmacro(p,len);
  417. { local buffer }
  418. inputbuffer:=buf;
  419. inputpointer:=buf;
  420. inputstart:=bufstart;
  421. end;
  422. { reset line }
  423. line_no:=0;
  424. lastlinepos:=0;
  425. lasttokenpos:=0;
  426. { load new c }
  427. c:=inputpointer^;
  428. inc(longint(inputpointer));
  429. end;
  430. procedure tscannerfile.gettokenpos;
  431. { load the values of tokenpos and lasttokenpos }
  432. begin
  433. lasttokenpos:=inputstart+(inputpointer-inputbuffer);
  434. tokenpos.line:=line_no;
  435. tokenpos.column:=lasttokenpos-lastlinepos;
  436. tokenpos.fileindex:=inputfile^.ref_index;
  437. aktfilepos:=tokenpos;
  438. end;
  439. procedure tscannerfile.inc_comment_level;
  440. var
  441. oldaktfilepos : tfileposinfo;
  442. begin
  443. if (m_nested_comment in aktmodeswitches) then
  444. inc(comment_level)
  445. else
  446. comment_level:=1;
  447. if (comment_level>1) then
  448. begin
  449. oldaktfilepos:=aktfilepos;
  450. gettokenpos; { update for warning }
  451. Message1(scan_w_comment_level,tostr(comment_level));
  452. aktfilepos:=oldaktfilepos;
  453. end;
  454. end;
  455. procedure tscannerfile.dec_comment_level;
  456. begin
  457. if (m_nested_comment in aktmodeswitches) then
  458. dec(comment_level)
  459. else
  460. comment_level:=0;
  461. end;
  462. procedure tscannerfile.linebreak;
  463. var
  464. cur : char;
  465. oldtokenpos,
  466. oldaktfilepos : tfileposinfo;
  467. begin
  468. with inputfile^ do
  469. begin
  470. if (byte(inputpointer^)=0) and not(endoffile) then
  471. begin
  472. cur:=c;
  473. reload;
  474. if byte(cur)+byte(c)<>23 then
  475. dec(longint(inputpointer));
  476. end
  477. else
  478. begin
  479. { Fix linebreak to be only newline (=#10) for all types of linebreaks }
  480. if (byte(inputpointer^)+byte(c)=23) then
  481. inc(longint(inputpointer));
  482. end;
  483. c:=newline;
  484. { increase line counters }
  485. lastlinepos:=bufstart+(inputpointer-inputbuffer);
  486. inc(line_no);
  487. { update linebuffer }
  488. if cs_asm_source in aktglobalswitches then
  489. inputfile^.setline(line_no,lastlinepos);
  490. { update for status and call the show status routine,
  491. but don't touch aktfilepos ! }
  492. oldaktfilepos:=aktfilepos;
  493. oldtokenpos:=tokenpos;
  494. gettokenpos; { update for v_status }
  495. inc(status.compiledlines);
  496. ShowStatus;
  497. aktfilepos:=oldaktfilepos;
  498. tokenpos:=oldtokenpos;
  499. end;
  500. end;
  501. procedure tscannerfile.end_of_file;
  502. begin
  503. checkpreprocstack;
  504. Message(scan_f_end_of_file);
  505. end;
  506. procedure tscannerfile.checkpreprocstack;
  507. begin
  508. { check for missing ifdefs }
  509. while assigned(preprocstack) do
  510. begin
  511. Message3(scan_e_endif_expected,preprocstring[preprocstack^.typ],preprocstack^.name,tostr(preprocstack^.line_nb));
  512. poppreprocstack;
  513. end;
  514. end;
  515. procedure tscannerfile.poppreprocstack;
  516. var
  517. hp : ppreprocstack;
  518. begin
  519. if assigned(preprocstack) then
  520. begin
  521. Message1(scan_c_endif_found,preprocstack^.name);
  522. hp:=preprocstack^.next;
  523. dispose(preprocstack,done);
  524. preprocstack:=hp;
  525. end
  526. else
  527. Message(scan_e_endif_without_if);
  528. end;
  529. procedure tscannerfile.addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:tmsgconst);
  530. begin
  531. preprocstack:=new(ppreprocstack,init(atyp,((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  532. preprocstack^.name:=s;
  533. preprocstack^.line_nb:=line_no;
  534. if preprocstack^.accept then
  535. Message2(w,preprocstack^.name,'accepted')
  536. else
  537. Message2(w,preprocstack^.name,'rejected');
  538. end;
  539. procedure tscannerfile.elsepreprocstack;
  540. begin
  541. if assigned(preprocstack) then
  542. begin
  543. preprocstack^.typ:=pp_else;
  544. preprocstack^.line_nb:=line_no;
  545. if not(assigned(preprocstack^.next)) or (preprocstack^.next^.accept) then
  546. preprocstack^.accept:=not preprocstack^.accept;
  547. if preprocstack^.accept then
  548. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  549. else
  550. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  551. end
  552. else
  553. Message(scan_e_endif_without_if);
  554. end;
  555. procedure tscannerfile.readchar;
  556. begin
  557. c:=inputpointer^;
  558. if c=#0 then
  559. reload
  560. else
  561. inc(longint(inputpointer));
  562. case c of
  563. #26 : reload;
  564. #10,
  565. #13 : linebreak;
  566. end;
  567. end;
  568. procedure tscannerfile.readstring;
  569. var
  570. i : longint;
  571. begin
  572. i:=0;
  573. repeat
  574. case c of
  575. '_',
  576. '0'..'9',
  577. 'A'..'Z' : begin
  578. if i<255 then
  579. begin
  580. inc(i);
  581. orgpattern[i]:=c;
  582. pattern[i]:=c;
  583. end;
  584. c:=inputpointer^;
  585. inc(longint(inputpointer));
  586. end;
  587. 'a'..'z' : begin
  588. if i<255 then
  589. begin
  590. inc(i);
  591. orgpattern[i]:=c;
  592. pattern[i]:=chr(ord(c)-32)
  593. end;
  594. c:=inputpointer^;
  595. inc(longint(inputpointer));
  596. end;
  597. #0 : reload;
  598. #26 : begin
  599. reload;
  600. if c=#26 then
  601. break;
  602. end;
  603. #13,#10 : begin
  604. linebreak;
  605. break;
  606. end;
  607. else
  608. break;
  609. end;
  610. until false;
  611. {$ifndef TP}
  612. {$ifopt H+}
  613. setlength(orgpattern,i);
  614. setlength(pattern,i);
  615. {$else}
  616. orgpattern[0]:=chr(i);
  617. pattern[0]:=chr(i);
  618. {$endif}
  619. {$else}
  620. orgpattern[0]:=chr(i);
  621. pattern[0]:=chr(i);
  622. {$endif}
  623. end;
  624. procedure tscannerfile.readnumber;
  625. var
  626. base,
  627. i : longint;
  628. begin
  629. case c of
  630. '%' : begin
  631. readchar;
  632. base:=2;
  633. pattern[1]:='%';
  634. i:=1;
  635. end;
  636. '$' : begin
  637. readchar;
  638. base:=16;
  639. pattern[1]:='$';
  640. i:=1;
  641. end;
  642. else
  643. begin
  644. base:=10;
  645. i:=0;
  646. end;
  647. end;
  648. while ((base>=10) and (c in ['0'..'9'])) or
  649. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  650. ((base=2) and (c in ['0'..'1'])) do
  651. begin
  652. if i<255 then
  653. begin
  654. inc(i);
  655. pattern[i]:=c;
  656. end;
  657. { get next char }
  658. c:=inputpointer^;
  659. if c=#0 then
  660. reload
  661. else
  662. inc(longint(inputpointer));
  663. end;
  664. { was the next char a linebreak ? }
  665. case c of
  666. #26 : reload;
  667. #10,
  668. #13 : linebreak;
  669. end;
  670. {$ifndef TP}
  671. {$ifopt H+}
  672. setlength(pattern,i);
  673. {$else}
  674. pattern[0]:=chr(i);
  675. {$endif}
  676. {$else}
  677. pattern[0]:=chr(i);
  678. {$endif}
  679. end;
  680. function tscannerfile.readid:string;
  681. begin
  682. readstring;
  683. readid:=pattern;
  684. end;
  685. function tscannerfile.readval:longint;
  686. var
  687. l : longint;
  688. w : integer;
  689. begin
  690. readnumber;
  691. valint(pattern,l,w);
  692. readval:=l;
  693. end;
  694. function tscannerfile.readcomment:string;
  695. var
  696. i : longint;
  697. begin
  698. i:=0;
  699. repeat
  700. case c of
  701. '{' :
  702. if aktcommentstyle=comment_tp then
  703. inc_comment_level;
  704. '}' :
  705. if aktcommentstyle=comment_tp then
  706. begin
  707. readchar;
  708. dec_comment_level;
  709. if comment_level=0 then
  710. break
  711. else
  712. continue;
  713. end;
  714. '*' :
  715. if aktcommentstyle=comment_oldtp then
  716. begin
  717. readchar;
  718. if c=')' then
  719. begin
  720. readchar;
  721. dec_comment_level;
  722. break;
  723. end;
  724. end;
  725. #26 :
  726. end_of_file;
  727. else
  728. begin
  729. if (i<255) then
  730. begin
  731. inc(i);
  732. readcomment[i]:=c;
  733. end;
  734. end;
  735. end;
  736. c:=inputpointer^;
  737. if c=#0 then
  738. reload
  739. else
  740. inc(longint(inputpointer));
  741. if c in [#10,#13] then
  742. linebreak;
  743. until false;
  744. {$ifndef TP}
  745. {$ifopt H+}
  746. setlength(readcomment,i);
  747. {$else}
  748. readcomment[0]:=chr(i);
  749. {$endif}
  750. {$else}
  751. readcomment[0]:=chr(i);
  752. {$endif}
  753. end;
  754. function tscannerfile.readstate:char;
  755. var
  756. state : char;
  757. begin
  758. state:=' ';
  759. if c=' ' then
  760. begin
  761. current_scanner^.skipspace;
  762. current_scanner^.readid;
  763. if pattern='ON' then
  764. state:='+'
  765. else
  766. if pattern='OFF' then
  767. state:='-';
  768. end
  769. else
  770. state:=c;
  771. if not (state in ['+','-']) then
  772. Message(scan_e_wrong_switch_toggle);
  773. readstate:=state;
  774. end;
  775. procedure tscannerfile.skipspace;
  776. begin
  777. while c in [' ',#9..#13] do
  778. begin
  779. c:=inputpointer^;
  780. if c=#0 then
  781. reload
  782. else
  783. inc(longint(inputpointer));
  784. case c of
  785. #26 :
  786. reload;
  787. #10,
  788. #13 :
  789. linebreak;
  790. end;
  791. end;
  792. end;
  793. procedure tscannerfile.skipuntildirective;
  794. var
  795. found : longint;
  796. next_char_loaded : boolean;
  797. oldcommentstyle : tcommentstyle;
  798. begin
  799. found:=0;
  800. next_char_loaded:=false;
  801. oldcommentstyle:=aktcommentstyle;
  802. repeat
  803. case c of
  804. #26 :
  805. end_of_file;
  806. '{' :
  807. begin
  808. if not(m_nested_comment in aktmodeswitches) or
  809. (comment_level=0) then
  810. begin
  811. found:=1;
  812. aktcommentstyle:=comment_tp;
  813. end;
  814. inc_comment_level;
  815. end;
  816. '}' :
  817. begin
  818. dec_comment_level;
  819. found:=0;
  820. end;
  821. '$' :
  822. begin
  823. if found=1 then
  824. found:=2;
  825. end;
  826. '''' :
  827. if (m_tp in aktmodeswitches) or
  828. (m_delphi in aktmodeswitches) then
  829. begin
  830. repeat
  831. readchar;
  832. case c of
  833. #26 :
  834. end_of_file;
  835. newline :
  836. break;
  837. '''' :
  838. begin
  839. readchar;
  840. if c<>'''' then
  841. break;
  842. end;
  843. end;
  844. until false;
  845. end;
  846. '(' :
  847. begin
  848. readchar;
  849. if c='*' then
  850. begin
  851. readchar;
  852. if c='$' then
  853. begin
  854. found:=2;
  855. inc_comment_level;
  856. aktcommentstyle:=comment_oldtp;
  857. end
  858. else
  859. begin
  860. skipoldtpcomment;
  861. aktcommentstyle:=oldcommentstyle;
  862. end;
  863. end
  864. else
  865. next_char_loaded:=true;
  866. end;
  867. else
  868. found:=0;
  869. end;
  870. if next_char_loaded then
  871. next_char_loaded:=false
  872. else
  873. begin
  874. c:=inputpointer^;
  875. if c=#0 then
  876. reload
  877. else
  878. inc(longint(inputpointer));
  879. case c of
  880. #26 : reload;
  881. #10,
  882. #13 : linebreak;
  883. end;
  884. end;
  885. until (found=2);
  886. end;
  887. {****************************************************************************
  888. Include directive scanning/parsing
  889. ****************************************************************************}
  890. {$i scandir.inc}
  891. {****************************************************************************
  892. Comment Handling
  893. ****************************************************************************}
  894. procedure tscannerfile.skipcomment;
  895. begin
  896. aktcommentstyle:=comment_tp;
  897. readchar;
  898. inc_comment_level;
  899. { handle compiler switches }
  900. if (c='$') then
  901. handledirectives;
  902. { handle_switches can dec comment_level, }
  903. while (comment_level>0) do
  904. begin
  905. case c of
  906. '{' : inc_comment_level;
  907. '}' : dec_comment_level;
  908. #26 : end_of_file;
  909. end;
  910. c:=inputpointer^;
  911. if c=#0 then
  912. reload
  913. else
  914. inc(longint(inputpointer));
  915. case c of
  916. #26 : reload;
  917. #10,
  918. #13 : linebreak;
  919. end;
  920. end;
  921. aktcommentstyle:=comment_none;
  922. end;
  923. procedure tscannerfile.skipdelphicomment;
  924. begin
  925. aktcommentstyle:=comment_delphi;
  926. inc_comment_level;
  927. readchar;
  928. { this is currently not supported }
  929. if c='$' then
  930. Message(scan_e_wrong_styled_switch);
  931. { skip comment }
  932. while c<>newline do
  933. begin
  934. if c=#26 then
  935. end_of_file;
  936. readchar;
  937. end;
  938. dec_comment_level;
  939. aktcommentstyle:=comment_none;
  940. end;
  941. procedure tscannerfile.skipoldtpcomment;
  942. var
  943. found : longint;
  944. begin
  945. aktcommentstyle:=comment_oldtp;
  946. inc_comment_level;
  947. readchar;
  948. { this is currently not supported }
  949. if (c='$') then
  950. handledirectives;
  951. { skip comment }
  952. while (comment_level>0) do
  953. begin
  954. found:=0;
  955. repeat
  956. case c of
  957. #26 :
  958. end_of_file;
  959. '*' :
  960. begin
  961. if found=3 then
  962. found:=4
  963. else
  964. found:=1;
  965. end;
  966. ')' :
  967. begin
  968. if found in [1,4] then
  969. begin
  970. dec_comment_level;
  971. if comment_level=0 then
  972. found:=2
  973. else
  974. found:=0;
  975. end;
  976. end;
  977. '(' :
  978. begin
  979. if found=4 then
  980. inc_comment_level;
  981. found:=3;
  982. end;
  983. else
  984. begin
  985. if found=4 then
  986. inc_comment_level;
  987. found:=0;
  988. end;
  989. end;
  990. c:=inputpointer^;
  991. if c=#0 then
  992. reload
  993. else
  994. inc(longint(inputpointer));
  995. case c of
  996. #26 : reload;
  997. #10,
  998. #13 : linebreak;
  999. end;
  1000. until (found=2);
  1001. end;
  1002. aktcommentstyle:=comment_none;
  1003. end;
  1004. {****************************************************************************
  1005. Token Scanner
  1006. ****************************************************************************}
  1007. procedure tscannerfile.readtoken;
  1008. var
  1009. code : integer;
  1010. low,high,mid : longint;
  1011. m : longint;
  1012. mac : pmacrosym;
  1013. asciinr : string[6];
  1014. label
  1015. exit_label;
  1016. begin
  1017. { was there already a token read, then return that token }
  1018. if nexttoken<>NOTOKEN then
  1019. begin
  1020. token:=nexttoken;
  1021. nexttoken:=NOTOKEN;
  1022. goto exit_label;
  1023. end;
  1024. { Skip all spaces and comments }
  1025. repeat
  1026. case c of
  1027. '{' :
  1028. skipcomment;
  1029. ' ',#9..#13 :
  1030. begin
  1031. if parapreprocess then
  1032. begin
  1033. if c=#10 then
  1034. preprocfile^.eolfound:=true
  1035. else
  1036. preprocfile^.spacefound:=true;
  1037. end;
  1038. skipspace;
  1039. end
  1040. else
  1041. break;
  1042. end;
  1043. until false;
  1044. { Save current token position, for EOF its already loaded }
  1045. if c<>#26 then
  1046. gettokenpos;
  1047. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  1048. if c in ['A'..'Z','a'..'z','_'] then
  1049. begin
  1050. readstring;
  1051. token:=_ID;
  1052. idtoken:=_ID;
  1053. { keyword or any other known token,
  1054. pattern is always uppercased }
  1055. if (pattern[1]<>'_') and (length(pattern) in [2..tokenidlen]) then
  1056. begin
  1057. low:=ord(tokenidx^[length(pattern),pattern[1]].first);
  1058. high:=ord(tokenidx^[length(pattern),pattern[1]].last);
  1059. while low<high do
  1060. begin
  1061. mid:=(high+low+1) shr 1;
  1062. if pattern<tokeninfo^[ttoken(mid)].str then
  1063. high:=mid-1
  1064. else
  1065. low:=mid;
  1066. end;
  1067. if pattern=tokeninfo^[ttoken(high)].str then
  1068. begin
  1069. if tokeninfo^[ttoken(high)].keyword in aktmodeswitches then
  1070. if tokeninfo^[ttoken(high)].op=NOTOKEN then
  1071. token:=ttoken(high)
  1072. else
  1073. token:=tokeninfo^[ttoken(high)].op;
  1074. idtoken:=ttoken(high);
  1075. end;
  1076. end;
  1077. { Only process identifiers and not keywords }
  1078. if token=_ID then
  1079. begin
  1080. { this takes some time ... }
  1081. if (cs_support_macro in aktmoduleswitches) then
  1082. begin
  1083. mac:=pmacrosym(macros^.search(pattern));
  1084. if assigned(mac) and (assigned(mac^.buftext)) then
  1085. begin
  1086. insertmacro(pattern,mac^.buftext,mac^.buflen);
  1087. { handle empty macros }
  1088. if c=#0 then
  1089. begin
  1090. reload;
  1091. case c of
  1092. #26 : reload;
  1093. #10,
  1094. #13 : linebreak;
  1095. end;
  1096. end;
  1097. { play it again ... }
  1098. inc(yylexcount);
  1099. if yylexcount>16 then
  1100. Message(scan_w_macro_deep_ten);
  1101. readtoken;
  1102. { that's all folks }
  1103. dec(yylexcount);
  1104. exit;
  1105. end;
  1106. end;
  1107. end;
  1108. { return token }
  1109. goto exit_label;
  1110. end
  1111. else
  1112. begin
  1113. idtoken:=_NOID;
  1114. case c of
  1115. '$' :
  1116. begin
  1117. readnumber;
  1118. token:=_INTCONST;
  1119. goto exit_label;
  1120. end;
  1121. '%' :
  1122. begin
  1123. readnumber;
  1124. token:=_INTCONST;
  1125. goto exit_label;
  1126. end;
  1127. '0'..'9' :
  1128. begin
  1129. readnumber;
  1130. if (c in ['.','e','E']) then
  1131. begin
  1132. { first check for a . }
  1133. if c='.' then
  1134. begin
  1135. readchar;
  1136. { is it a .. from a range? }
  1137. case c of
  1138. '.' :
  1139. begin
  1140. readchar;
  1141. token:=_INTCONST;
  1142. nexttoken:=_POINTPOINT;
  1143. goto exit_label;
  1144. end;
  1145. ')' :
  1146. begin
  1147. readchar;
  1148. token:=_INTCONST;
  1149. nexttoken:=_RECKKLAMMER;
  1150. goto exit_label;
  1151. end;
  1152. end;
  1153. { insert the number after the . }
  1154. pattern:=pattern+'.';
  1155. while c in ['0'..'9'] do
  1156. begin
  1157. pattern:=pattern+c;
  1158. readchar;
  1159. end;
  1160. end;
  1161. { E can also follow after a point is scanned }
  1162. if c in ['e','E'] then
  1163. begin
  1164. pattern:=pattern+'E';
  1165. readchar;
  1166. if c in ['-','+'] then
  1167. begin
  1168. pattern:=pattern+c;
  1169. readchar;
  1170. end;
  1171. if not(c in ['0'..'9']) then
  1172. Message(scan_f_illegal_char);
  1173. while c in ['0'..'9'] do
  1174. begin
  1175. pattern:=pattern+c;
  1176. readchar;
  1177. end;
  1178. end;
  1179. token:=_REALNUMBER;
  1180. goto exit_label;
  1181. end;
  1182. token:=_INTCONST;
  1183. goto exit_label;
  1184. end;
  1185. ';' :
  1186. begin
  1187. readchar;
  1188. token:=_SEMICOLON;
  1189. goto exit_label;
  1190. end;
  1191. '[' :
  1192. begin
  1193. readchar;
  1194. token:=_LECKKLAMMER;
  1195. goto exit_label;
  1196. end;
  1197. ']' :
  1198. begin
  1199. readchar;
  1200. token:=_RECKKLAMMER;
  1201. goto exit_label;
  1202. end;
  1203. '(' :
  1204. begin
  1205. readchar;
  1206. case c of
  1207. '*' :
  1208. begin
  1209. skipoldtpcomment;
  1210. readtoken;
  1211. exit;
  1212. end;
  1213. '.' :
  1214. begin
  1215. readchar;
  1216. token:=_LECKKLAMMER;
  1217. goto exit_label;
  1218. end;
  1219. end;
  1220. token:=_LKLAMMER;
  1221. goto exit_label;
  1222. end;
  1223. ')' :
  1224. begin
  1225. readchar;
  1226. token:=_RKLAMMER;
  1227. goto exit_label;
  1228. end;
  1229. '+' :
  1230. begin
  1231. readchar;
  1232. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1233. begin
  1234. readchar;
  1235. token:=_PLUSASN;
  1236. goto exit_label;
  1237. end;
  1238. token:=_PLUS;
  1239. goto exit_label;
  1240. end;
  1241. '-' :
  1242. begin
  1243. readchar;
  1244. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1245. begin
  1246. readchar;
  1247. token:=_MINUSASN;
  1248. goto exit_label;
  1249. end;
  1250. token:=_MINUS;
  1251. goto exit_label;
  1252. end;
  1253. ':' :
  1254. begin
  1255. readchar;
  1256. if c='=' then
  1257. begin
  1258. readchar;
  1259. token:=_ASSIGNMENT;
  1260. goto exit_label;
  1261. end;
  1262. token:=_COLON;
  1263. goto exit_label;
  1264. end;
  1265. '*' :
  1266. begin
  1267. readchar;
  1268. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1269. begin
  1270. readchar;
  1271. token:=_STARASN;
  1272. end
  1273. else
  1274. if c='*' then
  1275. begin
  1276. readchar;
  1277. token:=_STARSTAR;
  1278. end
  1279. else
  1280. token:=_STAR;
  1281. goto exit_label;
  1282. end;
  1283. '/' :
  1284. begin
  1285. readchar;
  1286. case c of
  1287. '=' :
  1288. begin
  1289. if (cs_support_c_operators in aktmoduleswitches) then
  1290. begin
  1291. readchar;
  1292. token:=_SLASHASN;
  1293. goto exit_label;
  1294. end;
  1295. end;
  1296. '/' :
  1297. begin
  1298. skipdelphicomment;
  1299. readtoken;
  1300. exit;
  1301. end;
  1302. end;
  1303. token:=_SLASH;
  1304. goto exit_label;
  1305. end;
  1306. '=' :
  1307. begin
  1308. readchar;
  1309. token:=_EQUAL;
  1310. goto exit_label;
  1311. end;
  1312. '.' :
  1313. begin
  1314. readchar;
  1315. case c of
  1316. '.' :
  1317. begin
  1318. readchar;
  1319. token:=_POINTPOINT;
  1320. goto exit_label;
  1321. end;
  1322. ')' :
  1323. begin
  1324. readchar;
  1325. token:=_RECKKLAMMER;
  1326. goto exit_label;
  1327. end;
  1328. end;
  1329. token:=_POINT;
  1330. goto exit_label;
  1331. end;
  1332. '@' :
  1333. begin
  1334. readchar;
  1335. if c='@' then
  1336. begin
  1337. readchar;
  1338. token:=_DOUBLEADDR;
  1339. end
  1340. else
  1341. token:=_KLAMMERAFFE;
  1342. goto exit_label;
  1343. end;
  1344. ',' :
  1345. begin
  1346. readchar;
  1347. token:=_COMMA;
  1348. goto exit_label;
  1349. end;
  1350. '''','#','^' :
  1351. begin
  1352. if c='^' then
  1353. begin
  1354. readchar;
  1355. c:=upcase(c);
  1356. if (block_type=bt_type) or
  1357. (lasttoken=_ID) or
  1358. (lasttoken=_RKLAMMER) or (lasttoken=_RECKKLAMMER) or (lasttoken=_CARET) then
  1359. begin
  1360. token:=_CARET;
  1361. goto exit_label;
  1362. end
  1363. else
  1364. begin
  1365. if c<#64 then
  1366. pattern:=chr(ord(c)+64)
  1367. else
  1368. pattern:=chr(ord(c)-64);
  1369. readchar;
  1370. end;
  1371. end
  1372. else
  1373. pattern:='';
  1374. repeat
  1375. case c of
  1376. '#' :
  1377. begin
  1378. readchar; { read # }
  1379. if c='$' then
  1380. begin
  1381. readchar; { read leading $ }
  1382. asciinr:='$';
  1383. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<6) do
  1384. begin
  1385. asciinr:=asciinr+c;
  1386. readchar;
  1387. end;
  1388. end
  1389. else
  1390. begin
  1391. asciinr:='';
  1392. while (c in ['0'..'9']) and (length(asciinr)<6) do
  1393. begin
  1394. asciinr:=asciinr+c;
  1395. readchar;
  1396. end;
  1397. end;
  1398. valint(asciinr,m,code);
  1399. if (asciinr='') or (code<>0) or
  1400. (m<0) or (m>255) then
  1401. Message(scan_e_illegal_char_const);
  1402. pattern:=pattern+chr(m);
  1403. end;
  1404. '''' :
  1405. begin
  1406. repeat
  1407. readchar;
  1408. case c of
  1409. #26 :
  1410. end_of_file;
  1411. newline :
  1412. Message(scan_f_string_exceeds_line);
  1413. '''' :
  1414. begin
  1415. readchar;
  1416. if c<>'''' then
  1417. break;
  1418. end;
  1419. end;
  1420. pattern:=pattern+c;
  1421. until false;
  1422. end;
  1423. '^' :
  1424. begin
  1425. readchar;
  1426. if c<#64 then
  1427. c:=chr(ord(c)+64)
  1428. else
  1429. c:=chr(ord(c)-64);
  1430. pattern:=pattern+c;
  1431. readchar;
  1432. end;
  1433. else
  1434. break;
  1435. end;
  1436. until false;
  1437. { strings with length 1 become const chars }
  1438. if length(pattern)=1 then
  1439. token:=_CCHAR
  1440. else
  1441. token:=_CSTRING;
  1442. goto exit_label;
  1443. end;
  1444. '>' :
  1445. begin
  1446. readchar;
  1447. case c of
  1448. '=' :
  1449. begin
  1450. readchar;
  1451. token:=_GTE;
  1452. goto exit_label;
  1453. end;
  1454. '>' :
  1455. begin
  1456. readchar;
  1457. token:=_OP_SHR;
  1458. goto exit_label;
  1459. end;
  1460. '<' :
  1461. begin { >< is for a symetric diff for sets }
  1462. readchar;
  1463. token:=_SYMDIF;
  1464. goto exit_label;
  1465. end;
  1466. end;
  1467. token:=_GT;
  1468. goto exit_label;
  1469. end;
  1470. '<' :
  1471. begin
  1472. readchar;
  1473. case c of
  1474. '>' :
  1475. begin
  1476. readchar;
  1477. token:=_UNEQUAL;
  1478. goto exit_label;
  1479. end;
  1480. '=' :
  1481. begin
  1482. readchar;
  1483. token:=_LTE;
  1484. goto exit_label;
  1485. end;
  1486. '<' :
  1487. begin
  1488. readchar;
  1489. token:=_OP_SHL;
  1490. goto exit_label;
  1491. end;
  1492. end;
  1493. token:=_LT;
  1494. goto exit_label;
  1495. end;
  1496. #26 :
  1497. begin
  1498. token:=_EOF;
  1499. checkpreprocstack;
  1500. goto exit_label;
  1501. end;
  1502. else
  1503. begin
  1504. Message(scan_f_illegal_char);
  1505. end;
  1506. end;
  1507. end;
  1508. exit_label:
  1509. lasttoken:=token;
  1510. end;
  1511. function tscannerfile.readpreproc:ttoken;
  1512. begin
  1513. skipspace;
  1514. case c of
  1515. 'A'..'Z',
  1516. 'a'..'z',
  1517. '_','0'..'9' : begin
  1518. preprocpat:=readid;
  1519. readpreproc:=_ID;
  1520. end;
  1521. '(' : begin
  1522. readchar;
  1523. readpreproc:=_LKLAMMER;
  1524. end;
  1525. ')' : begin
  1526. readchar;
  1527. readpreproc:=_RKLAMMER;
  1528. end;
  1529. '+' : begin
  1530. readchar;
  1531. readpreproc:=_PLUS;
  1532. end;
  1533. '-' : begin
  1534. readchar;
  1535. readpreproc:=_MINUS;
  1536. end;
  1537. '*' : begin
  1538. readchar;
  1539. readpreproc:=_STAR;
  1540. end;
  1541. '/' : begin
  1542. readchar;
  1543. readpreproc:=_SLASH;
  1544. end;
  1545. '=' : begin
  1546. readchar;
  1547. readpreproc:=_EQUAL;
  1548. end;
  1549. '>' : begin
  1550. readchar;
  1551. if c='=' then
  1552. begin
  1553. readchar;
  1554. readpreproc:=_GTE;
  1555. end
  1556. else
  1557. readpreproc:=_GT;
  1558. end;
  1559. '<' : begin
  1560. readchar;
  1561. case c of
  1562. '>' : begin
  1563. readchar;
  1564. readpreproc:=_UNEQUAL;
  1565. end;
  1566. '=' : begin
  1567. readchar;
  1568. readpreproc:=_LTE;
  1569. end;
  1570. else readpreproc:=_LT;
  1571. end;
  1572. end;
  1573. #26 :
  1574. end_of_file;
  1575. else
  1576. begin
  1577. readpreproc:=_EOF;
  1578. checkpreprocstack;
  1579. end;
  1580. end;
  1581. end;
  1582. function tscannerfile.asmgetchar : char;
  1583. begin
  1584. if lastasmgetchar<>#0 then
  1585. begin
  1586. c:=lastasmgetchar;
  1587. lastasmgetchar:=#0;
  1588. end
  1589. else
  1590. readchar;
  1591. case c of
  1592. '{' : begin
  1593. skipcomment;
  1594. asmgetchar:=c;
  1595. exit;
  1596. end;
  1597. '/' : begin
  1598. readchar;
  1599. if c='/' then
  1600. begin
  1601. skipdelphicomment;
  1602. asmgetchar:=c;
  1603. end
  1604. else
  1605. begin
  1606. asmgetchar:='/';
  1607. lastasmgetchar:=c;
  1608. end;
  1609. exit;
  1610. end;
  1611. '(' : begin
  1612. readchar;
  1613. if c='*' then
  1614. begin
  1615. skipoldtpcomment;
  1616. asmgetchar:=c;
  1617. end
  1618. else
  1619. begin
  1620. asmgetchar:='(';
  1621. lastasmgetchar:=c;
  1622. end;
  1623. exit;
  1624. end;
  1625. else
  1626. begin
  1627. asmgetchar:=c;
  1628. end;
  1629. end;
  1630. end;
  1631. end.
  1632. {
  1633. $Log$
  1634. Revision 1.103 2000-01-07 01:14:38 peter
  1635. * updated copyright to 2000
  1636. Revision 1.102 1999/12/02 17:34:34 peter
  1637. * preprocessor support. But it fails on the caret in type blocks
  1638. Revision 1.101 1999/11/15 17:52:59 pierre
  1639. + one field added for ttoken record for operator
  1640. linking the id to the corresponding operator token that
  1641. can now now all be overloaded
  1642. * overloaded operators are resetted to nil in InitSymtable
  1643. (bug when trying to compile a uint that overloads operators twice)
  1644. Revision 1.100 1999/11/06 14:34:26 peter
  1645. * truncated log to 20 revs
  1646. Revision 1.99 1999/11/03 23:44:28 peter
  1647. * fixed comment level counting after directive
  1648. Revision 1.98 1999/11/02 15:05:08 peter
  1649. * fixed oldtp comment parsing
  1650. Revision 1.97 1999/10/30 12:32:30 peter
  1651. * fixed line counter when the first line had #10 only. This was buggy
  1652. for both the main file as for include files
  1653. Revision 1.96 1999/09/27 23:40:10 peter
  1654. * fixed macro within macro endless-loop
  1655. Revision 1.95 1999/09/03 10:02:48 peter
  1656. * $IFNDEF is 7 chars and not 6 chars
  1657. Revision 1.94 1999/09/02 18:47:47 daniel
  1658. * Could not compile with TP, some arrays moved to heap
  1659. * NOAG386BIN default for TP
  1660. * AG386* files were not compatible with TP, fixed.
  1661. Revision 1.93 1999/08/30 10:17:58 peter
  1662. * fixed crash in psub
  1663. * ansistringcompare fixed
  1664. * support for #$0b8
  1665. Revision 1.92 1999/08/06 13:11:44 michael
  1666. * Removed C style comments.
  1667. Revision 1.91 1999/08/05 16:53:11 peter
  1668. * V_Fatal=1, all other V_ are also increased
  1669. * Check for local procedure when assigning procvar
  1670. * fixed comment parsing because directives
  1671. * oldtp mode directives better supported
  1672. * added some messages to errore.msg
  1673. Revision 1.90 1999/08/04 13:03:05 jonas
  1674. * all tokens now start with an underscore
  1675. * PowerPC compiles!!
  1676. Revision 1.89 1999/07/29 11:43:22 peter
  1677. * always output preprocstack when unexpected eof is found
  1678. * fixed tp7/delphi skipuntildirective parsing
  1679. Revision 1.88 1999/07/24 11:20:59 peter
  1680. * directives are allowed in (* *)
  1681. * fixed parsing of (* between conditional code
  1682. Revision 1.87 1999/07/18 10:20:02 florian
  1683. * made it compilable with Dlephi 4 again
  1684. + fixed problem with large stack allocations on win32
  1685. Revision 1.86 1999/06/02 22:44:19 pierre
  1686. * previous wrong log corrected
  1687. Revision 1.85 1999/06/02 22:25:49 pierre
  1688. * changed $ifdef FPC @ into $ifndef TP
  1689. Revision 1.84 1999/05/31 23:28:42 pierre
  1690. * problem with main file end without newline
  1691. Revision 1.83 1999/05/20 14:57:29 peter
  1692. * fixed line counting with macro's
  1693. Revision 1.82 1999/05/04 21:45:04 florian
  1694. * changes to compile it with Delphi 4.0
  1695. Revision 1.81 1999/04/07 14:36:44 pierre
  1696. + better preproc stack checking and report
  1697. Revision 1.80 1999/04/06 11:20:59 peter
  1698. * more hashing for keyword table
  1699. }