【发布时间】:2015-02-24 04:01:06
【问题描述】:
似乎大多数自动机理论的 CS 教科书都包含字母 Σ = {0, 1} 或 Σ = {a, b} 的正则表达式。 p>
Automata 班的许多学生在编写 RegEx 时遇到困难,是否有一个解析器可以接受类似以下示例的内容? Perl RegEx 和类似的语法太不相似而无用。
一些例子:
(0+1)* # All words in the language
(0+1)((0+1)(0+1))* # All words of odd length
0(0+1)*1 # Words starting with 0 and ending with 1
0*+0*10*+0*10*10* # Has at most two 1's
(0+10)(0+1)*(1+10) # Begins with 0 or 10 and ends with 1 or 10
(1+011)* # Every 0 followed by two 1's
在本课和几本教材使用的语法中,*表示匹配0+次,+表示OR。
有什么东西可以做到这一点,还是我应该构建自己的解析器?
【问题讨论】:
-
Regex 语法更接近于 EBNR。
-
EBNR?谷歌搜索这个并没有返回任何有用的东西,我从来没有听说过这个。
-
EBNF,即。增强型 BNF
标签: regex perl computer-science theory automata