我有一些基本的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.
这表示此处第四行正则表达式中的第一个[
出错。发生了什么事?
答案 0 :(得分:3)
您的文字中似乎有卷曲引号(也称为“智能引号” - 呃)。你需要定期的旧单引号。
curly quote: ’
old fashioned single quote: '