Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.012 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#9

AW: Parser - einfache Mathematische Formel

  Alt 8. Okt 2015, 17:04
Geht mit DelphiWebScript kinderleicht:

Delphi-Quellcode:
program MathExample;

{$APPTYPE CONSOLE}

uses
  dwsComp,
  dwsExprs;

var
  s: string;
  compiler: TDelphiWebScript;
  prog: IdwsProgram;
  exec: IdwsProgramExecution;
begin
  compiler := TDelphiWebScript.Create(nil);
  try
    repeat
      Readln(s);
      if s = 'then Exit;
      prog := compiler.Compile('Print(' + s + ')');
      if prog.Msgs.HasErrors then
        Writeln(prog.Msgs.AsInfo)
      else
      begin
        exec := prog.Execute;
        Writeln(exec.Result.ToString);
      end;
    until False;
  finally
    compiler.Free;
  end;
end.
LOL @LiveBindings Lösung...
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat