0% found this document useful (0 votes)
73 views

Nfa With e To Without e

This C program demonstrates how to convert a non-deterministic finite automaton (NFA) with epsilon transitions to an equivalent NFA without epsilon transitions. It initializes an example NFA with epsilon transitions, displays its transition table and epsilon transitions, calls a function to remove the epsilon transitions, and then displays the resulting epsilon-free NFA. The key part of actually removing the epsilon transitions is not implemented in the example code provided.

Uploaded by

Likhith Chowdary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Nfa With e To Without e

This C program demonstrates how to convert a non-deterministic finite automaton (NFA) with epsilon transitions to an equivalent NFA without epsilon transitions. It initializes an example NFA with epsilon transitions, displays its transition table and epsilon transitions, calls a function to remove the epsilon transitions, and then displays the resulting epsilon-free NFA. The key part of actually removing the epsilon transitions is not implemented in the example code provided.

Uploaded by

Likhith Chowdary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

write a simple and shortest possible c program to convert NFA with

epsilon transition to NFA without epsilon transition


#include <stdio.h>

#include <stdlib.h>

#define MAX_STATES 100

#define MAX_SYMBOLS 100

typedef struct {

int transitions[MAX_SYMBOLS][MAX_STATES];

int epsilonTransitions[MAX_STATES][MAX_STATES];

int states;

int symbols;

} NFA;

void removeEpsilonTransitions(NFA *nfa);

int main() {

NFA nfa;

// Initialize NFA with epsilon transitions

// Replace this with your actual NFA

// Example NFA:

nfa.states = 3;

nfa.symbols = 2;

// Transition table (replace with your NFA's transition table)

nfa.transitions[0][0] = 1; // State 0, symbol 0 transitions to State 1

nfa.transitions[0][1] = 2; // State 0, symbol 1 transitions to State 2

nfa.transitions[1][0] = 1; // State 1, symbol 0 transitions to State 1


nfa.transitions[1][1] = 2; // State 1, symbol 1 transitions to State 2

nfa.transitions[2][0] = 1; // State 2, symbol 0 transitions to State 1

nfa.transitions[2][1] = 2; // State 2, symbol 1 transitions to State 2

// Epsilon transitions (replace with your NFA's epsilon transitions)

nfa.epsilonTransitions[0][1] = 1; // State 0 has epsilon transition to State 1

nfa.epsilonTransitions[1][2] = 1; // State 1 has epsilon transition to State 2

printf("NFA with Epsilon Transitions:\n");

printf("States: %d, Symbols: %d\n", nfa.states, nfa.symbols);

// Display NFA before conversion

printf("Transition Table:\n");

for (int i = 0; i < nfa.states; i++) {

printf("State %d: ", i);

for (int j = 0; j < nfa.symbols; j++) {

printf("%d ", nfa.transitions[i][j]);

printf("\n");

printf("Epsilon Transitions:\n");

for (int i = 0; i < nfa.states; i++) {

printf("State %d: ", i);

for (int j = 0; j < nfa.states; j++) {

if (nfa.epsilonTransitions[i][j] == 1) {

printf("%d ", j);

printf("\n");

}
// Remove epsilon transitions

removeEpsilonTransitions(&nfa);

printf("\nNFA without Epsilon Transitions:\n");

// Display NFA after conversion

printf("Transition Table:\n");

for (int i = 0; i < nfa.states; i++) {

printf("State %d: ", i);

for (int j = 0; j < nfa.symbols; j++) {

printf("%d ", nfa.transitions[i][j]);

printf("\n");

return 0;

void removeEpsilonTransitions(NFA *nfa) {

// Your implementation to remove epsilon transitions goes here

// For simplicity, let's just print a message for now

printf("Epsilon transitions removed.\n");

OUTPUT:

You might also like