如何实现数据执行(就像脚本源代码一样) [英] How to implement data execution (as if it were script source code)

查看:108
本文介绍了如何实现数据执行(就像脚本源代码一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设存在一种称为ScriptCode的脚本语言,该脚本语言具有以相同语言执行代码的功能.

Suppose there is a script language called ScriptCode with the capabilities of execute code in same language.

//此ficticius程序执行一个简单的常量代码.

//This ficticius program executes a simple constant code.

main()
{
    ScriptCode sc=new ScriptCode ( "print \"Hello\"");

    execute(sc); 

    print (" world");
}

///这个ficticius程序将从stdin读取10个程序,然后全部执行.

//This ficticius program would read 10 programs from stdin and then execute them all.

main()
{

     ScriptCode programs[10] 

     String input;

     for(int i=0;i<10; i++)   
      {
          input =readInput();
          program[i] = new ScriptCode(input);
      }


   for( SriptCode p : programs)
       execute( p );

}

问题是:

"ScriptCode"可以是哪种程序语言? 或者 这种软件怎么实现?

Which existent program language could "ScriptCode" be ? or How could this kind of software be implemented?

(我希望它不是LISP的唯一选择,但如果是这样,我将不得不面对.)

(I hope it's not LISP the only choice, but if so.. I would have to face it.)

谢谢

推荐答案

您的execute例程通常称为eval. 关于eval的维基百科文章列出了许多具有"eval"的语言,包括JavaScript,ActionScript,Lisp ,Perl,PHP,Lua,PostScript,Python,D,ColdFusion,REALbasic,Ruby,Forth,VBScript,Visual Basic for Applications和Smalltalk.下面的注释中也提到了SQL(谢谢).

your execute routine is traditionally called eval. the wikipedia article on eval lists many languages that have an "eval", including JavaScript, ActionScript, Lisp, Perl, PHP, Lua, PostScript, Python, D, ColdFusion, REALbasic, Ruby, Forth, VBScript, Visual Basic for Applications, and Smalltalk. SQL is also mentioned in comments below (thanks).

通常,实现使用与语言本身相同的代码(以减少重复).因此,解释语言将调用解释器,而编译语言将调用编译器.由于解释器必须包含在解释程序中,但编译器通常不包含编译器,因此此功能在解释语言中更为常见.

typically, the implementation uses the same code as the language itself (to reduce duplication). so interpreted languages invoke the interpreter and compiled languages invoke the compiler. since the interpreter must be included with interpreted programs, but a compiler is often not included with compiled ones, this functionality is more common in interpreted languages.

这篇关于如何实现数据执行(就像脚本源代码一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆