scanner.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  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.105 2000-02-09 13:23:03 peter
  1640. * log truncated
  1641. Revision 1.104 2000/01/30 19:28:25 peter
  1642. * fixed filepos when eof is read, it'll now stay on the eof position
  1643. Revision 1.103 2000/01/07 01:14:38 peter
  1644. * updated copyright to 2000
  1645. Revision 1.102 1999/12/02 17:34:34 peter
  1646. * preprocessor support. But it fails on the caret in type blocks
  1647. Revision 1.101 1999/11/15 17:52:59 pierre
  1648. + one field added for ttoken record for operator
  1649. linking the id to the corresponding operator token that
  1650. can now now all be overloaded
  1651. * overloaded operators are resetted to nil in InitSymtable
  1652. (bug when trying to compile a uint that overloads operators twice)
  1653. Revision 1.100 1999/11/06 14:34:26 peter
  1654. * truncated log to 20 revs
  1655. Revision 1.99 1999/11/03 23:44:28 peter
  1656. * fixed comment level counting after directive
  1657. Revision 1.98 1999/11/02 15:05:08 peter
  1658. * fixed oldtp comment parsing
  1659. Revision 1.97 1999/10/30 12:32:30 peter
  1660. * fixed line counter when the first line had #10 only. This was buggy
  1661. for both the main file as for include files
  1662. Revision 1.96 1999/09/27 23:40:10 peter
  1663. * fixed macro within macro endless-loop
  1664. Revision 1.95 1999/09/03 10:02:48 peter
  1665. * $IFNDEF is 7 chars and not 6 chars
  1666. Revision 1.94 1999/09/02 18:47:47 daniel
  1667. * Could not compile with TP, some arrays moved to heap
  1668. * NOAG386BIN default for TP
  1669. * AG386* files were not compatible with TP, fixed.
  1670. Revision 1.93 1999/08/30 10:17:58 peter
  1671. * fixed crash in psub
  1672. * ansistringcompare fixed
  1673. * support for #$0b8
  1674. Revision 1.92 1999/08/06 13:11:44 michael
  1675. * Removed C style comments.
  1676. Revision 1.91 1999/08/05 16:53:11 peter
  1677. * V_Fatal=1, all other V_ are also increased
  1678. * Check for local procedure when assigning procvar
  1679. * fixed comment parsing because directives
  1680. * oldtp mode directives better supported
  1681. * added some messages to errore.msg
  1682. Revision 1.90 1999/08/04 13:03:05 jonas
  1683. * all tokens now start with an underscore
  1684. * PowerPC compiles!!
  1685. Revision 1.89 1999/07/29 11:43:22 peter
  1686. * always output preprocstack when unexpected eof is found
  1687. * fixed tp7/delphi skipuntildirective parsing
  1688. Revision 1.88 1999/07/24 11:20:59 peter
  1689. * directives are allowed in (* *)
  1690. * fixed parsing of (* between conditional code
  1691. }