[af]?lex regular expression difference

陌路散爱 提交于 2019-12-12 06:39:41

问题


I don't know how to do this, and I've found no good resources online for how to perform this operation[.] I'm trying to take an annotated EBNF production rule which is a difference between two regular expressions and turn it into a(n a| f?)lex grammar specification rule[.] The problem is that I see no way to do this normally[.]{3} is there a way to do this using Kleene algebra, like the way you can use an empty match with alternation in a context-free grammar[?]


回答1:


What does the EBNF production rule look like (and can you write that in EBNF?)

The set difference A\B between regular expressions is equivalent to intersection with a complement: A&~B: the set of strings matched by A, devoid of any strings matched by B. Neither flex nor alex support such semantics in their regular expression languages.

An expression of this form still denotes a regular language, and therefore has an equivalent automaton, for which a regular expression exists based only on the alternation and Kleene operators. This equivalent expression not easy to find, and it depends on the specific internals of A and B. That is to say, we can't just plug A and B into some general regex formula such that the result denotes the set difference. The original A and B will not appear in the set difference regex.



来源:https://stackoverflow.com/questions/9944361/aflex-regular-expression-difference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!