Changeset 72 for trunk/Compiler/Modules/Pascal/UAnalyzerPascal.pas
- Timestamp:
- Aug 1, 2012, 12:16:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Modules/Pascal/UAnalyzerPascal.pas
r70 r72 6 6 7 7 uses 8 Classes, SysUtils, UAnalyzer, USourceCode , Dialogs;8 Classes, SysUtils, UAnalyzer, USourceCodePascal, Dialogs, USourceConvertor; 9 9 10 10 type … … 12 12 { TAnalyzerPascal } 13 13 14 TAnalyzerPascal = class(T Analyzer)14 TAnalyzerPascal = class(TConvertor) 15 15 private 16 16 public 17 Parser: TAnalyzer; 17 18 function DebugExpressions(List: TListExpression): string; 18 19 function ParseFile(Name: string): Boolean; … … 29 30 function ParseUses(SourceCode: TUsedModuleList; AExported: Boolean): Boolean; 30 31 function ParseUsesItem(SourceCode: TUsedModuleList; AExported: Boolean): Boolean; 31 function ParseModule(ProgramCode: TProgram): TSourceModule; override;32 function ParseModule(ProgramCode: TProgram): TSourceModule; 32 33 function ParseUnit(var SourceCode: TModuleUnit; ProgramCode: TProgram): Boolean; 33 34 function ParseUnitInterface(SourceCode: TModuleUnit): Boolean; … … 63 64 constructor Create; 64 65 destructor Destroy; override; 66 procedure Convert(Input, Output: TSourceList); override; 65 67 end; 66 68 … … 108 110 NewModule: TSourceModule; 109 111 begin 110 try112 (* try 111 113 Parser := TAnalyzerPascal.Create; 112 114 Parser.OnDebugLog := OnDebugLog; … … 126 128 finally 127 129 Parser.Free; 128 end; 130 end; *) 129 131 end; 130 132 131 133 function TAnalyzerPascal.ParseWhileDo(var WhileDo: TWhileDo; SourceCode: TCommonBlock): Boolean; 132 134 begin 135 (* with Parser do 133 136 if NextToken = 'while' then begin 134 137 Expect('while'); … … 142 145 end; 143 146 Result := True; 144 end else Result := False; 147 end else Result := False;*) 145 148 end; 146 149 … … 153 156 II: Integer; 154 157 begin 158 (* with Parser do 155 159 try 156 160 Expressions := TListExpression.Create; … … 198 202 finally 199 203 Expressions.Free; 200 end; 204 end; *) 201 205 end; 202 206 … … 206 210 NewExpression: TExpression; 207 211 begin 208 if NextToken = '(' then begin212 (* if NextToken = '(' then begin 209 213 Expect('('); 210 214 // Subexpression … … 222 226 Expect(')'); 223 227 Result := True; 224 end else Result := False; 228 end else Result := False;*) 225 229 end; 226 230 … … 228 232 Expressions: TListExpression): Boolean; 229 233 begin 230 if IsOperator(NextToken) then begin234 (*if IsOperator(NextToken) then begin 231 235 // Operator 232 236 TExpression(Expressions.Last).OperatorName := ReadToken; 233 237 TExpression(Expressions.Last).NodeType := ntOperator; 234 238 Result := True; 235 end else Result := False; 239 end else Result := False; *) 236 240 end; 237 241 … … 249 253 begin 250 254 NewExpression := nil; 255 with Parser do 251 256 with SourceCode do begin 252 257 // if IsIdentificator(NextToken) then begin … … 367 372 begin 368 373 Func := nil; 369 with SourceCode do begin374 with Parser, SourceCode do begin 370 375 UseFunction := CommonBlock.Functions.Search(NextToken); 371 376 if Assigned(UseFunction) then begin … … 402 407 FunctionName: string; 403 408 begin 409 with PArser do 404 410 begin 405 411 if not ParseBeginEnd(TBeginEnd(Result), SourceCode) then … … 422 428 function TAnalyzerPascal.ParseModule(ProgramCode: TProgram): TSourceModule; 423 429 begin 424 Self.ProgramCode := ProgramCode;430 (* Output := TSource(ProgramCode); 425 431 if not ParseUnit(TModuleUnit(Result), ProgramCode) then 426 432 if not ParseProgram(TModuleProgram(Result), ProgramCode) then 427 ErrorMessage(SUnknownModuleType, [NextToken]); 433 ErrorMessage(SUnknownModuleType, [NextToken]);*) 428 434 end; 429 435 … … 432 438 Identifier: string; 433 439 begin 434 with SourceCode do begin440 with Parser, SourceCode do begin 435 441 SourceCode := TModuleProgram.Create; 436 442 SourceCode.ParentProgram := ProgramCode; … … 457 463 NewCommand: TCommand; 458 464 begin 465 with Parser do 459 466 if NextToken = 'unit' then begin 460 467 SourceCode := TModuleUnit.Create; … … 507 514 function TAnalyzerPascal.ParseUnitInterface(SourceCode: TModuleUnit): Boolean; 508 515 begin 516 with Parser do 509 517 if NextToken = 'interface' then begin 510 518 Expect('interface'); … … 519 527 function TAnalyzerPascal.ParseUnitImplementation(SourceCode: TModuleUnit): Boolean; 520 528 begin 529 with Parser do 521 530 if NextToken = 'implementation' then begin 522 531 Expect('implementation'); … … 539 548 NewType: TType; 540 549 begin 541 with SourceCode do begin550 with Parser, SourceCode do begin 542 551 while (NextToken <> EndSymbol) and (NextTokenType <> ttEndOfFile) do begin 543 552 if NextToken = 'var' then begin … … 591 600 begin 592 601 Log('ParseCommonBlockInterface'); 593 with SourceCode do begin602 with Parser, SourceCode do begin 594 603 while (NextToken <> 'implementation') and (NextTokenType <> ttEndOfFile) do begin 595 604 if NextToken = 'var' then begin … … 632 641 NewCommand: TCommand; 633 642 begin 643 with Parser do 634 644 if NextToken = 'begin' then begin 635 645 //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock))); … … 668 678 ValidParams: Boolean; 669 679 begin 680 with Parser do 670 681 if (NextToken = 'procedure') or (NextToken = 'function') then begin 671 682 with SourceCode do begin … … 779 790 I: Integer; 780 791 begin 781 with SourceCode do792 with Parser, SourceCode do 782 793 try 783 794 Identifiers := TStringList.Create; … … 837 848 function TAnalyzerPascal.ParseIfThenElse(var IfThenElse: TIfThenElse; SourceCode: TCommonBlock): Boolean; 838 849 begin 850 with Parser do 839 851 if NextToken = 'if' then begin 840 852 IfThenElse := TIfThenElse.Create; … … 860 872 VariableName: string; 861 873 begin 874 with Parser do 862 875 if NextToken = 'for' then begin 863 876 ForToDo := TForToDo.Create; … … 888 901 IdentName: string; 889 902 begin 903 with Parser do 890 904 if IsIdentificator(NextToken) then begin 891 905 Variable := SourceCode.Variables.Search(NextToken); … … 910 924 FunctionName: string; 911 925 begin 926 with Parser do 912 927 if IsIdentificator(NextToken) then begin 913 928 if Assigned(SourceCode.Functions.Search(NextToken)) then begin … … 939 954 I: integer; 940 955 begin 956 with Parser do 941 957 if NextToken = 'var' then begin 942 958 Expect('var'); … … 962 978 NewVariable: TVariable; 963 979 begin 980 with Parser do 964 981 try 965 982 Identifiers := TStringList.Create; … … 1001 1018 function TAnalyzerPascal.ParseConstantList(SourceCode: TConstantList; Exported: Boolean = False): Boolean; 1002 1019 begin 1020 with Parser do 1003 1021 if NextToken = 'const' then begin 1004 1022 Expect('const'); … … 1023 1041 ConstantValue: string; 1024 1042 begin 1025 with SourceCode do1043 with Parser, SourceCode do 1026 1044 try 1027 1045 Identifiers := TStringList.Create; … … 1070 1088 NewType.Parent := TypeList; 1071 1089 //with SourceCode do 1090 with Parser do 1072 1091 begin 1073 1092 if ExpectName then begin … … 1097 1116 NewType2: TType; 1098 1117 begin 1118 with Parser do 1099 1119 if NextToken = '<' then begin 1100 1120 Expect('<'); … … 1119 1139 Result := False; 1120 1140 // Use existed type 1141 with Parser do 1121 1142 if NextTokenType = ttIdentifier then begin 1122 1143 TypeName := ReadToken; … … 1146 1167 begin 1147 1168 // Buildin base type construction 1169 with Parser do 1148 1170 if NextToken = 'type' then begin 1149 1171 Expect('type'); … … 1165 1187 TempType: TType; 1166 1188 begin 1189 with Parser do 1167 1190 if NextToken = '^' then begin 1168 1191 Expect('^'); … … 1180 1203 TempType: TType; 1181 1204 begin 1205 with Parser do 1182 1206 if NextToken = '(' then begin 1183 1207 Expect('('); … … 1218 1242 TempType: TType; 1219 1243 begin 1244 with Parser do 1220 1245 if NextToken = 'record' then begin 1221 1246 Expect('record'); … … 1292 1317 TempType: TType; 1293 1318 begin 1319 with Parser do 1294 1320 if NextToken = 'class' then begin 1295 1321 Expect('class'); … … 1364 1390 TempType: TType; 1365 1391 begin 1392 with Parser do 1366 1393 if NextToken = 'array' then begin 1367 1394 Expect('array'); … … 1399 1426 TempType: TType; 1400 1427 begin 1428 with Parser do 1401 1429 if NextTokenType = ttConstantString then begin 1402 1430 TempType := NewType; … … 1424 1452 begin 1425 1453 inherited; 1454 Parser := TAnalyzer.Create; 1426 1455 Name := 'Delphi'; 1456 InputType := TSourceFileLink; 1457 OutputType := TProgram; 1427 1458 end; 1428 1459 1429 1460 destructor TAnalyzerPascal.Destroy; 1430 1461 begin 1462 Parser.Free; 1431 1463 inherited Destroy; 1432 1464 end; 1433 1465 1466 procedure TAnalyzerPascal.Convert(Input, Output: TSourceList); 1467 begin 1468 1469 end; 1470 1434 1471 { TParserUsedModuleList } 1435 1472 … … 1438 1475 NewUsedModule: TUsedModule; 1439 1476 begin 1477 with Parser do 1440 1478 if NextToken = 'uses' then begin 1441 1479 Expect('uses'); … … 1453 1491 AExported: Boolean): Boolean; 1454 1492 begin 1493 with Parser do 1455 1494 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin 1456 1495 Name := ReadToken;
Note:
See TracChangeset
for help on using the changeset viewer.