谁能给我指出解释堆栈机的 C# 代码吗?
我正在寻找堆栈机的 C# 实现,最好是附带单元测试或至少有几个示例的实现。 http://en.wikipedia.org/wiki/P-code_machine 中的代码出现成为我正在寻找的那种东西。不幸的是,自从我用 Pascal 编程以来已经十多年了,并且在将其移植到 C# 时遇到了一堆问题。此外,没有使用该代码的示例。
无论如何,在这方面的任何帮助将不胜感激......
I'm looking for a C# implementation of a stack machine, preferably one with accompaning unit tests or at least couple of examples. The code at http://en.wikipedia.org/wiki/P-code_machine appears to be the sort of thing that I'm looking for. Unfortunately, it's been more than a decade since I programmed in Pascal and ran into a bunch of problems porting it to C#. Also, there was no example(s) of using the code.
Anyway, any help in this regard would be greatly appreciated....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解释型堆栈机在概念上与逆波兰表示法非常相似。
该表达式
用 RPN 表示为
计算如下:
从这里开始,应该很容易用 C# 构建一个简单的解释堆栈机。例如
,对于
现实世界的示例,请查看 .NET Framework 中 OpCodes 类的字段。
Interpreted stack machines are very similar in concept to Reverse Polish notation.
The expression
is expressed in RPN as
This gets evaluated as follows:
From there, it should be easy to build a simple interpreted stack machine in C#. E.g.
with
For a real world example, have a look at the fields of the OpCodes class in the .NET Framework.
原始的 Magpie 解释器是用 C# 编写的,并编译为堆栈 -基于字节码。看看 Machine.cs对于核心解释器类。将源代码转换为该字节码的编译器位于 Magpie.Compiler 中。
The original Magpie interpreter was written in C# and compiled down to stack-based bytecode. Take a look at Machine.cs for the core intepreter class. The compiler that translates source code to this bytecode is in Magpie.Compiler.