0

我有一些基本的 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.

这表明[这里第四行的正则表达式的第一个有错误。到底是怎么回事?

4

1 回答 1

3

您的文本中似乎有弯引号(也称为“智能引号” - 呃)。您需要常规的旧单引号。

curly quote: ’
old fashioned single quote: '
于 2015-10-10T00:05:37.113 回答