请原谅我的英语。最近,我试图理解编译器的不同部分,并使用play语言实现它们。我想知道语义分析器的任务是什么,因为我所读到的语义分析器所要做的许多事情实际上并不适用于动态语言,例如类型检查、范围检查等,因为这些事情是在运行时检查的。
因此,我认为用于动态语言(如LUA、PYTHON或RUBY)的语义分析器的一些任务是
但是,我不确定动态语言编译器的语义分析阶段还有哪些其他工作。在动态语言中,它的工作量似乎很小,因为大多数都是在运行时完成的。语义分析器还为动态语言处理了哪些其他公共任务?我觉得我错过了语义分析的大部分内容。谢谢。
发布于 2011-08-25 06:44:50
没错,动态语言编译器中不存在许多分析任务(这就是为什么它们相对容易实现的原因)。不过,我还能想到一些其他的任务:
- What has to be analyzed? That part is easy in Lua as there is an explicit `local` keyword - but it still requires the compiler to be aware of it! - and requires relatively extensive analysis in Python, with assignments implicitly making variables locals and two (in 3.x, one in 2.x) keywords to change that behaviour.
- Why does it matter? In Python, acessing a local variable that hasn't been initialized yet is as much of an error as accessing a non-existing global in Python, but a different error. In Lua, both lead to `nil` and `local` doesn't change the scope of previous assignments, but the semantics of subsequent reads/writes still change. Also, the bytecode instructions for are very different in both cases.
CALL_LIKELY_BUILTIN操作码,用于调用可能是内置函数的全局函数。很明显,这需要一些范围分析。https://stackoverflow.com/questions/7185225
复制相似问题