Changeset 204


Ignore:
Timestamp:
Apr 17, 2020, 11:07:37 PM (4 years ago)
Author:
chronos
Message:
  • Added: Simple PHP code generator.
Location:
branches/interpreter2
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/Test.pas

    r203 r204  
    3737    WriteLn('Can''t believe this.');
    3838  end;
    39   WriteLn;
     39  WriteLn('');
    4040  WriteLn('Test');
    4141  WriteLn(A);
  • branches/interpreter2/UFormMain.lfm

    r203 r204  
    572572    TabOrder = 5
    573573  end
     574  object ButtonGenerate1: TButton
     575    Left = 416
     576    Height = 38
     577    Top = 18
     578    Width = 145
     579    Caption = 'Generate PHP'
     580    OnClick = ButtonGenerate1Click
     581    TabOrder = 6
     582  end
    574583  object SynFreePascalSyn1: TSynFreePascalSyn
    575584    Enabled = False
  • branches/interpreter2/UFormMain.pas

    r203 r204  
    1515  TFormMain = class(TForm)
    1616    ButtonCompile: TButton;
     17    ButtonGenerate1: TButton;
    1718    ButtonRun: TButton;
    1819    ButtonGenerate: TButton;
     
    2425    SynFreePascalSyn1: TSynFreePascalSyn;
    2526    procedure ButtonCompileClick(Sender: TObject);
     27    procedure ButtonGenerate1Click(Sender: TObject);
    2628    procedure ButtonGenerateClick(Sender: TObject);
    2729    procedure ButtonRunClick(Sender: TObject);
     
    4951
    5052uses
    51   UParser, UExecutor, UGenerator;
     53  UParser, UExecutor, UGenerator, UGeneratorPhp;
    5254
    5355{ TFormMain }
     
    107109end;
    108110
     111procedure TFormMain.ButtonGenerate1Click(Sender: TObject);
     112var
     113  Generator: TGeneratorPhp;
     114begin
     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;
     124end;
     125
    109126procedure TFormMain.ButtonGenerateClick(Sender: TObject);
    110127var
  • branches/interpreter2/UGenerator.pas

    r203 r204  
    140140    otFunctionCall: GenerateFunctionCall(Block, Expression.FunctionCall);
    141141    otConstantDirect: GenerateValue(Expression.ConstantDirect.Value);
    142     otConstantRef: GenerateValue(Expression.ConstantRef.Value);
     142    otConstantRef: AddText(Expression.ConstantRef.Name);
    143143    otVariableRef: AddText(Expression.VariableRef.Name);
    144144    else raise Exception.Create('Unsupported exception operand type.');
  • branches/interpreter2/UParser.pas

    r203 r204  
    605605  end;
    606606  with Block.Functions.AddNew('IntToStr') do begin
     607    InternalName := 'IntToStr';
    607608    Params.AddNew('Value', TypeInteger);
    608609    ResultType := TypeString;
    609610  end;
    610611  with Block.Functions.AddNew('StrToInt') do begin
     612    InternalName := 'StrToInt';
    611613    Params.AddNew('Value', TypeString);
    612614    ResultType := TypeInteger;
    613615  end;
    614616  with Block.Functions.AddNew('WriteLn') do begin
     617    InternalName := 'WriteLn';
    615618    Params.AddNew('Text', TypeString);
    616619  end;
    617620  with Block.Functions.AddNew('Write') do begin
     621    InternalName := 'Write';
    618622    Params.AddNew('Text', TypeString);
    619623  end;
  • branches/interpreter2/USource.pas

    r203 r204  
    1111  TExpressions = class;
    1212  TFunctions = class;
     13  TBeginEnd = class;
    1314
    1415  { TValue }
     
    9899  TFunction = class
    99100    Name: string;
     101    InternalName: string;
    100102    Params: TFunctionParameters;
    101103    ResultType: TType;
     104    BeginEnd: TBeginEnd;
    102105    constructor Create;
    103106    destructor Destroy; override;
     
    340343begin
    341344  Params := TFunctionParameters.Create;
     345  BeginEnd := TBeginEnd.Create;
    342346end;
    343347
    344348destructor TFunction.Destroy;
    345349begin
     350  BeginEnd.Free;
    346351  Params.Free;
    347352  inherited Destroy;
  • branches/interpreter2/interpreter.lpi

    r203 r204  
    7171      </Item2>
    7272    </RequiredPackages>
    73     <Units Count="8">
     73    <Units Count="9">
    7474      <Unit0>
    7575        <Filename Value="interpreter.lpr"/>
     
    107107        <IsPartOfProject Value="True"/>
    108108      </Unit7>
     109      <Unit8>
     110        <Filename Value="UGeneratorPhp.pas"/>
     111        <IsPartOfProject Value="True"/>
     112      </Unit8>
    109113    </Units>
    110114  </ProjectOptions>
  • branches/interpreter2/interpreter.lpr

    r203 r204  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, SysUtils, // this includes the LCL widgetset
    10   Forms, UFormMain, UParser, UTokenizer, USource, UExecutor, UInterpreter, UGenerator
     10  Forms, UFormMain, UParser, UTokenizer, USource, UExecutor, UInterpreter,
     11  UGenerator, UGeneratorPhp
    1112  { you can add units after this };
    1213
Note: See TracChangeset for help on using the changeset viewer.