Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

bnf - [af]?lex regular expression difference

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[?]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

The set difference AB 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...