Ignore:
Timestamp:
Apr 20, 2020, 10:23:44 AM (5 years ago)
Author:
chronos
Message:
  • Added: C# code generator.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UFormMain.pas

    r205 r206  
    77uses
    88  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
    9   ActnList, SynHighlighterPas, SynEdit, USource;
     9  ActnList, ExtCtrls, SynHighlighterPas, SynEdit, USource;
    1010
    1111type
     
    1414
    1515  TFormMain = class(TForm)
    16     ButtonCompile: TButton;
    17     ButtonGenerate1: TButton;
    18     ButtonRun: TButton;
    19     ButtonGenerate: TButton;
    20     Label1: TLabel;
     16    ACompile: TAction;
     17    AExit: TAction;
     18    ARun: TAction;
     19    AGenerateCSharp: TAction;
     20    AGeneratePhp: TAction;
     21    AGeneratePascal: TAction;
     22    ActionList1: TActionList;
    2123    Label2: TLabel;
    22     MemoLog: TMemo;
     24    MainMenu1: TMainMenu;
    2325    MemoOutput: TMemo;
    24     SynEditSource: TSynEdit;
    25     SynFreePascalSyn1: TSynFreePascalSyn;
    26     procedure ButtonCompileClick(Sender: TObject);
    27     procedure ButtonGenerate1Click(Sender: TObject);
    28     procedure ButtonGenerateClick(Sender: TObject);
    29     procedure ButtonRunClick(Sender: TObject);
     26    MenuItem1: TMenuItem;
     27    MenuItem2: TMenuItem;
     28    MenuItem3: TMenuItem;
     29    MenuItem4: TMenuItem;
     30    MenuItem5: TMenuItem;
     31    MenuItem6: TMenuItem;
     32    MenuItemRun: TMenuItem;
     33    MenuItemGenerate: TMenuItem;
     34    MenuItemFile: TMenuItem;
     35    PanelSource: TPanel;
     36    PanelMessages: TPanel;
     37    procedure ACompileExecute(Sender: TObject);
     38    procedure AExitExecute(Sender: TObject);
     39    procedure AGenerateCSharpExecute(Sender: TObject);
     40    procedure AGeneratePascalExecute(Sender: TObject);
     41    procedure AGeneratePhpExecute(Sender: TObject);
     42    procedure ARunExecute(Sender: TObject);
    3043    procedure FormActivate(Sender: TObject);
    3144    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    3851    procedure InterpreterError(Pos: TPoint; Text: string);
    3952    procedure UpdateInterface;
     53    procedure DockForm(Form: TForm; DockSite: TWinControl);
    4054  public
    4155
     
    5165
    5266uses
    53   UParser, UExecutor, UGeneratorPascal, UGeneratorPhp;
     67  UParser, UExecutor, UGeneratorPascal, UGeneratorPhp, UFormMessages, UFormSource,
     68  UGeneratorCSharp;
    5469
    5570{ TFormMain }
     
    5974  if not Initialized then begin
    6075    Initialized := True;
    61     SynEditSource.Lines.LoadFromFile('Test.pas');
    62     ButtonRun.Click;
     76    FormSource.SynEditSource.Lines.LoadFromFile('Test.pas');
     77    ARun.Execute;
    6378  end;
    6479end;
     
    7691procedure TFormMain.FormShow(Sender: TObject);
    7792begin
     93  DockForm(FormMessages, PanelMessages);
     94  DockForm(FormSource, PanelSource);
    7895  UpdateInterface;
    7996end;
    8097
    81 procedure TFormMain.ButtonRunClick(Sender: TObject);
     98procedure TFormMain.AExitExecute(Sender: TObject);
     99begin
     100  Close;
     101end;
     102
     103procedure TFormMain.ACompileExecute(Sender: TObject);
     104var
     105  Parser: TParser;
     106begin
     107  FormMessages.Clear;
     108  Parser := TParser.Create;
     109  Parser.OnError := InterpreterError;
     110  Parser.Source := FormSource.SynEditSource.Lines.Text;
     111  Parser.Parse;
     112  if Assigned(Prog) then Prog.Free;
     113  Prog := Parser.Prog;
     114  Parser.Free;
     115  UpdateInterface;
     116end;
     117
     118procedure TFormMain.AGenerateCSharpExecute(Sender: TObject);
     119var
     120  Generator: TGeneratorCSharp;
     121begin
     122  ACompile.Execute;
     123  MemoOutput.Lines.Clear;
     124  if Assigned(Prog) then begin
     125    Generator := TGeneratorCSharp.Create;
     126    Generator.Prog := Prog;
     127    Generator.Generate;
     128    MemoOutput.Lines.Text := Generator.Output;
     129    Generator.Free;
     130    MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.cs');
     131  end;
     132end;
     133
     134procedure TFormMain.AGeneratePascalExecute(Sender: TObject);
     135var
     136  Generator: TGeneratorPascal;
     137begin
     138  ACompile.Execute;
     139  MemoOutput.Lines.Clear;
     140  if Assigned(Prog) then begin
     141    Generator := TGeneratorPascal.Create;
     142    Generator.Prog := Prog;
     143    Generator.Generate;
     144    MemoOutput.Lines.Text := Generator.Output;
     145    Generator.Free;
     146    MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.pas');
     147  end;
     148end;
     149
     150procedure TFormMain.AGeneratePhpExecute(Sender: TObject);
     151var
     152  Generator: TGeneratorPhp;
     153begin
     154  ACompile.Execute;
     155  MemoOutput.Lines.Clear;
     156  if Assigned(Prog) then begin
     157    Generator := TGeneratorPhp.Create;
     158    Generator.Prog := Prog;
     159    Generator.Generate;
     160    MemoOutput.Lines.Text := Generator.Output;
     161    Generator.Free;
     162    MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.php');
     163  end;
     164end;
     165
     166procedure TFormMain.ARunExecute(Sender: TObject);
    82167var
    83168  Executor: TExecutor;
    84169begin
    85   ButtonCompile.Click;
     170  ACompile.Execute;
    86171  MemoOutput.Lines.Clear;
    87172  if Assigned(Prog) then begin
     
    94179end;
    95180
    96 procedure TFormMain.ButtonCompileClick(Sender: TObject);
    97 var
    98   Parser: TParser;
    99 begin
    100   MemoLog.Lines.Clear;
    101   Parser := TParser.Create;
    102   Parser.OnError := InterpreterError;
    103   Parser.Source := SynEditSource.Lines.Text;
    104   Parser.Parse;
    105   if Assigned(Prog) then Prog.Free;
    106   Prog := Parser.Prog;
    107   Parser.Free;
    108   UpdateInterface;
    109 end;
    110 
    111 procedure TFormMain.ButtonGenerate1Click(Sender: TObject);
    112 var
    113   Generator: TGeneratorPhp;
    114 begin
    115   ButtonCompile.Click;
    116   MemoOutput.Lines.Clear;
    117   if Assigned(Prog) then begin
    118     Generator := TGeneratorPhp.Create;
    119     Generator.Prog := Prog;
    120     Generator.Generate;
    121     MemoOutput.Lines.Text := Generator.Output;
    122     Generator.Free;
    123   end;
    124 end;
    125 
    126 procedure TFormMain.ButtonGenerateClick(Sender: TObject);
    127 var
    128   Generator: TGeneratorPascal;
    129 begin
    130   ButtonCompile.Click;
    131   MemoOutput.Lines.Clear;
    132   if Assigned(Prog) then begin
    133     Generator := TGeneratorPascal.Create;
    134     Generator.Prog := Prog;
    135     Generator.Generate;
    136     MemoOutput.Lines.Text := Generator.Output;
    137     Generator.Free;
    138   end;
    139 end;
    140 
    141181procedure TFormMain.InterpreterError(Pos: TPoint; Text: string);
    142182begin
    143   MemoLog.Lines.Add('[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] ' + Text);
     183  FormMessages.AddLine('[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] ' + Text);
    144184end;
    145185
    146186procedure TFormMain.UpdateInterface;
    147187begin
    148   ButtonRun.Enabled := Assigned(Prog);
     188end;
     189
     190procedure TFormMain.DockForm(Form: TForm; DockSite: TWinControl);
     191begin
     192  Form.ManualDock(DockSite, nil, alClient);
     193  Form.Align := alClient;
     194  Form.Show;
    149195end;
    150196
Note: See TracChangeset for help on using the changeset viewer.