可以使用单行和多行注释,如C。
如何描述lexer忽略所有注释的规则,即使是嵌套的注释,例如:
// comment /* nested comment /* and nested again? */ */或者像这样:
/* comment // one more comment /* and more... */ */UPD:
下面是解析嵌套注释的有效代码(谢谢相同的):
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 }发布于 2011-08-19 15:05:33
当我在玩FsLex时,我发现Ocamllex教程很有帮助,特别是嵌套注释部分很容易转换成F#。
https://stackoverflow.com/questions/7117975
复制相似问题