Lab - 01 DFA Simulation
Lab - 01 DFA Simulation
Introduction
Objectives
Tools/Software Requirement
Description
Practice Task
S0 S1
CODE:
#include <iostream>
ifint(valid)
main({) {
char
int index
input[100];
= 0;
ints0:
valid = 1;
intifsize
( index
= 0;== size) {
// Code
coutfor
<<checking
" String isvalidity
Accepted";
of input
do {goto endprogram;
}cout << "\n Enter next character – Press 2 for input termination ";
cin >>
else if (input[size];
input[index] == ‘a’ || input [index] == ‘b’){
if (index++;
input[size] == ‘a’ || input[size] == ‘b’ || input[size] == ‘2’ )
size++;
goto s1;
}else {
s1:valid = 0;
if (cout<<"You
index == size)
entered
{ the wrong input character. Program terminated!";
break;
cout << " String is Rejected";
} goto endprogram;
} while
} ( input[size-1] != ‘2’ || size < 100 );
goto s0;
}
1. Consider the following Regular Expression:
a(bb)*bc
a. Draw a DFA for the above RE.
b. Determine the language accepted by this automaton
c. Implement this DFA in C/C++/Java.
i. Your implementation should validate the input string for alphabet
i.e. ∑ = {a, b, c}, before using it in the DFA.
ii. Your first implementation of DFA should use goto statements only.
iii. Your second implementation of DFA should use switch statement
instead of the goto’s.
d. Test your implementation using the following inputs:
abc, abbc, abcd, abbbc, abbbbc
L(M) = {w | w € {a, b}* and contains even number of a’s and b’s}