When lexing, POSIX provides two rules:

  • Longest match rule: longest initial substring matched by any regular expression is taken as the next token
  • Rule priority: for a particular longest initial substring, the first regular expression that can match determines the token

Sulzmann & Lu Matcher

The Sulzmann & Lu Matcher works in two phases:

  • Try to find the derivatives of a given string using a given regex then see if it’s nullable.
  • Try to work backwards and understand how the last regex matched the string.

Example: Match the string using

As opposed to the Brzozowski algorithm, this matcher will return a value.

This correlates directly to the definition of our regex:

Inductive definition of regular expression

Regular expressions are inductively defined as:

Link to original

Flatten

This function allows us to obtain the string underlying a value:

Mkeps

Finding a (posix) value for recognising the empty string:

Inject

The idea of the injection function is to do the reverse of the derivative function.

The injection function knows what string it should match and tries to figure out how the regular expression matched it. It takes three arguments, , , and .

Lexing

As opposed to our previous matcher, our lexer will take a string and produce a value instead of a boolean.

Records

A record is an indicator within our regular expression which can be used to pull out some specific information we are looking for.

We have a new regex: and an associated value: .

Here is how records are implemented:

Example usage of records

We can use it to extract subpatterns:

Example: email address regex

We can generate a resulting environment:

While Tokens

Simplification

If we simplify after the derivative, then we are building the value for the simplified regular expression, but not for the original regular expression.

Example

For example, we would have and answer how this regular expression matches the empty string with the value . But now we simplify this to and would produce (see mkeps).

Rectification

We want to reverse the simplification.

The old simp returns a rexp, the new simp returns a rexp and a rectification function.

Example

TODO

Rectification of _ + _

Rectification of _ . _

Lexing with Simplification

Environments

Obtaining the “recorded” parts of a value:

1 item under this folder.