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
- Lecture reference: Lexical Analysis II
Expression
From the slides
Lecture reference: Lexical Analysis
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 Regular definition letter = 'A' | … | 'Z' | 'a' | … | 'z' (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) } letter Regular definition letter = 'A' | … | 'Z' | 'a' | … | 'z' digit Regular definition digit = '0' | '1' | '2' | … | '9' Language
infinite Minimal DFA: 2 states
Shortlex order: shorter strings first, then by symbol. Strings of up to 6 symbols; the first 200 are listed.
| Length | Strings |
|---|---|
| 0 | 0 |
| 1 | 52 |
| 2 | 3,224 |
| 3 | 199,888 |
| 4 | 12,393,056 |
| 5 | 768,369,472 |
| 6 | 47,638,907,264 |
| 7 | 2,953,612,250,368 |
| 8 | 183,123,959,522,816 |
Test strings
- in L(R)
- not in L(R)
No string in L(R) starts with '2'. Allowed first: letter.
- 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.