Changeset 150


Ignore:
Timestamp:
Jan 18, 2018, 2:36:23 PM (6 years ago)
Author:
chronos
Message:
  • Added: Load/Save example source code from/to file instead of hardcoded text in application source code.
Location:
branches/easy compiler
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler/UFormMain.lfm

    r149 r150  
    88  ClientWidth = 909
    99  DesignTimePPI = 120
     10  OnClose = FormClose
    1011  OnCreate = FormCreate
    1112  OnDestroy = FormDestroy
    1213  OnShow = FormShow
    1314  LCLVersion = '1.8.0.6'
    14   object MemoOutput: TMemo
    15     Left = 440
    16     Height = 464
     15  object MemoSource: TMemo
     16    Left = 9
     17    Height = 488
    1718    Top = 32
    18     Width = 448
    19     ReadOnly = True
     19    Width = 416
     20    Anchors = [akTop, akLeft, akBottom]
    2021    ScrollBars = ssAutoBoth
    2122    TabOrder = 0
    2223  end
    23   object MemoSource: TMemo
    24     Left = 8
    25     Height = 240
    26     Top = 32
    27     Width = 416
    28     ScrollBars = ssAutoBoth
    29     TabOrder = 1
    30   end
    3124  object ButtonBuild: TButton
    32     Left = 112
     25    Left = 9
    3326    Height = 31
    34     Top = 280
     27    Top = 528
    3528    Width = 166
     29    Anchors = [akLeft, akBottom]
    3630    Caption = 'Compile && Execute'
    3731    OnClick = ButtonBuildClick
    38     TabOrder = 2
    39   end
    40   object Edit1: TEdit
    41     Left = 440
    42     Height = 28
    43     Top = 526
    44     Width = 200
    45     OnKeyPress = Edit1KeyPress
    46     TabOrder = 3
    47   end
    48   object ButtonSend: TButton
    49     Left = 656
    50     Height = 31
    51     Top = 526
    52     Width = 94
    53     Caption = 'Send'
    54     OnClick = ButtonSendClick
    55     TabOrder = 4
     32    TabOrder = 1
    5633  end
    5734  object Label1: TLabel
     
    6340    ParentColor = False
    6441  end
    65   object Label2: TLabel
    66     Left = 440
    67     Height = 20
    68     Top = 11
    69     Width = 108
    70     Caption = 'Executor output:'
    71     ParentColor = False
    72   end
    73   object Label3: TLabel
    74     Left = 441
    75     Height = 20
    76     Top = 504
    77     Width = 98
    78     Caption = 'Executor input:'
    79     ParentColor = False
    80   end
    81   object MemoGenerator: TMemo
    82     Left = 8
    83     Height = 216
    84     Top = 344
    85     Width = 416
    86     ScrollBars = ssAutoBoth
    87     TabOrder = 5
    88   end
    89   object Label4: TLabel
    90     Left = 8
    91     Height = 20
    92     Top = 315
    93     Width = 117
    94     Caption = 'Generator output:'
    95     ParentColor = False
     42  object PageControl1: TPageControl
     43    Left = 432
     44    Height = 552
     45    Top = 8
     46    Width = 470
     47    ActivePage = TabSheetExecutor
     48    Anchors = [akTop, akLeft, akRight, akBottom]
     49    TabIndex = 0
     50    TabOrder = 2
     51    object TabSheetExecutor: TTabSheet
     52      Caption = 'Executor'
     53      ClientHeight = 519
     54      ClientWidth = 462
     55      object Label2: TLabel
     56        Left = 8
     57        Height = 20
     58        Top = 8
     59        Width = 108
     60        Caption = 'Executor output:'
     61        ParentColor = False
     62      end
     63      object MemoOutput: TMemo
     64        Left = 8
     65        Height = 416
     66        Top = 32
     67        Width = 448
     68        Anchors = [akTop, akLeft, akRight, akBottom]
     69        ReadOnly = True
     70        ScrollBars = ssAutoBoth
     71        TabOrder = 0
     72      end
     73      object Label3: TLabel
     74        Left = 8
     75        Height = 20
     76        Top = 452
     77        Width = 98
     78        Anchors = [akLeft, akBottom]
     79        Caption = 'Executor input:'
     80        ParentColor = False
     81      end
     82      object Edit1: TEdit
     83        Left = 8
     84        Height = 28
     85        Top = 480
     86        Width = 336
     87        Anchors = [akLeft, akRight, akBottom]
     88        OnKeyPress = Edit1KeyPress
     89        TabOrder = 1
     90      end
     91      object ButtonSend: TButton
     92        Left = 360
     93        Height = 31
     94        Top = 477
     95        Width = 94
     96        Anchors = [akRight, akBottom]
     97        Caption = 'Send'
     98        OnClick = ButtonSendClick
     99        TabOrder = 2
     100      end
     101    end
     102    object TabSheetGenerator: TTabSheet
     103      Caption = 'Generator'
     104      ClientHeight = 519
     105      ClientWidth = 462
     106      object Label4: TLabel
     107        Left = 8
     108        Height = 20
     109        Top = 8
     110        Width = 117
     111        Caption = 'Generator output:'
     112        ParentColor = False
     113      end
     114      object MemoGenerator: TMemo
     115        Left = 8
     116        Height = 480
     117        Top = 32
     118        Width = 448
     119        Anchors = [akTop, akLeft, akRight, akBottom]
     120        ScrollBars = ssAutoBoth
     121        TabOrder = 0
     122      end
     123    end
    96124  end
    97125end
  • branches/easy compiler/UFormMain.pas

    r149 r150  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   UTargetCode, USourceCode, USourceExecutor, USourceGenerator, LCLIntf;
     9  UTargetCode, USourceCode, USourceExecutor, USourceGenerator, LCLIntf,
     10  ComCtrls;
    1011
    1112type
     
    1415
    1516  TForm1 = class(TForm)
     17    ButtonBuild: TButton;
    1618    ButtonSend: TButton;
    17     ButtonBuild: TButton;
    1819    Edit1: TEdit;
    1920    Label1: TLabel;
     
    2122    Label3: TLabel;
    2223    Label4: TLabel;
     24    MemoGenerator: TMemo;
    2325    MemoOutput: TMemo;
    2426    MemoSource: TMemo;
    25     MemoGenerator: TMemo;
     27    PageControl1: TPageControl;
     28    TabSheetExecutor: TTabSheet;
     29    TabSheetGenerator: TTabSheet;
    2630    procedure ButtonBuildClick(Sender: TObject);
    2731    procedure ButtonSendClick(Sender: TObject);
    2832    procedure Edit1KeyPress(Sender: TObject; var Key: char);
     33    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2934    procedure FormCreate(Sender: TObject);
    3035    procedure FormDestroy(Sender: TObject);
     
    3540    function ExecutorInput: string;
    3641  public
     42    FileName: string;
    3743  end;
    3844
     
    5157procedure TForm1.FormShow(Sender: TObject);
    5258begin
    53 {  with MemoSource.Lines do begin
    54     Add('Begin');
    55     Add('var I Integer');
    56     Add('Assign I 10');
    57     Add('Repeat');
    58     Add('Begin');
    59     Add('PrintLn I');
    60     Add('Decrement I 1');
    61     Add('IfEqual I 0');
    62     Add('Break');
    63     Add('End');
    64     Add('End');
    65   end;
    66   with MemoSource.Lines do begin
    67     Add('PrintLn ''Super Calculator''');
    68     Add('var Value1 Integer');
    69     Add('var Value2 Integer');
    70     Add('var Result Integer');
    71     Add('Print ''Enter value 1: ''');
    72     Add('Assign Value1 0');
    73     Add('InputLn Value1');
    74     Add('Print ''Enter value 2: ''');
    75     Add('Assign Value2 0');
    76     Add('InputLn Value2');
    77 
    78     Add('Assign Result Value1');
    79     Add('Increment Result Value2');
    80     Add('Print ''Sum of two values is: ''');
    81     Add('PrintLn Result');
    82   end;
    83   with MemoSource.Lines do begin
    84     Add('PrintLn ''Hello World!''');
    85     Add('print ''Hello'' PRINT '' World!''');
    86     Add('PrintLn ''Live your life.''');
    87     Add('var Text1 String');
    88     Add('Assign Text1 ''Live your life.''');
    89     Add('var Text2 String');
    90     Add('Assign Text2 ''Live your life.''');
    91     Add('PrintLn Text1');
    92     Add('PrintLn Text2');
    93 
    94     Add('var Value1 Integer');
    95     Add('Assign Value1 123');
    96     Add('Increment Value1 2');
    97     Add('PrintLn Value1');
    98 
    99     Add('var Text3 String');
    100     Add('Assign Text3 ''''');
    101     Add('Print ''Enter your name:''');
    102     Add('InputLn Text3');
    103     Add('PrintLn Text3');
    104   end;
    105 }
    106   with MemoSource.Lines do begin
    107     Add('Begin');
    108     Add('Var AnimalName StringArray');
    109     Add('Var AnimalProperty StringArray');
    110     Add('Var AnimalCount Integer');
    111     Add('Var Answer String');
    112     Add('Var I Integer');
    113     Add('Assign AnimalName[0] ''an elephant''');
    114     Add('Assign AnimalProperty[0] ''It is big and slow''');
    115     Add('Assign AnimalName[1] ''a cat''');
    116     Add('Assign AnimalProperty[1] ''It meows and purrs''');
    117     Add('Print ''An animal guessing game.''');
    118     Add('Assign AnimalCount 2');
    119     Add('Repeat');
    120     Add('Begin');
    121       Add('PrintLn ''Think an animal.''');
    122       Add('Assign I 0');
    123       Add('Repeat');
    124       Add('Begin');
    125         Add('Print AnimalProperty[I]');
    126         Add('Print ''? (y/n)''');
    127         Add('InputLn Answer');
    128         Add('IfEqual Answer ''y''');
    129         Add('Begin');
    130           Add('Print ''Thats clear. It is ''');
    131           Add('PrintLn AnimalName[I]');
    132           Add('Break');
    133         Add('End');
    134         Add('Increment I 1');
    135         Add('IfEqual I AnimalCount');
    136         Add('Break');
    137       Add('End');
    138       Add('IfEqual I AnimalCount');
    139       Add('Begin');
    140         Add('PrintLn ''I am lost. What is the animal?''');
    141         Add('InputLn AnimalName[I]');
    142         Add('PrintLn ''Describe the animal for me. What is it like?''');
    143         Add('InputLn AnimalProperty[I]');
    144         Add('PrintLn ''Thank you. I will remember that animal.''');
    145         Add('Increment AnimalCount 1');
    146       Add('End');
    147       Add('Print ''Do you want to try again? (y/n)''');
    148       Add('InputLn Answer');
    149       Add('IfNotEqual Answer ''y''');
    150       Add('Break');
    151       Add('PrintLn ''''');
    152     Add('End');
    153     Add('PrintLn ''Bye''');
    154     Add('End');
    155   end;
    156 
     59  FileName := 'Examples' + DirectorySeparator + 'Animal guessing game.lan';
     60  MemoSource.Lines.LoadFromFile(FileName);
    15761end;
    15862
     
    196100end;
    197101
     102procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     103begin
     104  MemoSource.Lines.SaveToFile(FileName);
     105end;
     106
    198107procedure TForm1.FormCreate(Sender: TObject);
    199108begin
  • branches/easy compiler/USourceGenerator.pas

    r149 r150  
    9191    end else
    9292    if Name = 'assign' then begin
     93      if TSourceReference(Parameters[0]) is TSourceReferenceArray then
     94        Result := Result + IndentStr + 'SetLength(' + TSourceReferenceArray(Parameters[0]).ArrayRef.Name +
     95          ', ' + GenerateRef(TSourceReferenceArray(Parameters[0]).Index) + ' + 1);' + LineEnding;
    9396      Result := Result + IndentStr + GenerateRef(TSourceReference(Parameters[0])) + ' := ' +
    9497        GenerateRef(TSourceReference(Parameters[1])) + ';' + LineEnding;
Note: See TracChangeset for help on using the changeset viewer.