可以使用单行和多行注释,例如C。
如何描述词法分析器忽略所有注释的规则,甚至嵌套,例如:
// comment /* nested comment /* and nested again? */ */
或者喜欢这些:
/* comment // one more comment /* and more... */ */
UPD:
以下是解析嵌套注释的有效代码(感谢Sam):
rule token = parse
| "/*" { comments 0 lexbuf }
| [' ' '\t' '\n'] { token lexbuf }
| eof { raise End_of_file }
and comments level = parse
| "*/" {
if level = 0 then token lexbuf
else comments (level-1) lexbuf
}
| "/*" { comments (level+1) lexbuf }
| _ { comments level lexbuf }