scanner.pas 51 KB

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