我有一些基本的 ocamllex 代码,由我的教授编写,看起来还不错:
{ type token = EOF | Word of string }
rule token = parse
| eof { EOF }
| [’a’-’z’ ’A’-’Z’]+ as word { Word(word) }
| _ { token lexbuf }
{
(*module StringMap = BatMap.Make(String) in *)
let lexbuf = Lexing.from_channel stdin in
let wordlist =
let rec next l = match token lexbuf with
EOF -> l
| Word(s) -> next (s :: l)
in next []
in
List.iter print_endline wordlist
}
但是,运行ocamllex wordcount.mll
会产生
File "wordcount.mll", line 4, character 3: syntax error.
这表明[
这里第四行的正则表达式的第一个有错误。到底是怎么回事?