| 1 | unit UMainForm;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, SynHighlighterCpp, SynEdit, SynMemo,
|
|---|
| 9 | SynHighlighterAny, SynHighlighterPas, Forms, Controls, Graphics, Dialogs,
|
|---|
| 10 | StdCtrls, UParser, UCompiler;
|
|---|
| 11 |
|
|---|
| 12 | type
|
|---|
| 13 | { TFormMain }
|
|---|
| 14 |
|
|---|
| 15 | TFormMain = class(TForm)
|
|---|
| 16 | ButtonSelectDir: TButton;
|
|---|
| 17 | ButtonConvert: TButton;
|
|---|
| 18 | EditPath: TEdit;
|
|---|
| 19 | OpenDialog1: TOpenDialog;
|
|---|
| 20 | SynCppSyn1: TSynCppSyn;
|
|---|
| 21 | SynMemo1: TSynMemo;
|
|---|
| 22 | function IsKeyword(Text: string): Boolean;
|
|---|
| 23 | procedure ButtonConvertClick(Sender: TObject);
|
|---|
| 24 | procedure ButtonSelectDirClick(Sender: TObject);
|
|---|
| 25 | procedure FormCreate(Sender: TObject);
|
|---|
| 26 | procedure FormDestroy(Sender: TObject);
|
|---|
| 27 | procedure FormShow(Sender: TObject);
|
|---|
| 28 | private
|
|---|
| 29 | public
|
|---|
| 30 | MainFile: TStringList;
|
|---|
| 31 | MainFileOut: TStringList;
|
|---|
| 32 | Macros: TStringList;
|
|---|
| 33 | Compiler: TCompiler;
|
|---|
| 34 | CompilerMacro: TCompilerMacro;
|
|---|
| 35 | procedure Error(Text: string);
|
|---|
| 36 | end;
|
|---|
| 37 |
|
|---|
| 38 | var
|
|---|
| 39 | FormMain: TFormMain;
|
|---|
| 40 |
|
|---|
| 41 | implementation
|
|---|
| 42 |
|
|---|
| 43 | {$R *.lfm}
|
|---|
| 44 |
|
|---|
| 45 | { TFormMain }
|
|---|
| 46 |
|
|---|
| 47 | function TFormMain.IsKeyword(Text: string): Boolean;
|
|---|
| 48 | var
|
|---|
| 49 | I: integer;
|
|---|
| 50 | begin
|
|---|
| 51 | Result := False;
|
|---|
| 52 | for I := 0 to High(Instructions) do
|
|---|
| 53 | if Instructions[I] = Text then
|
|---|
| 54 | Result := True;
|
|---|
| 55 | end;
|
|---|
| 56 |
|
|---|
| 57 | procedure TFormMain.ButtonConvertClick(Sender: TObject);
|
|---|
| 58 | begin
|
|---|
| 59 | MainFile.LoadFromFile(EditPath.Text);
|
|---|
| 60 | MainFileOut.Text := CompilerMacro.Compile(MainFile.Text);
|
|---|
| 61 | MainFileOut.Text := Compiler.Compile(MainFileOut.Text);
|
|---|
| 62 | ForceDirectoriesUTF8(ExtractFileDir(EditPath.Text) + DirectorySeparator + 'C');
|
|---|
| 63 | MainFileOut.SaveToFile(ExtractFileDir(EditPath.Text) + DirectorySeparator + 'C' +
|
|---|
| 64 | DirectorySeparator + 'main.c');
|
|---|
| 65 | SynMemo1.Lines.Assign(MainFileOut);
|
|---|
| 66 | end;
|
|---|
| 67 |
|
|---|
| 68 | procedure TFormMain.ButtonSelectDirClick(Sender: TObject);
|
|---|
| 69 | var
|
|---|
| 70 | Dir: string;
|
|---|
| 71 | begin
|
|---|
| 72 | OpenDialog1.FileName := EditPath.Text;
|
|---|
| 73 | if OpenDialog1.Execute then begin
|
|---|
| 74 | EditPath.Text := OpenDialog1.FileName;
|
|---|
| 75 | end;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 79 | begin
|
|---|
| 80 | MainFile := TStringList.Create;
|
|---|
| 81 | MainFileOut := TStringList.Create;
|
|---|
| 82 | CompilerMacro := TCompilerMacro.Create;
|
|---|
| 83 | CompilerMacro.Parser.OnError := Error;
|
|---|
| 84 | Compiler := TCompiler.Create;
|
|---|
| 85 | Compiler.Parser.OnError := Error;
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 89 | begin
|
|---|
| 90 | FreeAndNil(MainFile);
|
|---|
| 91 | FreeAndNil(MainFileOut);
|
|---|
| 92 | FreeAndNil(CompilerMacro);
|
|---|
| 93 | FreeAndNil(Compiler);
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 97 | begin
|
|---|
| 98 | ButtonConvertClick(Self);
|
|---|
| 99 | //Close;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TFormMain.Error(Text: string);
|
|---|
| 103 | begin
|
|---|
| 104 | Compiler.Emit('Error: ' + Text + LineEnding);
|
|---|
| 105 | Compiler.Parser.Position := Length(Compiler.Parser.Source) + 1;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | end.
|
|---|
| 111 |
|
|---|