本文介绍了ocamllex regex语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些基本的ocamllex代码,由我的教授编写,似乎还不错:
I have some basic ocamllex code, which was written by my professor, and seems to be fine:
{ 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.
这表示此处第四行的正则表达式的第一个[
处有错误.发生了什么事?
This indicates that there is an error at the first [
in the regex in the fourth line here. What is going on?
推荐答案
您的文本中似乎带有卷曲的引号(也称为智能引号"-ugh).您需要常规的旧单引号.
You seem to have curly quotes (also called "smart quotes" -- ugh) in your text. You need regular old single quotes.
curly quote: ’
old fashioned single quote: '
这篇关于ocamllex regex语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!