我想在程序里面做一个内嵌的语言分析解释器,让它可以执行我自己定义的语言,不知道哪位大哥能提供一点思路。
比如:
我在程序执行时,输入
if i>0 then showmessage('test');
程序就能象delphi编译以后的程序一样执行。
比如:
我在程序执行时,输入
if i>0 then showmessage('test');
程序就能象delphi编译以后的程序一样执行。
解决方案 »
- delphi做OCX浏览WEB服务器上TIFF文件
- 问个问题
- 如何用DBGrid做到这个效果!急切盼望高手提点!
- 如何获取运行程序的列表?
- 如何在IEEE上发表论文?
- 很简单,在线等待....................不多50分
- 深入研究过 SystrayIcon 的请进来看看┅┅(100分请教,问题解决,马上给分)
- 哪位有李维的《Inside VCL》的电子书?????
- 江湖救急!access中的数据库如何实现两个表的复制?
- delphi 6 重大bug发布!!!!!!!!
- 如何实现像QQ那样左键双击和按下分开的代码???
- 请问98下的winipcfg.exe这个软件的功能是怎么实现的
你可以下一个带原代码的fast report 看一下
那个和你的要求一样,你可以参考一下
我的一个老师也在做类似的东西,他做的是类pascal的解释器,据他说差不多了。学过编译的应该知道,这东西不是那么简单的,不过很多编译书都提供了简单的编译器,你可以参考。
好像还是pascal版本的,
delphi中没有类似宏代换的功能吗?
另外还有一套控件也支持,或者你不想出¥的话,用微软的msscript.ocx也可以,不过只支持VBScript/JScript。
google上可以找到的
首先要谢谢你.
其次:IFPS3好象支持pascal可是不支持delphi呀!
不知道你有没有试过.
帮帮忙吧
你可以作一个简单的脚本解释器,然后编译的工作就是把你的脚本解释器和你的脚本合成一个可执行文件。(就像winzip的可执行文件一样,winzip可执行文件就是把winzip的解释器捆绑上zip数据文件)
unit ExeBufUnit;interface
uses
SysUtils;
const
//our ExeBuffer signature
ExeBufSig = 'EB1.0';type
EExeBuf = class(Exception)
end; TExeBuf = array of byte;
//the Footer for our executable format
TExeBufFooter = record
OriginalSize : Integer;
Sig : Array[0..4] of char;
end;procedure SetExeData (ExeName : String; ExeBuf : TExeBuf);
procedure GetExeData (ExeName : String; var ExeBuf : TExeBuf);
procedure StringToExeBuf (const S : String; var ExeBuf : TExeBuf);
function ExeBufToString (const ExeBuf : TExeBuf) : String;implementationprocedure SetExeData (ExeName : String; ExeBuf : TExeBuf);
var
F : File;
BufSz,OrigSz : Integer;
Footer : TExeBufFooter;
begin
AssignFile (F,ExeName);
Reset (F,1);
try
//obtaining the original file size
OrigSz := FileSize(F);
//go to the EOF of the file
Seek (F,OrigSz);
//Writing our custom data beyond the EOF
BufSz := Length(ExeBuf);
BlockWrite (F,Pointer(ExeBuf)^,BufSz);
//Writing our footer
FillChar (Footer,SizeOf(Footer),0);
Footer.OriginalSize := OrigSz;
Footer.Sig := ExeBufSig;
BlockWrite (F,Footer,Sizeof(Footer));
finally
CloseFile (F);
end;
end;
procedure GetExeData (ExeName : String; var ExeBuf : TExeBuf);
var
F : File;
CurrSz, BufSize : Integer;
OldFileMode : Integer;
Footer : TExeBufFooter;
begin
AssignFile (F,ExeName);
//Saving the old FileMode
OldFileMode := FileMode;
//Setting the FileMode to ReadOnly
FileMode := 0;
try
Reset (F,1);
try
//Getting the current file size
CurrSz := FileSize (F);
//Seeking to the footer position
//and reading it
Seek (F,CurrSz-SizeOf (Footer));
BlockRead (F,Footer,Sizeof(Footer));
//if there's no signature, boom!
//no data in this executable!
if Footer.Sig <> ExeBufSig then
raise EExeBuf.Create ('No Data in EXE!');
//calculating the buffer size that was written
//to this executable file
BufSize :=CurrSz-Footer.OriginalSize-SizeOf(Footer);
SetLength (ExeBuf,BufSize);
//seek and read!
Seek (F,Footer.OriginalSize);
BlockRead(F,Pointer(ExeBuf)^, BufSize);
finally
CloseFile (F);
end;
finally
//returning to the previous saved
//FileMode
FileMode := OldFileMode;
end;
end;procedure StringToExeBuf (const S : String; var ExeBuf : TExeBuf);
begin
SetLength(ExeBuf,Length(S));
Move (Pointer(S)^,Pointer(ExeBuf)^,Length(S));
end;function ExeBufToString (const ExeBuf : TExeBuf) : String;
begin
SetLength (Result,Length(ExeBuf));
Move (Pointer(ExeBuf)^,Pointer(Result)^,Length(ExeBuf));
end;end.