创建语言解释器 [英] Creating a language interpreter

查看:42
本文介绍了创建语言解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解语言解释器的工作原理.你们能告诉我口译员如何工作的一般路线吗?

I am trying to understand how a language interpreter works. Can you guys point me the general lines on how an interpreter works?

我的意思是,假设我有一些像这样写的行

I mean, suppose I have some lines written like this

10  x = 200;
20  for r = x to 1000 step 1
25  z = r + 32;
30  print z;
40  next r;
50  end;

构建可以运行类似程序的解释器的最佳方法是什么?

what's the best way to build an interpreter that could run something like that?

有一个包含所有允许的函数并搜索匹配项的大矩阵?第一行,例如:它给变量 x 赋值 200,但这些是不存在的符号.

Having a large matrix containing all functions allowed and searching for a match? The first line, for example: it is assigning 200 to a variable x, but these are symbols that does not exist.

如果你们能给我指路...

If you guys can give me the direction...

感谢您的帮助.

推荐答案

编译器创建是一个复杂的话题(解释器可以看作是一种特殊的编译器).

Compiler creation is a complex topic (an interpreter can be seen as a special compiler).

你必须首先解析它 - 尝试理解语法,然后创建一些内部表示(抽象语法树),然后创建一些执行逻辑.

You have to first parse it - try to understand the syntax and then create some internal representation (abstract syntax tree) and then create some execution logic.

维基百科 建议 http://mcs.une.edu.au/~comp319/

这篇关于创建语言解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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