Ignore:
Timestamp:
Nov 25, 2020, 12:18:45 AM (4 years ago)
Author:
chronos
Message:
  • Added: Support for more expression operators.
  • Added: Support for brackets in expressions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/Forms/UFormMain.pas

    r221 r222  
    77uses
    88  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
    9   ActnList, ExtCtrls, SynHighlighterPas, SynEdit, USource, UOptimizer;
     9  ActnList, ExtCtrls, SynHighlighterPas, SynEdit, USource, UOptimizer,
     10  UGenerator;
    1011
    1112type
     
    5253    Prog: TProgram;
    5354    Initialized: Boolean;
     55    procedure Generate(GeneratorClass: TGeneratorClass);
    5456    procedure ExecutorOutput(Text: string);
    5557    procedure InterpreterError(Pos: TPoint; Text: string);
     
    9092procedure TFormMain.FormDestroy(Sender: TObject);
    9193begin
    92   if Assigned(Prog) then Prog.Free;
     94  if Assigned(Prog) then FreeAndNil(Prog);
    9395end;
    9496
     
    99101  DockForm(FormOutput, PanelOutput);
    100102  UpdateInterface;
     103end;
     104
     105procedure TFormMain.Generate(GeneratorClass: TGeneratorClass);
     106var
     107  Generator: TGenerator;
     108  TargetFileName: string;
     109begin
     110  Generator := GeneratorClass.Create;
     111  try
     112    Generator.Prog := Prog;
     113    Generator.Generate;
     114    FormOutput.SetText(Generator.Output);
     115    TargetFileName := 'Generated' + DirectorySeparator +
     116      Generator.Name + DirectorySeparator + 'Test' + Generator.FileExt;
     117    ForceDirectories(ExtractFileDir(TargetFileName));
     118    FormOutput.SynEditOutput.Lines.SaveToFile(TargetFileName);
     119  finally
     120    Generator.Free;
     121  end;
    101122end;
    102123
     
    122143
    123144procedure TFormMain.AGenerateCSharpExecute(Sender: TObject);
    124 var
    125   Generator: TGeneratorCSharp;
    126145begin
    127146  ACompile.Execute;
     
    130149  FormOutput.Clear;
    131150  if Assigned(Prog) then begin
    132     Generator := TGeneratorCSharp.Create;
    133     Generator.Prog := Prog;
    134     Generator.Generate;
    135     FormOutput.SetText(Generator.Output);
    136     Generator.Free;
    137     FormOutput.SynEditOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.cs');
     151    Generate(TGeneratorCSharp);
    138152  end;
    139153end;
    140154
    141155procedure TFormMain.AGeneratePascalExecute(Sender: TObject);
    142 var
    143   Generator: TGeneratorPascal;
    144156begin
    145157  ACompile.Execute;
     
    147159  FormOutput.SynEditOutput.Lines.Clear;
    148160  if Assigned(Prog) then begin
    149     Generator := TGeneratorPascal.Create;
    150     Generator.Prog := Prog;
    151     Generator.Generate;
    152     FormOutput.SynEditOutput.Lines.Text := Generator.Output;
    153     Generator.Free;
    154     FormOutput.SynEditOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.pas');
     161    Generate(TGeneratorPascal);
    155162  end;
    156163end;
    157164
    158165procedure TFormMain.AGeneratePhpExecute(Sender: TObject);
    159 var
    160   Generator: TGeneratorPhp;
    161166begin
    162167  ACompile.Execute;
     
    165170  FormOutput.SynEditOutput.Lines.Clear;
    166171  if Assigned(Prog) then begin
    167     Generator := TGeneratorPhp.Create;
    168     Generator.Prog := Prog;
    169     Generator.Generate;
    170     FormOutput.SynEditOutput.Lines.Text := Generator.Output;
    171     Generator.Free;
    172     FormOutput.SynEditOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.php');
     172    Generate(TGeneratorPhp);
    173173  end;
    174174end;
    175175
    176176procedure TFormMain.AGenerateXmlExecute(Sender: TObject);
    177 var
    178   Generator: TGeneratorXml;
    179177begin
    180178  ACompile.Execute;
     
    182180  FormOutput.SynEditOutput.Lines.Clear;
    183181  if Assigned(Prog) then begin
    184     Generator := TGeneratorXml.Create;
    185     Generator.Prog := Prog;
    186     Generator.Generate;
    187     FormOutput.SynEditOutput.Lines.Text := Generator.Output;
    188     Generator.Free;
    189     FormOutput.SynEditOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.xml');
     182    Generate(TGeneratorXml);
    190183  end;
    191184end;
Note: See TracChangeset for help on using the changeset viewer.