Ignore:
Timestamp:
Nov 9, 2009, 8:59:48 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Testování nyní prováděno přes oknovou aplikaci.
  • Přidáno: Podpora pro zobrazení řádku chyby.
Location:
branches/Void
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Void

    • Property svn:ignore
      •  

        old new  
        66project1.exe
        77*.dsk
         8*.~dsk
  • branches/Void/UCompilator.pas

    r5 r6  
    99
    1010type
    11   TOnErrorEvent = procedure (Text: string; var Terminate: Boolean) of object;
     11  TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object;
    1212
    1313  TVariable = class
     
    2525    Variables: TList;
    2626    Commands: TList;
     27    ParsePosition: TPoint;
    2728    procedure DoError(Text: string);
    2829    function FindVariableByName(AName: string): TVariable;
    2930  public
     31    SourceCode: TStringList;
    3032    Output: TStringList;
    31     procedure Compile(FileName: string);
     33    procedure Compile;
     34    procedure Clear;
    3235    procedure ProcessLine(Line: string);
    3336    constructor Create;
     
    4649begin
    4750  Terminate := False;
    48   if Assigned(FOnError) then FOnError(Text, Terminate);
     51  if Assigned(FOnError) then FOnError(Text, Terminate, ParsePosition);
    4952  if Terminate then raise Exception.Create('Compilation terminated');
    5053end;
     
    6063end;
    6164
    62 procedure TCompilator.Compile(FileName: string);
     65procedure TCompilator.Compile;
    6366var
    64   SourceCode: TStringList;
    6567  I: Integer;
    6668begin
    67   SourceCode := TStringList.Create;
    68   SourceCode.LoadFromFile(FileName);
     69  Clear;
    6970
    7071  // Process source lines
    7172  for I := 0 to SourceCode.Count - 1 do begin
     73    ParsePosition.Y := I;
    7274    ProcessLine(SourceCode[I]);
    7375  end;
     
    7577  // Prepare output
    7678  Output.Clear;
    77   Output.Add('program ' + ExtractFileName(FileName) + ';');
     79  Output.Add('program Test;');
    7880  Output.Add('{$APPTYPE CONSOLE}');
    7981
     
    9092      Output.Add(Text);
    9193  Output.Add('end.');
    92   Output.SaveToFile(ExtractFileName(FileName) + '.dpr');
    93   SourceCode.Destroy;
     94end;
     95
     96procedure TCompilator.Clear;
     97var
     98  I: Integer;
     99begin
     100  for I := 0 to Variables.Count - 1 do
     101    TVariable(Variables[I]).Destroy;
     102  Variables.Clear;
     103  for I := 0 to Commands.Count - 1 do
     104    TCommand(Commands[I]).Destroy;
     105  Commands.Clear;
     106  Output.Clear;
    94107end;
    95108
     
    99112  Variable: TVariable;
    100113  VariableName: string;
    101   begin
     114begin
    102115  Command := Parse(Line);
    103   WriteLn(Command);
    104116  if Command = 'Write' then
    105117  with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin
     
    128140  end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin
    129141    Text := 'Exit;';
    130   end else DoError('Unknown command: ' + Command);
     142  end else DoError('Unknown command ' + Command);
    131143end;
    132144
    133145constructor TCompilator.Create;
    134146begin
     147  SourceCode := TStringList.Create;
    135148  Output := TStringList.Create;
    136149  Variables := TList.Create;
     
    149162    TCommand(Commands[I]).Destroy;
    150163  Commands.Destroy;
     164  SourceCode.Destroy;
    151165  inherited Destroy;
    152166end;
Note: See TracChangeset for help on using the changeset viewer.