0% found this document useful (0 votes)
29 views24 pages

Finite State Automata

Uploaded by

Mariya Shibi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views24 pages

Finite State Automata

Uploaded by

Mariya Shibi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

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

» What is Finite State Automata?

∗ A Finite State Automata (FSA), also known as a Finite State


Machine (FSM), is a mathematical model used to represent
and control the execution of processes that can be in a finite
number of states
∗ Imagine it as a simple computer with a limited amount of
memory. It can only be in one state at a time and transitions
between these states based on the input it receives.

[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

» State Transitiion Tables

∗ We label the transitions of FSA using the conventions:


A transition out of si  S on encountering a symbol symb  Σ
has the label symb
∗ We say a symbol symb is recognized by FSA when the FSA
makes a transition labelled symb.
∗ The transitions in an FSA can be represented in the form of a
State Transition Table (STT).
∗ An STT has one row for each state si and one column for
each symbol symb  Σ

[5/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» State Transition Tables Contd

∗ An entry in STT(si , symb) in the table indicates the id of the


new state entered by the FSA if there exists a transition
labelled symb in state si .
∗ if the FSA does not contain a transition out of state si we
leave STT(si , symb) blank
∗ A state transition can also be represented by a triple (old
state, source symbol, new state).
∗ thus the entry STT(si , symb) = sj and the triple (si , symb,
sj ) are equivalent.

[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

∗ In DFA Transitions are Deterministic , that is at most one


transition exists in state si for a symbol symb
Defintion A deterministic finite state automation (DFA) is an FSA such
that ti  T, t1 ≡ (si , symb, sj )
implies 3! t2  T, t2 ≡ (si , symb, sk )

[8/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» Deterministic FSA

∗ At any point in time DFA would recognize some prefix α of


the source string, possibly the null string.
∗ The operation of DFA is history sensitive because its current
state is a function of the prefix recognized by it.
∗ The DFA halts when all symbols in the source string are
recognized, or an error condition is encountered.
∗ The string is valid if and only if the DFA recognizes every
symbol in the string and find itself in a final state at the end
of the sring.

[9/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» Transition Table

State Next Symbol


d
Start Int
Int Int
STT to recognize integer string

[10/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» Visual Representation

q0 d q1
start

DFA for Integer strings

[11/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» DFA States Description

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

Definition Regular expressions are a generalization of type 3 production


rules.
∗ The regular expression generalizes on Type 3 rules by
premitting multiple occurences of a string form, and
concatenation of strings.

[13/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» Some Regexes

Regular Expression Meaning


r string r
s string s
r .s or rs concatenation of r and s
(r ) same meaning as r
r | s or (r | s) alternation, i.e., string r or string s
(r ) | (s) alternation
[r ] an optional occurrence of string r
(r )∗ 0 or more occurrences of string r
(r )+ 1 or more occurrences of string r
Regular Expression Notation

[14/18]
Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» DFA for integers, real numbers and


identifiers
letter, digit

Id
letter

start s1
digit

digit
. digit
Int s2 Real

digit

DFA for Identifiers and Numeric Literals [15/18]


Introduction Definition Types Deterministic FSA Regular Expressions Building A DFA

» DFA States Description

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

State Next Symbol


l d .
s1 Id int
Id Id
Int Int s2
s2 Real
Real Real
Transition Table for integers, real numbers and identifiers

[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]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy