Skip to content
Back to the collection

Derivatives of Regular Expressions

Janusz A. Brzozowski

1964 · Journal of the ACM

Read the paper
HN score
0
Mentions
5
Readers
4
Months
3
What’s in a score?

In the conversation

Original HN comments, with labels from simple text rules. A label describes the whole comment and may miss context or irony. Read the discussion to make up your own mind. About the labels

5 selected excerpts · 5 total mentions

DonHopkins
Neutral mention · rule
This "derivatives of regular expressions" technique is what James Clark used in the design of the efficient implementation of the Relax/NG tree regular expression based XML validator, based on Janusz A. Brzozowski, "Derivatives of Regular Expressions", Journal of the ACM, Volume 11, Issue 4, 1964. https://relaxng.org/jclark/design.html >Unordered content >SGML provides an & operator: A & B matches A followed by B or B followed by A. XML removed the & operator. RELAX NG reintroduces it with a twist. In SGML, a content model of A & B* requires all the B elements to be consecutive: the required A element cannot occur in between two B elements. Usually, users use the &…
Read the full comment
operator because they want to allow child elements to occur in any order, so this restriction is undesirable. In RELAX NG, the corresponding operator has interleaving semantics. It matches any interleaving of a sequence containing a single A element and a sequence containing zero or more B elements; it thus allows the A element to occur anywhere, including between two B elements. >XML removed the & operator mainly because of the & operator's reputation for implementation complexity. The most difficult part of implementing the & operator in SGML is detecting whether a content model including & is 1-unambiguous. Unlike SGML, XML and W3C XML Schema, RELAX NG does not restrict content models to be 1-unambiguous, so this implementation difficulty is removed. The classic implementation technique for SGML and XML content models is to construct a Glushkov automaton. The 1-unambiguity restriction is helpful for this technique because it ensures that the Glushkov automaton is deterministic. An interleaving operator causes difficulty with this technique. However, there is an alternative implementation technique available [17] based on derivatives of regular expressions [4]. This handles content models that are not 1-unambiguous without any additional effort and can deal with interleaving without difficulty. RELAX NG imposes restrictions on the use of interleave which are sufficient to ensure that a derivative-based implementation will not exhibit exponential behavior. [4] Janusz A. Brzozowski. Derivatives of Regular Expressions. Journal of the ACM, Volume 11, Issue 4, 1964. https://dl.acm.org/doi/10.1145/321239.321249 https://dl.acm.org/doi/pdf/10.1145/321239.321249 [17] Joe English. How to validate XML. 1999. See http://www.flightlab.com/~joe/sgml/validate.html
mananaysiempre
Neutral mention · rule
From my own experiments[1], I suspect your engine might still be prone to exponential blowup: you only get proper linear matching if you reassociate and sort the choice expressions and merge identical terms (and Brzozowski’s original paper[2] does point this out). This makes the implementation quite a bit more annoying. ETA: Yup. Try (successfully) matching (A*)* against a long string of As and watch it die. [1] http://ix.io/4qan/ (matching only), http://ix.io/4qap/ (adds parsing and printing). [2] https://dl.acm.org/doi/10.1145/321239.321249
carapace
Neutral mention · rule
You can use Brzozowski's derivatives of regular expressions[1] to lazily get a state machine from a RE. I made a simple FSM using a trampoline function[2] to imitate a kind of table-drive GOTO design.[3] [1] "Derivatives of Regular Expressions", Janusz A. Brzozowski https://dl.acm.org/doi/10.1145/321239.321249 [2] https://en.wikipedia.org/wiki/Trampoline_(computing)#High-le... [3] http://joypy.osdn.io/notebooks/Derivatives_of_Regular_Expres...

Keep following the thread.

More in Other research

More from the same topics.