构建一个简单的跨preTER [英] Constructing a simple interpreter

查看:131
本文介绍了构建一个简单的跨preTER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始一个项目,我需要实现一个轻量级的跨preTER。
跨preTER用于执行简单的科学算法。
编程语言,这间preTER将使用应该是简单的,因为它是针对非软件开发者(例如,数学家。)

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 this interpreter will use should be simple, since it is targeting non- software developers (for example, mathematicians.)

该间preTER应该支持基本的编程语言的特点:

The interpreter should support basic programming languages features:


  • 实数,变量,多维数组

  • 二进制(+, - ,*,/,%)和布尔(==,=,<,>,<!=,> =)操作

  • 循环(对于同时),有条件的前pressions(如果)

  • 功能

MathWorks的MatLab的是我前往那里的一个很好的例子,只是要简单得多。
间preTER将被用来作为环境证明算法;简单的算法如查找数据集/阵列的平均,或稍微复杂的算法,比如高斯消 RSA

MathWorks MatLab is a good example of where I’m heading, just much simpler. The interpreter will be used as an environment to demonstrate algorithms; simple algorithms such as finding the average of a dataset/array, or slightly more complicated algorithms such as Gaussian elimination or RSA.

我的主题是罗恩·阿尤布对code项目条目(发现最佳/最实用的资源的解析代数防爆pressions使用国米preTER模式) - 我的问题的一个缩小的版本,一个很好的例子。

Best/Most practical resource I found on the subject is Ron Ayoub’s entry on Code Project (Parsing Algebraic Expressions Using the Interpreter Pattern) - a perfect example of a minified version of my problem.

紫色龙书似乎是太多了,什么更实用?

The Purple Dragon Book seems to be too much, anything more practical?

该间preTER将实施作为.NET库,使用C#。然而,对于任何平台资源是受欢迎的,因为这个问题的设计架构部分是最具挑战性的。

The interpreter will be implemented as a .NET library, using C#. However, resources for any platform are welcome, since the design-architecture part of this problem is the most challenging.

任何实际的资源?

(请避开这不是小事或为什么要重新发明轮子响应)

(please avoid "this is not trivial" or "why re-invent the wheel" responses)

推荐答案

我想它写在 ANTLR 。写语法,让ANTLR生成一个C#编译器。您可以ANTLR要求一个解析树,并有可能跨preTER已经可以在解析树进行操作。也许你将不得不解析树转换成一些更抽象的内部重新presentation(虽然ANTLR已经允许生成树时,留下不相关的标点)。

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).

这篇关于构建一个简单的跨preTER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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