Finite State Machine

Finite State Machine

A finite state machine is a simple machine to recognize patterns. It takes a string of symbols as the input and changes its state to another state, but it rests on the given input symbol. The automata have two-state; either they advance to the next state or stick in the same state. The accepted state of automata is when it reaches the final state, and the input symbol is successfully processed.

Finite automata consist of the following:

Q: Finite set of state

?: Finite set of an input symbol

q0: Initial state

F: Final state

?: Transition function

The transition function can be defined as:

?: Q x ??Q

The construction of finite automata

Let consider L(r) is a regular language, and it is recognized by some finite automata(FA)

  • State– It is represented by circles. The state's names are written inside the circles.
  • Start state– Thestarting point of automata is termed as a start state. This state has an arrow coming towards it.
  • Intermediate state– The states with at least two arrows, one is pointing towards them and another pointing out from them.
  • Final state– The final state is depicted by a double circle. Any input string is successfully parsed, then the automata will be expected to be in the final state. The final state may have any odd number of arrows pointing towards them and even numbers of arrows pointing out from them. But the number of the odd arrow will be one greater than the even arrow, i.e., odd = even + 1.
  • Transition– It is the collection of circles or nodes, called state. Each state depicts a condition that could happen during the process of scanning the input. Edges are pointed from one state of transition to another. Each edge is marked by a symbol or set of the symbol.

Finite automata come in two ways:

  • DFA(Determinist finite automata)
  • NDFA(Non deterministic finite automata)

DFA

It stands for deterministic finite automata. For each state 'a' and input symbol b, there is exactly one edge out of a labeled b. A finite automaton is said to deterministic for an input symbol if there exists a unique resultant state. It means for each input; there is only one transition. It represents the uniqueness of computation. It doesn't accept a null value.

DFA has five tuples {Q, ?, q0, F, ?}

Q- Set of all states
?- Finite set of input symbol where ?: Q x ? ?Q
q0- Initial state
F- Final state
?- Transition function

Example

Q = (q0, q1, q2)

? = (0, 1)

q0 = (q0)

F = (q3)

NFA
It stands for non-deterministic finite automata. It does not have any limit on the label of their edges. A finite automaton is said to be non-deterministic: If we have more than one transition state for a single input, then the non-deterministic finite automata accept the null move.

Non-deterministic finite automata consist same five tuples as deterministic finite automata. The only difference is the transition function that is mentioned below:

Transition function:

                           ?: Q x ? ?2Q

We can represent deterministic finite automata (DFA) and non-deterministic fine automata (NFA) by transition graph, where the nodes are state and labeled edges represent the transition function.

Example

Q = (q0, q1, q2)

? = (0, 1)

q0 = (q0)

F = (q3)

Difference between DFA and NFA

S.NDFANFA
1DFA stands for Deterministic Finite Automata.NFA stands for Non-deterministic Finite Automata.
2In DFA, for each pair of state and symbol, the next possible state is unique.In NFA, each pair of state and symbol can have more than one next state. 
3DFA cannot use an empty string.NFA can use a null string.
4It is difficult to constructIt is easier to construct
5Backtracking is may or may not allowBacktracking is allowed
6It requires more space.It requires less space.
7EF can be understood as one machine.NFA can be understood as several little machines.
8All DFA is NFA.Not all NFA is DFA.
9Execution time is less.Execution time is more.

Related Topics

Run-Time Storage Management

Run-Time Storage Management Every executing program has its own logical address space. Logical address space is partitioned into: Code: It is responsible for storing the executable target code. Static: It is used to...

3 minutes read.

Storage Allocation

Storage Allocation The storage allocation represents memory management. The allocation of memory can be done in the following ways: Static AllocationStack AllocationHeap Management Static Allocation: It is a procedure used for the allocation of...

1 minute read.

Basic Blocks and Flow Graphs in Compiler Design

Basic Blocks and Flow Graphs In this section, we are going to learn how to work with basic block and flow graphs in compiler design. Basic Block The basic block is a set...

3 minutes read.

Shift Reduce Parsing in Compiler Design

Like the bottom-up parsing, the shift reduce parser also builds the parse tree from the leaves (bottom) to the root (up). The LR parser is a more versatile variation of...

4 minutes read.

Code Generation

Code Generation The last phase of the compiler is code generation. It is the compiler's back-end that makes multiple passes over the IR before generating the target program. The code generator's...

4 minutes read.

Syntax Analysis Compiler Design

Syntax Analysis This article will describe the parsing method used in the compiler. The grammatical rule of programming language can be constructed with the help of context-free grammars or BNF (Backus–Naur...

3 minutes read.

YACC in Compiler Design

YACC  YACC is known as Yet Another Compiler Compiler. It is used to produce the source code of the syntactic analyzer of the language produced by LALR (1) grammar. The input...

5 minutes read.

LR Parser Compiler Design

LR Parser LR parsing is a type of bottom-up parsing that is used to parse the large class of grammars. Here "L" stands for left-to-right scanning of the input "R" stands...

6 minutes read.

Regular Expression | Compiler Design

Regular Expression A regular expression is a set of patterns that can match a character or string. It can also match alternative characters or strings. The grammar defined by the regular...

3 minutes read.

Derivation and Parse Tree in Compiler Design

Derivation and Parse Tree In this article, we will learn Derivation and Parse Tree. Derivations The parse tree can be constructed by taking a derivational view in which production is treated as rewriting...

4 minutes read.

LEX

LEX Lex is a tool/computer program that generates a Lexical analyzer. Lex is developed by Vern Paxson in C around 1987. Lex works together with the YACC parser generator. It allows...

3 minutes read.

Finite State Machine

Finite State Machine A finite state machine is a simple machine to recognize patterns. It takes a string of symbols as the input and changes its state to another state, but...

3 minutes read.

Target Machine

Target Machine A target machine is a byte-addressable machine. This machine has n general-purpose registers, R0, R1,.....Rn-1. A Simple Target Machine Model has three-address instruction. A full-edged assembly language would have...

3 minutes read.

LALR 1 Parsing | Compiler Design

LALR (1) Parsing The LALR parsing refers to the "lookahead LR" that has many lesser steps than typical parsers based on LR(1) items. For constructing the LALR(1) parsing table, the canonical...

6 minutes read.

Data Flow Analysis in Compiler Design

Data Flow Analysis All the optimization techniques we have learned earlier depend on data flow analysis. DFA is a technique used to know about how the data is flowing in any...

3 minutes read.

LR Parser in Compiler Design

LR Parser The most popular type of bottom-up parsing is LR(K) parsing. The LR() parser scans the input from left – to – right, which is the actual abbreviation of L...

2 minutes read.

Errors in Compiler Design

Introduction Errors in compiler design refer to mistakes or issues that arise during the process of execution of the program. A compiler is a program that translates source code written in...

4 minutes read.

Intermediate-Code Generator Compiler Design

Intermediate-Code Generator The process of translating a source language into machine code for a given target machine is done by intermediate-code. It lies between the high-level language and the machine language....

2 minutes read.

Ambiguity Elimination Compiler Design

Ambiguity Elimination Ambiguity elimination makes the sentence clear and readable. A sentence is grammatically ambiguous if it can produce more than one parse tree for a particular grammar. In this article,...

3 minutes read.

Lexical Analysis in Compiler Design

Lexical Analysis It is the first phase of the compiler. As we know, it is also known as a scanner. The input for lexical analysis is source code. After taking source...

2 minutes read.