MRI Ruby 1.9.2 中的词法分析
我目前正在学习一些编译器理论和实践。 Ruby 是我日常选择的语言,所以我去查看它的词法分析器和解析语法。 ruby 有单独的词法分析器吗?如果有,它在哪个文件中描述?
I'm learning some compiler theory and practice at the moment. Ruby is my every day language of choice, and so I went to look at its lexer and parse grammar. Does ruby have a separate lexer? If so, which file is it described in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ruby 源代码中有包含语法的
parse.y
文件。我相对确定 ruby 使用单独的词法分析器(就像大多数 LR 解析器一样)。另外,词法分析器似乎是有状态的:我想这是必要的,因为在某些情况下会忽略换行符,而在其他情况下它会终止表达式等。而且“class”并不总是像“x.class”中的关键字。
但我不是专家。
编辑:深入查看 parse.y 文件,词法分析器并不完全与解析器分开:
In the ruby source there is the
parse.y
file which contains the grammar. I am relatively sure that ruby uses a separate lexer (like most LR parsers). Also it seems like the lexer is stateful:I guess this necessary because a newline is ignored in some cases and in other cases it terminates expressions etc. Also 'class' is not always a keyword like e.g. in 'x.class'.
But i'm no expert.
EDIT: Looking deeper in the parse.y file the lexer is not completely separate from the parser: