编译器主动减少代码中的编译错误?
这周我坐在计算机科学的初级课上,想到了一些事情:
是否有一个编译器可以主动纠正代码中出现的编译错误(有效地减少/消除代码中的错误的反馈循环)?
在某些编程环境中,这是通过建议(例如,未知语法上的红色下划线、输入代码时自动完成)被动完成的,但是是否有编译器主动执行此操作的示例(即直接重写代码)?
想到这一点让我想到了其他事情:
实施起来有多复杂?我认为非常复杂,因为它归结为分析代码和平衡精度(例如准确指出用户想要什么 - 提出问题并获得程序员反馈)与方便的通用性(例如“一般”决定用户想要什么并更改代码 - 然后程序员可以返回并更改代码以使其更适合其任务)。这些都是粗略的想法,因为一个高度复杂、重点突出的程序涉及很多很多复杂的想法,这些想法的优先级并不总是很容易在代码中检测到(并且很容易分析)。
作为一个极端的例子,可以分析诸如“画一个矩形”之类的无语法代码段,然后使用程序员输入(从程序员那里获取关于“画在哪里?”、“多大尺寸的矩形?”等问题的反馈,或者“2d 还是 3d 空间?”)可以编写一个程序(优先考虑精度而不是通用性)。或者可能存在低级默认值,用于在发现关键字(“绘制”、“矩形”)时创建代码(优先考虑通用性而不是精确性)。
I was sitting in beginning Computer Science class this week and thought of something:
Is there a compiler that actively corrects compile errors that arise in code (effectively a feedback loop of reducing/eliminating errors in code)?
This is done passively with suggestions (e.g. red underlining on unknown syntax, auto-completion when typing in code) in some programming environments, but are there examples of a compiler doing this actively (i.e. directly rewriting the code)?
Thinking about this lead me to think about something else:
How complex would this be to implement? I imagine extremely complex, as it comes down to analyzing the code and balancing precision (e.g. pinpointing exactly what a user wants- asking questions and getting programmer feedback) with convenient generality (e.g. deciding "generally" what the user wants and making changes to the code- the programmer could then go back in and alter the code to be more specific to their task ). These are rough ideas, as a highly complex, focused program involves many, many complex ideas whose priorities are not always easily detected in the code (and easily analyzable).
As an extreme example a syntax-free piece of code such as "draw a rectangle" could be analyzed and then with programmer input (getting feedback from the programmer on questions such as "draw where?", "what size rectangle?", or "2d or 3d space?") a program could be written (privileging precision over generality). Or there could be low level default values which are used to create code when keywords ("draw", "rectangle") are spotted (privileging generality over precision).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数编译器在解析时会尝试某种程度的语法修复,但只是为了避免针对一个错误报告 100 个语法错误。然而,猜测程序员的意图并在这样的过程之后给他们一个工作的可执行程序充满了危险。
Most compilers attempt some level of syntax repair while parsing, but only so they don't report 100 syntax errors against one fault. However guessing what the programmer intended and giving them a working executable program after such a process is fraught with danger.
它于 1973 年完成。康奈尔大学的几位计算机科学研究人员为 PL/I 设计了一个编译器称为 PL/C 的语言。它的目的是作为一个教学系统,并将每个程序编译为语法正确且可以编译和执行的东西。它会重复重写或删除无效语句,直到它们能够正确编译。他们的工作的后来的、更像 IDE 的版本在 1977 年技术报告。
It was done in 1973. Several Cornell University CS researchers designed a compiler for the PL/I language called PL/C. It was intended as a teaching system, and compiled every program to something that was syntactically correct and could be compiled and executed. It would repetitively rewrite or remove invalid statements until they would compile correctly. A later, more-IDE-like version of their work is described in a 1977 technical report.