Dr. B.C.
Roy Engineering College
TOPIC TITLE :- Regular Expressions and RE to NFA
PRESENTED BY :- ANKIT KUMAR
SUBJECT :- COMPILER DESIGN
CLASS :- CSE 2
UNIVERSITY ROLL NO :- 12000123127
SEMESTER :- 5
1 . Introduction
What are Regular Expressions?
Regular expressions (regex) are sequences of characters that define
search patterns, primarily used for string matching and manipulation
in text processing. They provide a concise and flexible means for
identifying patterns in strings, and are widely used in programming
languages, search engines, and text editors.
What is an NFA?
A Nondeterministic Finite Automaton (NFA) is a theoretical machine used in
computer science to recognize
patterns defined by regular expressions. Unlike Deterministic Finite Automata
(DFA), NFAs can have multiple
transitions for the same input from any given state, and can include
transitions that consume no input (ε-transitions).
2 .Types of Regular Expressions
1 . There are different types of regular expressions,
including basic and extended.
2 . Basic regular expressions have limited syntax,
while extended ones offer additional features.
3 . Understanding the differences helps in choosing
the correct type for a specific task
3 . Basics of Regular Expressions
Definition and Syntax
Alphabet (Σ): A finite set of symbols.
•Regular Expressions: Descriptions of patterns over the alphabet Σ.
• They can be constructed using:
•Literal characters: Single characters (e.g., a, b).
•Concatenation: Sequence of charactes (e.g., ab).
•Alternation: Either of two patterns (e.g., a|b).
•Kleene star: Zero or more occurrences of a pattern (e.g., a*).
4 . Introduction to Finite Automata
•Deterministic Finite Automaton (DFA): A finite state machine
where each state has exactly one transition per input symbol.
•Nondeterministic Finite Automaton (NFA): A finite state
machine where each state can have zero, one, or multiple transitions
per input symbol, including ε-transitions.
NFA Characteristics
•Multiple transitions: A state can transition to multiple states for
the same input.
•ε-transitions: Transitions that do not consume any input symbols.
5 . Converting Regular Expressions to NFA
1 . The conversion process involves constructing an
NFA that accepts the same language as the regular
expression.
2 . This process typically uses Thompson's
construction algorithm for systematic conversion.
3 .Each component of the regular expression is
translated into a corresponding NFA segment.
6 .Thompson's Construction Algorithm
Basic Concepts
1 . The construction begins by breaking down the
regular expression into its basic components.
2 . Each component is translated into simple NFAs,
which are then combined using union and
concatenation rules.
3 . The final NFA is built by connecting these simple
NFAs according to the structure of the regular
expression.
7 . Applications of Regular Expressions and NFA
Lexical Analysis
•Token recognition in compilers and interpreters.
Network Security
•Intrusion detection systems use regex to identify
malicious patterns in network traffic.
Other Applications
•Data validation (e.g., email, phone numbers).
•Syntax highlighting in code editors.
8 . Conclusion
•Regular expressions describe patterns in strings using concise syntax.
•NFAs are theoretical models used to recognize these patterns.
•Thompson's construction algorithm systematically converts regular
expressions to NFAs.
•Understanding this conversion is fundamental to text processing and
lexical analysis.
•Thank You for Your Attention
ANKIT KUMAR