scanner.pas 53 KB

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