Ruby:评论是代币吗?
我刚刚读过这里(http://ruby.runpaint.org/programs#lexical)评论是令牌。我从未将注释视为标记,因为它们要么是注释,要么是后处理器的。
评论真的是象征性的还是这个来源是错误的?
I've just read here (http://ruby.runpaint.org/programs#lexical) that comments are tokens. I've never thought of comments as tokens as they're either annotations or for a post-processor.
Are comments really tokens or is this source wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,它们应该是标记,但稍后会被解析器忽略。如果您对如下所示的文件执行 ruby --dump parsetree foo.rb ,
您将得到以下结果:
Yes, they should be tokens, but ignored by the parser later on. If you do
ruby --dump parsetree foo.rb
with a file that looks like thisthis is what you'll get:
是的,它们是解析器的标记。通常,如果您使用解析器生成器,这就是注释的定义
。这是 SableCC 语法。它们通常是被忽略的标记。
请记住,您在源代码中编写的所有内容都是一个令牌,这始终是第一步。解析器需要开始从标记构建抽象语法树。
Yeah they're tokens to the parser. Usually, if you use a parser generator this is the definition of a comment
This is a SableCC grammar. They're usually ignored tokens.
Remember that everything you write in a source code is a token, that's always the first step. The parser needs to start building the abstract syntax tree from tokens.