scanner.pas 51 KB

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