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

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.

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.

Optimization of Basic Blocks in Compiler Design

Optimization of Basic Blocks We can apply the optimization process on a basic block. While optimization, there is no need to change the set of expressions computed by the block. The basic...

3 minutes read.

Translation of Array References in Compiler Design

Translation of Array References We can access the elements of an array stored in consecutive blocks very easily and quickly. In a programming language like C and Java, the size of...

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.

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.

Syntax-Directed Translation

Syntax-Directed Translation A context-free-grammar with some additional rules is known as a syntax-directed definition. In SDT, attributes are associated with grammar symbols and rules are associated with productions. The attributes can...

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.

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.

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.

Evolution of Programming Languages in Compiler Design

The Evolution of Programming Languages The first computer came in the 1940s and was programmed in a binary language that told the computer what operations are to be performed and in...

4 minutes read.

SLR 1 Parsing Compiler Design

SLR(1) Parsing It is a simple LR parsing. Most of the function of this parsing is the same as LR(0) parsing. The parsing table for both the parser vary. The SLR(1)...

5 minutes read.

Three-Address Code

Three-Address Code If there is at most one operator on the right side of the instruction, then the instruction will be the three-address code so that no arithmetic expressions are permitted....

2 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.

Switch Case Statement Compiler Design

Case Statement The “case” or “switch” statement is available in various languages. The following is the syntax for the case statement: switch (E)  {             case V1: S1             case V2: S2 ...

1 minute 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.

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.

Run-Time Environments

Run-Time Environments Storage Organization Every target program has its own logical address, and an executable program runs in it. The logical address space has the location for each program value. The...

2 minutes read.

Stack Allocation of Space

Stack Allocation of Space Almost all compilers for languages that use procedure, functions, or methods manage their run-time memory as a stack. Whenever a procedure is called, the local variable's space...

2 minutes read.