scanner.pas 51 KB

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