Lexical analysis

Regular Expressions

Parse a regular expression, see its structure, list the strings it denotes, and test or compare strings and expressions.

  • Lecture reference: Lexical Analysis · slides 19–34
  • Lecture reference: Lexical Analysis II · slide 4

Expression

From the slides

Lecture reference: Lexical Analysis · slide 29
  • identifier = ?

    Show answer

    letter (letter | digit)*

  • Is (letter* | digit*) the same?

    Show answer

    No. (letter* | digit*) contains "" and strings of digits such as "42", and it does not contain strings that mix letters and digits, such as "a1".

Structure

letter (letter | digit)* Concatenation L(AB) = { ab | a ∈ L(A) and b ∈ L(B) }
(letter | digit)* Iteration (Kleene closure) L(A*) = { "" } ∪ L(A) ∪ L(AA) ∪ …
letter | digit Choice/Alternation L(A | B) = { s | s ∈ L(A) or s ∈ L(B) }

Language

infinite Minimal DFA: 2 states
6

Shortlex order: shorter strings first, then by symbol. Strings of up to 6 symbols; the first 200 are listed.

Number of strings of each length
LengthStrings
00
152
23,224
3199,888
412,393,056
5768,369,472
647,638,907,264
72,953,612,250,368
8183,123,959,522,816

Test strings

  1. in L(R)
  2. not in L(R)

    No string in L(R) starts with '2'. Allowed first: letter.

  3. not in L(R)

    The shortest string in L(R) is "A".

Type \t, \n, \r for a tab, newline, or return, and \\ for a backslash.

Compare

L(R) ≠ L(R₂) R and R₂ denote different languages.
Shortest string in L(R) but not in L(R₂)
"A0"
Shortest string in L(R₂) but not in L(R)
""

Only in L(R)

In both

Only in L(R₂)

Examples of up to 8 symbols in shortlex order, at most 8 per column.