扩展魅力解释器
我需要扩展 Charme 解释器(此处描述)通过向全局环境添加一个原始过程 <= 。我知道要做到这一点,我还需要定义一个实现原语的过程,并修改 initializeGlobalEnvironment
以安装原语。
这就是我的 initializeGlobalEnvironment
--
def initializeGlobalEnvironment():
global globalEnvironment
globalEnvironment = Environment(None)
globalEnvironment.addVariable('true', True)
globalEnvironment.addVariable('false', False)
globalEnvironment.addVariable('+', primitivePlus)
globalEnvironment.addVariable('-', primitiveMinus)
globalEnvironment.addVariable('*', primitiveTimes)
globalEnvironment.addVariable('=', primitiveEquals)
globalEnvironment.addVariable('zero?', primitiveZero)
globalEnvironment.addVariable('>', primitiveGreater)
globalEnvironment.addVariable('<', primitiveLessThan)
I need to extend the Charme interpreter (described here) by adding a primitive procedure <= to the global environment. I know that to do this I also need to define a procedure that implements the primitive, and modify initializeGlobalEnvironment
to install the primitive.
This is what I have for initializeGlobalEnvironment
--
def initializeGlobalEnvironment():
global globalEnvironment
globalEnvironment = Environment(None)
globalEnvironment.addVariable('true', True)
globalEnvironment.addVariable('false', False)
globalEnvironment.addVariable('+', primitivePlus)
globalEnvironment.addVariable('-', primitiveMinus)
globalEnvironment.addVariable('*', primitiveTimes)
globalEnvironment.addVariable('=', primitiveEquals)
globalEnvironment.addVariable('zero?', primitiveZero)
globalEnvironment.addVariable('>', primitiveGreater)
globalEnvironment.addVariable('<', primitiveLessThan)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定 charme 的确切语法,但近似的 schema-y 代码是
I am not sure about the exact syntax for charme, but the approximate scheme-y code would be