scanner.pas 53 KB

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