Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top