Ruby:评论标记是什么?

Mat*_*tty 6 ruby

我刚刚在这里阅读(http://ruby.runpaint.org/programs#lexical)评论是令牌.我从来没有把评论视为令牌,因为它们既可以是注释,也可以是后处理器.

评论真的是令牌还是这个来源错了?

die*_*rre 3

是的,它们是解析器的标记。通常,如果您使用解析器生成器,这就是注释的定义

{code} short_comment = '//' not_cr_lf* eol | '#' not_cr_lf* eol;
{code} long_comment = '/*' not_star* '*'+ (not_star_slash not_star* '*'+)* '/';  /* '4vim */
Ignored Tokens
  short_comment,
  long_comment;
Run Code Online (Sandbox Code Playgroud)

这是 SableCC 语法。它们通常是被忽略的标记。

请记住,您在源代码中编写的所有内容都是一个令牌,这始终是第一步。解析器需要开始从标记构建抽象语法树。