Constructing a simple interpreter

后端 未结 9 2157
别跟我提以往
别跟我提以往 2020-12-15 11:41

I’m starting a project where I need to implement a light-weight interpreter. The interpreter is used to execute simple scientific algorithms. The programming language that t

相关标签:
9条回答
  • 2020-12-15 12:07

    One way to do it is to examine the source code for an existing interpreter. I've written a javascript interpreter in the D programming language, you can download the source code from http://ftp.digitalmars.com/dmdscript.zip

    Walter Bright, Digital Mars

    0 讨论(0)
  • 2020-12-15 12:09

    I would write it in ANTLR. Write the grammar, let ANTLR generate a C# parser. You can ANTLR ask for a parse tree, and possibly the interpreter can already operate on the parse tree. Perhaps you'll have to convert the parse tree to some more abstract internal representation (although ANTLR already allows to leave out irrelevant punctuation when generating the tree).

    0 讨论(0)
  • 2020-12-15 12:13

    The Silk library has just been published to GitHub. It seems to do most of what you are asking. It is very easy to use. Just register the functions you want to make available to the script, compile the script to bytecode and execute it.

    0 讨论(0)
提交回复
热议问题