我有一些由我的教授编写的基本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.
这表明这里第四行正则表达式中的第一个[出现了错误。怎么一回事?
发布于 2015-10-10 00:05:37
你的文本中似乎有卷曲引号(也叫“智能引号”)。你需要常规的老单引号。
curly quote: ’
old fashioned single quote: 'https://stackoverflow.com/questions/33048725
复制相似问题