testunit1.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. //This is only for testing the parser, it is not intended to be runable in a real
  2. //program but for checking the contructs to be parsed well.
  3. //All statements are written like testparser would print them out to diff the
  4. //result with this file again to show differences.
  5. //Based on /utils/fpdoc/testunit.pp
  6. {$mode objfpc}
  7. {$h+}
  8. unit testunit1;
  9. interface
  10. uses
  11. SysUtils,Classes;
  12. resourcestring
  13. SParserErrorAtToken = 'parser error at token';
  14. const
  15. AnIntegerConst=1;
  16. AStringConst='Hello, World!';
  17. AFLoatconst=1.23;
  18. ABooleanConst=True;
  19. ATypedConst: Integer=3;
  20. AnArrayConst: Array[1..3] of Integer=(1,2,3);
  21. ARecordConst: TMethod=(Code:nil;Data:nil);
  22. ASetConst=[true,false];
  23. ADeprecatedConst=1 deprecated;
  24. ADeprecatedConst2 = 2 deprecated 'use another const';
  25. Type
  26. TLineEndStr = string [3];
  27. TDeprecatedType = Integer deprecated;
  28. TDeprecatedRecord = Record
  29. x,Y : Integer;
  30. end deprecated;
  31. TDeprecatedFieldsRecord = Record
  32. x,Y : Integer deprecated;
  33. end;
  34. TDeprecatedFieldsRecord2 = Record
  35. x,Y : Integer deprecated
  36. end;
  37. TAnEnumType=(one,two,three);
  38. arangetypealias = type 0..$FF;
  39. TASetType=set of TAnEnumType;
  40. TIntegerSet = Set of 0..SizeOf(Integer)*8-1;
  41. TAnArrayType=Array[1..10] of Integer;
  42. TASubRangeType=one..two;
  43. TABooleanArrayType=Array[Boolean] of Integer;
  44. TDay = (monday,tuesday,wednesday,thursday,friday,saturday,sunday);
  45. TShortDay = (mon,tue,wed,thu,fri,sat,sun);
  46. TShortDays = set of TShortDay;
  47. TDays = set of TDay;
  48. TMyInteger = Integer;
  49. ADouble = type double;
  50. TARecordType=record
  51. X,Y: Integer;
  52. Z: String;
  53. end;
  54. TAVariantRecordType=record
  55. A: String;
  56. Case Integer of
  57. 1: (X,Y : Integer);
  58. 2: (phi,Omega : Real);
  59. end;
  60. TAVariantRecordType2=record
  61. A: String;
  62. Case Atype : Integer of
  63. 1 : (X,Y : Integer);
  64. 2 : (phi,Omega : Real);
  65. end;
  66. MyRec = Record
  67. X : Longint;
  68. Case byte of
  69. 2 : (Y : Longint;
  70. case byte of
  71. 3 : (Z : Longint);
  72. );
  73. end;
  74. TYPE
  75. PPoint = ^TPoint;
  76. TPoint = OBJECT
  77. X, Y: Sw_Integer;
  78. END;
  79. PRect = ^TRect;
  80. TRect = OBJECT
  81. A, B: TPoint; { Corner points }
  82. FUNCTION Empty: Boolean;
  83. FUNCTION Equals (R: TRect): Boolean;
  84. FUNCTION Contains (P: TPoint): Boolean;
  85. PROCEDURE Copy (R: TRect);
  86. PROCEDURE Union (R: TRect);
  87. PROCEDURE Intersect (R: TRect);
  88. PROCEDURE Move (ADX, ADY: Sw_Integer);
  89. PROCEDURE Grow (ADX, ADY: Sw_Integer);
  90. PROCEDURE Assign (XA, YA, XB, YB: Sw_Integer);
  91. END;
  92. TNotifyEvent = Procedure (Sender : TObject) of object;
  93. TNestedProcedure = Procedure (Sender : TObject) is nested;
  94. TNotifyEvent2 = Function (Sender : TObject) : Integer of object;
  95. // TADeprecatedType = Integer deprecated;
  96. TMyChildClass = Class;
  97. MyInterface = Interface;
  98. { TMyParentClass }
  99. TMyParentClass=Class(TComponent)
  100. Private
  101. FI: Integer;
  102. Function GetA(AIndex: Integer): String;
  103. Function GetIP(AIndex: integer): String;
  104. procedure SetA(AIndex: Integer; const AValue: String);
  105. procedure SetIP(AIndex: integer; const AValue: String);
  106. Procedure WriteI(AI: Integer);
  107. Function ReadI: Integer;
  108. Protected
  109. Procedure AProtectedMethod;
  110. Property AProtectedProp: Integer Read FI Write FI;
  111. Public
  112. Constructor Create(AOwner: TComponent); override;
  113. Destructor Destroy; override;
  114. Procedure AVirtualProc; virtual;
  115. Procedure AnAbstractProc; virtual; abstract;
  116. Procedure AMessageProc(var Msg);message 123;
  117. Procedure AStringMessageProc(var Msg);message '123';
  118. Procedure ADeprecatedProc; deprecated;
  119. Procedure APlatformProc; Platform;
  120. Property IntProp: Integer Read FI Write Fi;
  121. Property IntROProp: Integer Read FI;
  122. Property GetIntProp: Integer Read ReadI Write WriteI;
  123. Property AnArrayProp[AIndex: Integer]: String Read GetA Write SetA;
  124. Property AnIndexProp: String Index 1 Read GetIP Write SetIP;
  125. Property AnIndexProp2: String Index 2 Read GetIP Write SetIP;
  126. Published
  127. Procedure SomePublishedMethod;
  128. end;
  129. { TMyChildClass }
  130. TMyChildClass=Class(TMyParentClass)
  131. Public
  132. Procedure AVirtualProc; Override;
  133. Procedure AnAbstractProc; Override;
  134. Published
  135. Property AProtectedProp;
  136. end;
  137. TC = TMyChildClass;
  138. TPasFunctionType=Class(TObject)
  139. public
  140. destructor Destroy; override;
  141. Class Function TypeName: string;
  142. Function ElementTypeName: string;
  143. Function GetDeclaration(Full: boolean): string;
  144. Procedure Something; strict
  145. Private
  146. Procedure SomethingElse;
  147. public
  148. ResultEl: TObject;
  149. end;
  150. TPropModifiers = Class(TObject)
  151. Private
  152. FB : Integer;
  153. Function IsStored : Boolean;
  154. Function GetI(AI : Integer) : Integer;
  155. Procedure SetI(AI : Integer; AVal : Integer);
  156. Published
  157. Property A : Integer Read FB Write FB Stored False;
  158. Property B : Integer Read FB Write FB Stored True;
  159. Property C : Integer Read FB Write FB Stored IsStored;
  160. Property D : Integer Read FB Write FB Default 1;
  161. Property E : Integer Read FB Write FB Stored True Default 1;
  162. Public
  163. Property Ints[AI : Integer] : Integer Read GetI Write SetI; default;
  164. end;
  165. TPropModifiers2 = class(TPropModifiers)
  166. Public
  167. Property Ints[AI : Integer] : Integer Read GetI Write SetI; default; deprecated;
  168. end;
  169. TEdit = Class(TObject)
  170. Text : String;
  171. end;
  172. var
  173. ASimpleVar: Integer;
  174. ATypedVar: TMethod;
  175. ARecordVar: Record
  176. A,B: Integer;
  177. end;
  178. AnArrayVar: Array[1..10] of Integer;
  179. ATypedArray: Array[TanEnumType] of Integer;
  180. AInitVar: Integer=1;
  181. ADeprecatedVar: Integer deprecated;
  182. ACVarVar: Integer ; cvar;
  183. AnExternalVar1: Integer; external;
  184. AnExternalVar2: Integer; external name 'avar';
  185. AnExternalLibVar: Integer; external 'library' name 'avar';
  186. APublicVar : String; public;
  187. APublicVar2 : String; public name 'ANAME';
  188. APublicVar3 : String; export;
  189. APublicVar4 : String; export name 'nono';
  190. APublicVar5 : String; cvar; external;
  191. APublicVar6 : String; external name 'me';
  192. APublicVar7 : String deprecated; external name 'me';
  193. Procedure SimpleProc;
  194. Procedure OverloadedProc(A: Integer);
  195. Procedure OverloadedProc(B: String);
  196. Function SimpleFunc: Integer;
  197. Function OverloadedFunc(A: Integer): Integer;
  198. Function OverloadedFunc(B: String): Integer;
  199. Procedure ConstArgProc(const A: Integer);
  200. Procedure VarArgProc(var A: Integer);
  201. Procedure OutArgProc(out A: Integer);
  202. Procedure UntypedVarArgProc(var A);
  203. Procedure UntypedConstArgProc(const A);
  204. Procedure UntypedOutArgProc(out A);
  205. Procedure ArrayArgProc(A: TAnArrayType);
  206. Procedure OpenArrayArgProc(A: Array of string);
  207. Procedure ConstArrayArgProc(A: Array of const);
  208. Procedure externalproc; external;
  209. Procedure externalnameProc; external name 'aname';
  210. Procedure externallibnameProc; external 'alibrary' name 'aname';
  211. Function hi(q : QWord) : DWord; [INTERNPROC: fpc_in_hi_qword];
  212. {$define extdecl:=cdecl}
  213. Type
  214. FontEnumProc = function (var ELogFont:TEnumLogFont; var Metric:TNewTextMetric;
  215. FontType:longint; Data:LParam):longint; extdecl;
  216. Type
  217. generic TFPGListEnumerator<T> = class(TObject)
  218. protected
  219. FList: TFPList;
  220. FPosition: Integer;
  221. function GetCurrent: T;
  222. end;
  223. TFPGListEnumeratorSpec = specialize TFPGListEnumerator<TPasFunctionType>;
  224. Implementation
  225. Procedure SimpleProc;
  226. procedure SubProc;
  227. Var S : String;
  228. begin
  229. s:= s+'a';
  230. end;
  231. Var
  232. a,B,c,i : integer;
  233. begin
  234. a:= 1;
  235. c:= a+b;
  236. for i:= 1 to 10 do
  237. write(a);
  238. end;
  239. Procedure OverloadedProc(A: Integer);
  240. Var
  241. i : integer;
  242. begin
  243. if i=1 then ;
  244. end;
  245. Procedure OverloadedProc(B: String);
  246. begin
  247. end;
  248. Function SimpleFunc: Integer;
  249. begin
  250. end;
  251. Function OverloadedFunc(A: Integer): Integer;
  252. begin
  253. end;
  254. Function OverloadedFunc(B: String): Integer;
  255. begin
  256. end;
  257. Procedure ArrayArgProc(A: TAnArrayType);
  258. begin
  259. end;
  260. Procedure OpenArrayArgProc(A: Array of String);
  261. begin
  262. end;
  263. Procedure ConstArrayArgProc(A: Array of const);
  264. begin
  265. end;
  266. Procedure ConstArgProc(const A: Integer);
  267. begin
  268. end;
  269. Procedure VarArgProc(var A: Integer);
  270. begin
  271. end;
  272. Procedure OutArgProc(out A: Integer);
  273. begin
  274. end;
  275. Procedure UntypedVarArgProc(var A);
  276. begin
  277. end;
  278. Procedure UntypedConstArgProc(const A);
  279. begin
  280. end;
  281. Procedure UntypedOutArgProc(out A);
  282. begin
  283. end;
  284. { TMyChildClass }
  285. procedure TMyChildClass.AVirtualProc;
  286. begin
  287. inherited AVirtualProc;
  288. end;
  289. procedure TMyChildClass.AnAbstractProc;
  290. procedure SubCProc;
  291. Var sc : string;
  292. begin
  293. sc:= sc+'ac';
  294. end;
  295. begin
  296. // Cannot call ancestor
  297. end;
  298. { TMyParentClass }
  299. procedure TMyParentClass.WriteI(AI: Integer);
  300. begin
  301. end;
  302. Function TMyParentClass.GetA(AIndex: Integer): String;
  303. begin
  304. end;
  305. Function TMyParentClass.GetIP(AIndex: integer): String;
  306. begin
  307. end;
  308. procedure TMyParentClass.SetA(AIndex: Integer; const AValue: String);
  309. begin
  310. end;
  311. procedure TMyParentClass.SetIP(AIndex: integer; const AValue: String);
  312. begin
  313. end;
  314. Function TMyParentClass.ReadI: Integer;
  315. begin
  316. end;
  317. procedure TMyParentClass.AProtectedMethod;
  318. begin
  319. end;
  320. constructor TMyParentClass.Create(AOwner: TComponent);
  321. begin
  322. inherited Create(AOwner);
  323. end;
  324. destructor TMyParentClass.Destroy;
  325. begin
  326. inherited Destroy;
  327. end;
  328. procedure TMyParentClass.AVirtualProc;
  329. begin
  330. end;
  331. procedure TMyParentClass.AMessageProc(var Msg);
  332. begin
  333. end;
  334. procedure TMyParentClass.AStringMessageProc(var Msg);
  335. begin
  336. end;
  337. procedure TMyParentClass.ADeprecatedProc;
  338. begin
  339. end;
  340. procedure TMyParentClass.APlatformProc;
  341. begin
  342. end;
  343. procedure TMyParentClass.SomePublishedMethod;
  344. begin
  345. end;
  346. Class Function TPasFunctionType.TypeName: String;
  347. begin
  348. Result:= 'Function';
  349. end;
  350. Type
  351. TI = Class(TComponent)
  352. Public
  353. FP : Integer;
  354. Procedure SetP1(A : Integer); virtual;
  355. Procedure M1;virtual;
  356. Function F1 : Integer; virtual;
  357. procedure test; virtual;
  358. property P : Integer Read FP Write SetP1;
  359. end;
  360. Procedure TI.M1;
  361. begin
  362. end;
  363. Procedure TI.Test;
  364. begin
  365. end;
  366. Function TI.F1 : Integer;
  367. begin
  368. Result:=0;
  369. end;
  370. Procedure TI.SetP1(A : Integer);
  371. begin
  372. FP:=A;
  373. end;
  374. TYpe
  375. TI2 = Class(TI)
  376. procedure write(s : string);
  377. Procedure SetP1(A : Integer); override;
  378. Procedure M1;override;
  379. Procedure Test;override;
  380. Function F1 : integer; override;
  381. procedure donothing;
  382. property P : Integer Read F1 Write SetP1;
  383. end;
  384. Procedure TI2.M1;
  385. begin
  386. Inherited;
  387. end;
  388. Procedure TI2.Write(s : string);
  389. begin
  390. writeln(s);
  391. end;
  392. Function TI2.F1 :Integer;
  393. begin
  394. Result:=0;
  395. end;
  396. Procedure TI2.Test;
  397. begin
  398. if true then
  399. Inherited Test
  400. else
  401. DoNothing;
  402. Inherited test;
  403. if true then
  404. Inherited
  405. else
  406. DoNothing;
  407. end;
  408. Procedure TI2.DoNothing;
  409. function escapetext(s : string) : string;
  410. begin
  411. end;
  412. var
  413. Atext : string;
  414. begin
  415. Self.Write(EscapeText(AText));
  416. TComponent.Create(Self);
  417. end;
  418. Procedure TI2.SetP1(A : Integer);
  419. begin
  420. FP:=A;
  421. Inherited P:= 3;
  422. Inherited SetP1(3);
  423. Inherited P:= Ord(A);
  424. end;
  425. procedure usage;
  426. begin
  427. end;
  428. Procedure DoSomething;
  429. begin
  430. end;
  431. Procedure DoSomethingElse;
  432. begin
  433. end;
  434. procedure stat1;
  435. begin
  436. end;
  437. procedure stat2;
  438. begin
  439. end;
  440. procedure stat3;
  441. begin
  442. end;
  443. procedure stat4;
  444. begin
  445. end;
  446. procedure stat5;
  447. begin
  448. end;
  449. procedure stat6;
  450. begin
  451. end;
  452. procedure stat7;
  453. begin
  454. end;
  455. procedure stat8;
  456. begin
  457. end;
  458. procedure stat9;
  459. begin
  460. end;
  461. procedure doit;
  462. begin
  463. end;
  464. procedure statement;
  465. begin
  466. end;
  467. procedure work;
  468. begin
  469. end;
  470. procedure kissdwarf(i : integer);
  471. begin
  472. writeln('kiss dwarf',i);
  473. end;
  474. procedure Statements;
  475. const
  476. cint=1;
  477. cint1=-1;
  478. creal=3.1415;
  479. Addi=1+2;
  480. Subs=2-3;
  481. Muti=3*3;
  482. Divi=3/5;
  483. //Powe=2^3;
  484. Modu=5 mod 3;
  485. IDiv=5 div 3;
  486. fals= not TRUE;
  487. cand=true and false;
  488. cor=true or false;
  489. cxor=true xor false;
  490. lt=2<3;
  491. gt=3>2;
  492. let=2<=3;
  493. get=3>=2;
  494. LeftShift=2 shl 3;
  495. RightShift=2 shr 3;
  496. ConstString='01'+'ab';
  497. Type
  498. Passenger=Record
  499. Name: String[30];
  500. Flight: String[10];
  501. end;
  502. Type
  503. AR=record
  504. X,Y: LongInt;
  505. end;
  506. TScanner = record
  507. currow,curcolumn : integer;
  508. curfilename : string;
  509. end;
  510. //PAR = Record;
  511. var
  512. msg,curtokenname : string;
  513. TheCustomer: Passenger;
  514. L: ^LongInt;
  515. P: PPChar;
  516. S,T: Ar;
  517. M, X,Y : Double;
  518. Done : Boolean;
  519. Weather,Good: Boolean;
  520. c : char;
  521. j,dwarfs,i,Number,Block : integer;
  522. exp1,exp2,exp3,exp4,exp5,exp6,exp7,exp8,exp9 : boolean;
  523. o : Tobject;
  524. day,today : tday;
  525. A,B,D : Passenger;
  526. E : Exception;
  527. scanner : tscanner;
  528. begin
  529. O:=Nil;
  530. X:= X+Y;
  531. //EparserError on C++ style
  532. //X+=Y; { Same as X := X+Y, needs -Sc command line switch}
  533. //x-=y;
  534. //X/=2; { Same as X := X/2, needs -Sc command line switch}
  535. //x*=y;
  536. Done:= False;
  537. Weather:= Good;
  538. //MyPi := 4* Tan(1); warum * ?
  539. L^:= 3;
  540. P^^:= 'A';
  541. Usage;
  542. WriteLn('Pascal is an easy language !');
  543. Doit();
  544. //label jumpto;
  545. //Jumpto :
  546. // Statement;
  547. //Goto jumpto;
  548. Case i of
  549. 6: DoSomething;
  550. 1..5: DoSomethingElse;
  551. end;
  552. Case C of
  553. 'a': WriteLn('A pressed');
  554. 'b': WriteLn('B pressed');
  555. 'c': WriteLn('C pressed');
  556. else
  557. WriteLn('unknown letter pressed : ',C);
  558. end;
  559. Case C of
  560. 'a','e','i','o','u': WriteLn('vowel pressed');
  561. 'y': WriteLn('This one depends on the language');
  562. else
  563. WriteLn('Consonant pressed');
  564. end;
  565. Case Number of
  566. 1..10: WriteLn('Small number');
  567. 11..100: WriteLn('Normal, medium number');
  568. else
  569. WriteLn('HUGE number');
  570. end;
  571. case block of
  572. 1: begin
  573. writeln('1');
  574. end;
  575. 2: writeln('2');
  576. else
  577. writeln('3');
  578. writeln('4');
  579. end;
  580. If exp1 Then
  581. If exp2 then
  582. Stat1
  583. else
  584. stat2;
  585. If exp3 Then
  586. begin
  587. If exp4 then
  588. Stat5
  589. else
  590. stat6
  591. end;
  592. If exp7 Then
  593. begin
  594. If exp8 then
  595. Stat9
  596. end
  597. else
  598. stat2;
  599. if o is TObject then
  600. begin
  601. write('object');
  602. end
  603. else
  604. if o is TMyParentClass then
  605. begin
  606. write('real');
  607. end
  608. else
  609. write('0');
  610. if Today in [Monday..Friday] then
  611. WriteLn('Must work harder')
  612. else
  613. WriteLn('Take a day off.');
  614. for Day:= Monday to Friday do
  615. Work;
  616. for I:= 100 downto 1 do
  617. WriteLn('Counting down : ',i);
  618. for I:= 1 to 7*dwarfs do
  619. KissDwarf(i);
  620. for i:= 0 to 10 do
  621. begin
  622. j:= 2+1;
  623. write(i,j);
  624. end;
  625. repeat
  626. WriteLn('I =',i);
  627. I:= I+2;
  628. until I>100;
  629. repeat
  630. X:= X/2;
  631. until x<10e-3;
  632. I:= I+2;
  633. while i<=100 do
  634. begin
  635. WriteLn('I =',i);
  636. I:= I+2;
  637. end;
  638. X:= X/2;
  639. while i>=10e-3 do
  640. dec(i);
  641. while i>0 do
  642. while j>0 do
  643. begin
  644. dec(i);
  645. dec(j);
  646. end;
  647. while i>0 do
  648. if i>2 then
  649. dec(i)
  650. else
  651. dec(i,2);
  652. X:= 2+3;
  653. TheCustomer.Name:= 'Michael';
  654. TheCustomer.Flight:= 'PS901';
  655. With TheCustomer do
  656. begin
  657. Name:= 'Michael';
  658. Flight:= 'PS901';
  659. end;
  660. With A,B,D do
  661. Statement;
  662. With A do
  663. With B do
  664. With D do
  665. Statement;
  666. S.X:= 1;S.Y:= 1;
  667. T.X:= 2;T.Y:= 2;
  668. With S,T do
  669. WriteLn(X,' ',Y);
  670. {asm
  671. Movl $1,%ebx
  672. Movl $0,%eax
  673. addl %eax,%ebx
  674. end; ['EAX','EBX'];}
  675. try
  676. try
  677. M:= Y;
  678. except
  679. on excep: EParserError do
  680. begin
  681. writeln(excep.message,' : ',excep.classname);
  682. raise ;
  683. end;
  684. end;
  685. FreeAndNil(M);
  686. finally
  687. FreeAndNil(E)
  688. end;
  689. raise EParserError.Create(Format(SParserErrorAtToken, [Msg, CurTokenName]) {$ifdef addlocation}+' ('+inttostr(scanner.currow)+' '+inttostr(scanner.curcolumn)+')'{$endif});
  690. // try else
  691. end;
  692. function addone : integer;
  693. begin
  694. end;
  695. procedure myproc;
  696. begin
  697. end;
  698. procedure Expression;
  699. Var
  700. A,b,c,d,e,f,i,j : Integer;
  701. x : double;
  702. u : Boolean;
  703. fu : function : integer;
  704. ad : boolean;
  705. z : tdays;
  706. today,tomorrow : tday;
  707. bs : set of byte;
  708. cs : set of char;
  709. cc : char;
  710. W : TShortDays;
  711. buffer : array[1..10] of byte;
  712. P : Pointer;
  713. SErrMultipleSourceFiles,FileName,Dirname,S : string;
  714. o,co : tobject;
  715. begin
  716. x:= a+b *c /(-e+f)*(3 div 2) + 4 mod 5 - 2 shl 3 + 3 shr 1 ;
  717. b:= (a and not b) or c xor d;
  718. u:= (i<=2) or (a<>b) or (j>=3);
  719. u:= (i=1) or (a>b) or (b<a) or (i<>2);
  720. u:= i in [1..2];
  721. If Fu=@AddOne Then
  722. WriteLn('Functions are equal');
  723. If Fu()=Addone then
  724. WriteLn('Functions return same values ');
  725. z:= [today,tomorrow];
  726. z:= [Monday..Friday,Sunday];
  727. bs:= [2,3*2,6*2,9*2];
  728. cs:= ['A'..'Z','a'..'z','0'..'9'];
  729. i:= Byte('A');
  730. cc:= Char(48);
  731. ad:= boolean(1);
  732. i:= longint(@Buffer);
  733. i:= Integer('A');
  734. cc:= Char(225);
  735. i:= Word(@Buffer);
  736. B:= Byte(C);
  737. S:= TObject(P).ClassName;
  738. P:= @MyProc; //warum @ ? fix pparser 769 ?
  739. Dirname:= Dirname+'\';
  740. W:= [mon,tue]+[wed,thu,fri]; // equals [mon,tue,wed,thu,fri]
  741. W:= [mon,tue,wed]-[wed]; // equals [mon,tue]
  742. W:= [mon,tue,wed]*[wed,thu,fri]; // equals [wed] warum * ?
  743. (Co as TEdit).Text:= 'Some text';
  744. Co:= O as TComponent;
  745. if co is TComponent then ;
  746. If co is TC then ;
  747. raise Exception.Create(SErrMultipleSourceFiles);
  748. if Filename<>'' then
  749. raise Exception.Create(SErrMultipleSourceFiles);
  750. if Filename<>'' then
  751. raise Exception.Create(SErrMultipleSourceFiles)
  752. else
  753. Filename:= s;
  754. end;
  755. constructor TPasPackage.Create(const AName: String; AParent: TPasElement);
  756. begin
  757. if (Length(AName)>0)and(AName[1]<>'#') then
  758. Inherited Create('#'+AName,AParent)
  759. else
  760. Inherited Create(AName,AParent);
  761. Modules:= TList.Create;
  762. end;
  763. Function TPascalScanner.FetchToken: TToken;
  764. var
  765. IncludeStackItem: TIncludeStackItem;
  766. begin
  767. while true do
  768. begin
  769. Result:= DoFetchToken;
  770. if FCurToken=tkEOF then
  771. if FIncludeStack.Count>0 then
  772. begin
  773. CurSourceFile.Free;
  774. IncludeStackItem:= TIncludeStackItem(FIncludeStack[FIncludeStack.Count-1]);
  775. FIncludeStack.Delete(FIncludeStack.Count-1);
  776. FCurSourceFile:= IncludeStackItem.SourceFile;
  777. FCurFilename:= IncludeStackItem.Filename;
  778. FCurToken:= IncludeStackItem.Token;
  779. FCurTokenString:= IncludeStackItem.TokenString;
  780. FCurLine:= IncludeStackItem.Line;
  781. FCurRow:= IncludeStackItem.Row;
  782. TokenStr:= IncludeStackItem.TokenStr;
  783. IncludeStackItem.Free;
  784. Result:= FCurToken;
  785. end
  786. else
  787. break
  788. else
  789. if not PPIsSkipping then
  790. break;
  791. end;
  792. end;
  793. Procedure IFS;
  794. begin
  795. if true then
  796. repeat
  797. until false
  798. else
  799. Noting;
  800. end;
  801. Procedure IFS(x: integer); overload;
  802. begin
  803. if true then
  804. case x of
  805. 1: writeln;
  806. 2: write;
  807. else
  808. writeln('#');
  809. end
  810. else
  811. Noting;
  812. end;
  813. Procedure IFS1;
  814. begin
  815. if true then
  816. while true do
  817. Something
  818. else
  819. Noting;
  820. end;
  821. Procedure IFS3;
  822. begin
  823. if true then
  824. if true then
  825. write
  826. else
  827. writeln;
  828. end;
  829. Initialization
  830. hallo:= valid;
  831. end.