2015-10-09 24 views
0

我有一些基本的ocamllex代码,这是写的我的教授,似乎是罚款: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.

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

回答

3

你的文字似乎有卷曲的引号(也叫“聪明引号” - 唉)。你需要经常使用旧的单引号。

curly quote: ’ 
old fashioned single quote: '