{$APPTYPE CONSOLE}
{$O-}
program Project1;
uses
  SysUtils,
  PaxCompiler, PaxProgram, PaxRegister;
type
  TMyHandler = class
  public
    function UndeclaredIdentifierHandler(Sender: TPaxCompiler;
        const IdentName: String;
        var Scope: String;
        var FullTypeName: String): boolean;
  end;

function TMyHandler.UndeclaredIdentifierHandler(Sender: TPaxCompiler;
     const IdentName: String;
     var Scope: String;
     var FullTypeName: String): boolean;
begin
  result := false;
  if CompareText(IdentName, 'x') = 0 then
  begin
    result := true;
    FullTypeName := 'Integer';
    Scope := 'MyProg';
  end;
end;

var
  PaxCompiler1: TPaxCompiler;
  PaxProgram1: TPaxProgram;
  PaxPascalLanguage1: TPaxPascalLanguage;
  MyHandler: TMyHandler;
begin
  PaxCompiler1 := TPaxCompiler.Create(nil);
  PaxProgram1 := TPaxProgram.Create(nil);
  PaxPascalLanguage1 := TPaxPascalLanguage.Create(nil);
  MyHandler := TMyHandler.Create;
  try
    PaxCompiler1.OnUndeclaredIdentifier := MyHandler.UndeclaredIdentifierHandler;

    PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
    PaxCompiler1.AddModule('1', 'Pascal');
    PaxCompiler1.AddCodeFromFile('1', 'script.txt');
    if PaxCompiler1.Compile(PaxProgram1) then
    begin
      PaxProgram1.Run;
    end
    else
    begin
      writeln(PaxCompiler1.ErrorMessage[0]);
      writeln(PaxCompiler1.ErrorLineNumber[0]);
      writeln(PaxCompiler1.ErrorLine[0]);
    end;
  finally
    MyHandler.Free;
    PaxCompiler1.Free;
    PaxProgram1.Free;
    PaxPascalLanguage1.Free;
  end;
  writeln('Press any key...');
  Readln;
end.
