nielsAD / lape

Scripting engine with Pascal-like syntax for FPC and Delphi
119 stars 28 forks source link
compiler interpreter pascal programming-language

Lape

tests

Lape is a scripting engine with a Pascal derived syntax for Free Pascal and Delphi. It's written with speed and a broad platform compatibility in mind. The syntax is backwards compatible with Pascal Script (to a certain degree).

Lape is:


Simple example of running a script:

uses
  Classes, Sysutils, lpparser, lpcompiler, lpinterpreter;   

const
  MyScript = 'function DiceRoll: Int32;'           + LineEnding +
             'begin'                               + LineEnding +
             '  Result := Random(1, 6);'           + LineEnding +
             'end;'                                + LineEnding +
             ''                                    + LineEnding +
             'begin'                               + LineEnding +
             '  WriteLn("Rolled a ", DiceRoll());' + LineEnding +
             'end.';

var
  Compiler: TLapeCompiler;
begin
  Randomize();

  Compiler := TLapeCompiler.Create(TLapeTokenizerString.Create(MyScript));
  try
    if Compiler.Compile() then
      RunCode(Compiler.Emitter);
  except
    on E: Exception do
      WriteLn(E.ToString());
  end;
  Compiler.Free();

  ReadLn;
end.