Académique Documents
Professionnel Documents
Culture Documents
Examples
A dfa for regular expressions on the
alphabet
S = { a, b, c }
a. Which have exactly one b:
Examples (Cont. 1)
b. Which have 0 or 1 b's:
Examples (Cont. 2)
A dfa for a number with an optional fractional
part (assume S = { 0,1,2,3,4,5,6,7,8,9,+,-,. }:
Constructing DFA
Regular expressions give us rules for recognizing
the symbols or tokens of a programming
language.
The way a lexical analyzer can recognize the
symbols is to use a DFA (machine) to construct a
matrix, or table, that reports when a particular
kind of symbol has been recognized.
In order to recognize symbols, we need to know
how to (efficiently) construct a DFA from a regular
expression.
NFA Example
Examples
a f.a. for ab*:
a f.a. for ad
To obtain a f.a. for: ab* | ad
We could try:
Examples (Cont. 1)
So, then we could try:
Examples (Cont. 2)
Example of a NFA with epsilon-transitions:
Example
Example (Cont.1)
Next, construct the closure: ( letter | digit )*
letter
digit
Example (Cont.2)
Now, finish the construction for: letter ( letter | digit )*