Changeset 7 for trunk/Compiler/Analyze/UPascalParser.pas
- Timestamp:
- Nov 5, 2010, 1:50:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Analyze/UPascalParser.pas
r6 r7 33 33 function ParseUnitInterface(SourceCode: TModuleUnit): Boolean; 34 34 function ParseUnitImplementation(SourceCode: TModuleUnit): Boolean; 35 procedure ParseProgram(SourceCode: TModuleProgram);35 function ParseProgram(var SourceCode: TModuleProgram; ProgramCode: TProgram): Boolean; 36 36 procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';'; 37 37 WithBody: Boolean = True); … … 396 396 begin 397 397 Self.ProgramCode := ProgramCode; 398 if not ParseUnit(TModuleUnit(Result), ProgramCode) then begin 399 Result := TModuleProgram.Create; 400 Result.ParentProgram := ProgramCode; 401 ParseProgram(TModuleProgram(Result)); 402 end else 398 if not ParseUnit(TModuleUnit(Result), ProgramCode) then 399 if not ParseProgram(TModuleProgram(Result), ProgramCode) then 403 400 ErrorMessage(SUnknownModuleType, [NextToken]); 404 401 end; 405 402 406 procedure TPascalParser.ParseProgram(SourceCode: TModuleProgram);403 function TPascalParser.ParseProgram(var SourceCode: TModuleProgram; ProgramCode: TProgram): Boolean; 407 404 var 408 405 Identifier: string; 409 406 begin 410 407 with SourceCode do begin 408 SourceCode := TModuleProgram.Create; 409 SourceCode.ParentProgram := ProgramCode; 411 410 if NextToken = 'program' then begin 412 411 Expect('program'); … … 421 420 ParseCommonBlock(Body, '.'); 422 421 SourceCode.ParentProgram.Modules.Add(SourceCode); 422 Result := True; 423 423 end; 424 424 end; … … 427 427 var 428 428 NewModule: TModule; 429 NewCommand: TCommand; 429 430 begin 430 431 if NextToken = 'unit' then begin … … 447 448 if NextToken = 'initialization' then begin 448 449 Expect('initialization'); 450 while (NextToken <> 'end') and (NextToken <> 'finalization') 451 and (NextTokenType <> ttEndOfFile) do 452 begin 453 NewCommand := ParseCommand(SourceCode.InititializeSection); 454 if Assigned(NewCommand) then 455 SourceCode.InititializeSection.Code.Commands.Add(NewCommand); 456 //ShowMessage(NextCode); 457 if NextToken = ';' then 458 ReadToken; 459 end; 449 460 end; 450 461 if NextToken = 'finalization' then begin 451 462 Expect('finalization'); 452 end; 463 while (NextToken <> 'end') and (NextTokenType <> ttEndOfFile) do 464 begin 465 NewCommand := ParseCommand(SourceCode.FinalalizeSection); 466 if Assigned(NewCommand) then 467 SourceCode.FinalalizeSection.Code.Commands.Add(NewCommand); 468 //ShowMessage(NextCode); 469 if NextToken = ';' then 470 ReadToken; 471 end; 472 end; 473 Expect('end'); 474 Expect('.'); 453 475 Result := True; 454 476 end else Result := False; … … 487 509 begin 488 510 with SourceCode do begin 489 while (NextToken <> EndSymbol) do begin511 while (NextToken <> EndSymbol) and (NextTokenType <> ttEndOfFile) do begin 490 512 if not ParseVariableList(Variables) then 491 513 if not ParseConstantList(Constants) then … … 1270 1292 end; 1271 1293 1272 1273 1294 end. 1274 1295
Note:
See TracChangeset
for help on using the changeset viewer.