我想在程序里面做一个内嵌的语言分析解释器,让它可以执行我自己定义的语言,不知道哪位大哥能提供一点思路。
比如:
我在程序执行时,输入
if i>0 then showmessage('test');
程序就能象delphi编译以后的程序一样执行。

解决方案 »

  1.   

    太难了,需要编译原理学的很好啊
    你可以下一个带原代码的fast  report 看一下
    那个和你的要求一样,你可以参考一下
      

  2.   

    这个有想法,好。
    我的一个老师也在做类似的东西,他做的是类pascal的解释器,据他说差不多了。学过编译的应该知道,这东西不是那么简单的,不过很多编译书都提供了简单的编译器,你可以参考。
      

  3.   

    大学学过编译原理没有?最后那个pl0文法分析,那就是你要的东东,去看吧:-)
    好像还是pascal版本的,
      

  4.   

    试试VXML吧,当然具体解释方面的还是要自己写的啦!
      

  5.   

    没有简单的方法吗?
    delphi中没有类似宏代换的功能吗?
      

  6.   

    DreamScript控件主支持VCL,OOP
    另外还有一套控件也支持,或者你不想出¥的话,用微软的msscript.ocx也可以,不过只支持VBScript/JScript。
      

  7.   

    去问Chechy,这个家伙对编译原理很熟悉,因为他大学学这个学的太烂了,哈哈....
      

  8.   

    用微软的 ScriptControl,自己做还不知道做到何年月日。
      

  9.   

    51delphi 有个 scripter studio下,可以解释object pascal 和basic
      

  10.   

    看这个:http://expert.csdn.net/Expert/TopicView1.asp?id=1818477要自己写的话可以参考一下DCScripter或者DelphiWebScript的源码
      

  11.   

    最好用微软的脚本语言解析器,毕竟已经是成熟的产品了,而且你自己写的话,Bug在短期内不可能清除的很好吧!推荐使用微软的。毕竟可以免费使用。如果你实在要写,那么我也只能让你去看编译原理的书了
      

  12.   

    IFPS强大的pascal script动态执行的免费有源代码的组件
    google上可以找到的
      

  13.   

    TO: ly_liuyang(Liu Yang)
    首先要谢谢你.
    其次:IFPS3好象支持pascal可是不支持delphi呀!
    不知道你有没有试过.
      

  14.   

    我有一个控件包:DELPHIIN不知道大家听说过没有,我用过可以解释一些简单的PASCAL语法,我主要是用来做公式编辑和计算的,总体感觉还不错,你可以试试,到网上去DOWN个看看,找不到的话可以联系我把MAIL告诉我,我把我的给你MAIL过去
      

  15.   

    http://expert.csdn.net/Expert/topic/1923/1923268.xml?temp=.3507044
    帮帮忙吧
      

  16.   

    要是borland公开object pascal的编译器接口就好了,能够动态地在执行时编译代码。.net里就公开了编译器,很好用。
      

  17.   

    建议:我都晕了,你既然说是自己的编译器,怎么出现了DELPHI里的If、ShowMessage等关键字 不过这种东西不是那么简单的
      

  18.   

    用Delphi自带的命令行编译器,我曾经试过,可以的,但是你在发行程序时把它用到的头文件和库都包括进去,太大了不现实.
      

  19.   

    to redhf(农民的儿子) ,我的email是:[email protected],你能给我发一份吗?谢谢!
      

  20.   

    都不用!
    你可以作一个简单的脚本解释器,然后编译的工作就是把你的脚本解释器和你的脚本合成一个可执行文件。(就像winzip的可执行文件一样,winzip可执行文件就是把winzip的解释器捆绑上zip数据文件)
      

  21.   

    给你一段代码作参考,下面的代码把自己的数据放到可执行文件的尾部
    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.
      

  22.   

    找一下与Parser相关的资料吧..