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.
這表明有在這裏第四行的正則表達式中的第一個[
錯誤。到底是怎麼回事?