Finite State Automata
Finite State Automata
[1/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Contents
Introduction
Definition
Types
Deterministic FSA
Regular Expressions
Building A DFA
[2/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
[3/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Definition
Definition
Finite state automata is 3 tuple(S, Σ,T) where
S A finite set of states, one of which is the initial
state sinit .
Σ The alphabet, of source symbols.
T is a finite set of state transitions defining transitions
out of each si S on encountering the symbols Σ.
[4/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
[5/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
[6/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Types
∗ Deterministic FSA
∗ Non Deterministic FSA
[7/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Deterministic FSA
[8/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Deterministic FSA
[9/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Transition Table
[10/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Visual Representation
q0 d q1
start
[11/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
q0 Initial state
q1 Valid identifier state (accepts only integer strings)
Accepts:
∗ Literals: 42, 314, 1234 100
[12/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Regular Expressions
[13/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Some Regexes
[14/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
Id
letter
start s1
digit
digit
. digit
Int s2 Real
digit
s1 Initial state
Id Valid identifier state (accepts letters, digits)
Int Integer literal state
s2 Decimal point after integer state (not a final state)
Real Decimal point state
Accepts:
∗ Identifiers: x, name, my_var, temp1
∗ Literals: 42, 3.14, 0.123, 100
[16/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» Transition Table
[17/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
∗ Goes to the same state Id for digits and letters as input
symbols
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
∗ Goes to the same state Id for digits and letters as input
symbols
∗ Goes to Int state from Start state if a digit is received as the
input symbol
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
∗ Goes to the same state Id for digits and letters as input
symbols
∗ Goes to Int state from Start state if a digit is received as the
input symbol
∗ Goes to the same state Int for Consecutive digit input symbols
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
∗ Goes to the same state Id for digits and letters as input
symbols
∗ Goes to Int state from Start state if a digit is received as the
input symbol
∗ Goes to the same state Int for Consecutive digit input symbols
∗ Goes to s2 state from Int state if a decimal point received as
the input symbol
[18/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA
» DFA Flow
∗ Start State
∗ Goes to Id state from Start if Letter is the first input symbol
∗ Goes to the same state Id for digits and letters as input
symbols
∗ Goes to Int state from Start state if a digit is received as the
input symbol
∗ Goes to the same state Int for Consecutive digit input symbols
∗ Goes to s2 state from Int state if a decimal point received as
the input symbol
∗ Goes to Real state for further digits as input symbols
[18/18]