is this ok

R

Ricky

thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am
i supposed to do , i just cant get it right.
please have a look at the following code and tell me am i in the right way,
or can i do the covertion from this structure, and if possible (not trying
to bother you) one kind of solution.
thanks much

struct TLink
{
int linkNode;
int stringMax;
int string[5];
};

struct Node
{
int isFinalState;
int max_links;
TLink Link[5];
} NFA[5];

struct DLink
{
int meCilinLidhet;
int stringNo;
int node[5];
};

struct NodeD
{
int stringNode;
int isFinalState;
int max_links;
DLink Link[5];
} DFA[5];

int max_states;
int maxNode;

void NFA_input()
{
int i, j, k, f;
cout<<"\nHow MAny states does the NFA has =";
cin>>max_states;
for (i=0; i<max_states; i++)
{
cout<<"\nIs State q["<<i<<"] final State ? (yes=1, No=0)";
cin>>NFA.isFinalState;
cout<<"\nHow many transitions does this State have ?";
cin>>NFA.max_links;
for (j=0; j<NFA.max_links; j++)
{
cout<<"\nThe "<<j+1<<" transition is linking state q["<<i<<"] with
state =";
cin>>NFA.Link[j].linkNode;
cout<<"\nHow many strings make this transition=";
cin>>NFA.Link[j].stringMax;
for (k = 0; k < NFA.Link[j].stringMax; k++)
{
cout<<"\nEnter those strings=\n";
cout<<"delta["<<k+1<<"]= ";
cin>>NFA.Link[j].string[k];
}
}
}
}

void print_NFA()
{
int i, j, k ;
for (i=0; i<max_states; i++)
{
cout<<"\nState q["<<i<<"]";
for (j=0; j<NFA.max_links; j++)
{
cout<<"\n is linked with state q["<<NFA.Link[j].linkNode<<"]";
cout<<" with string";
for (k = 0; k < NFA.Link[j].stringMax; k++)
cout<<" " <<NFA.Link[j].string[k];
}
cout<<"\n";

}
cout<<"\nInitial State of the automata is:q[0]\n ";
cout<<"\nFinal States of the automata are: ";
for (i=0; i<max_states; i++)
{
if (NFA.isFinalState == 1)
cout<<"\n q["<<i<<"] \t";
}
}
int main()
{
clrscr();
char line[80]="-------------------------------------------------";
NFA_input();
cout<<"\nTranitions of the NFA are: \n";
cout<<line;
print_NFA();
cout<<"\n"<<line;
cin.get(); cin.ignore();
return 0;
}
 
T

Thomas Matthews

Ricky said:
thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am
i supposed to do , i just cant get it right.
please have a look at the following code and tell me am i in the right way,
or can i do the covertion from this structure, and if possible (not trying
to bother you) one kind of solution.
thanks much

I will review your code, but I have no clue what a NFA is. Perhaps you
should not use acronyms or abbreviations, but spell them out.

struct TLink
{
int linkNode;
int stringMax;
int string[5];
};

Why are there 5 int values for the string?
The '5' is a _magic_ number and should be a named constant, such
as:
const unsigned int MAX_NUMBERS_IN_STRING = 5;
Also, do you want signed or unsigned integers. In many communications
scenarios, numbers are unsigned to allow for more range. If the
number is not negative, declare it as unsigned.

struct Node
{
int isFinalState;
int max_links;
TLink Link[5];
} NFA[5];

1. The member "isFinalState" implies a boolean (true / false) type.
You should name it that way:
bool isFinalState;
2. What is with the number '5'? Magic number again. Convert to
a named constant. See above.

struct DLink
{
int meCilinLidhet;
int stringNo;
int node[5];
};

1. What is with the number '5'? Magic number again. Convert to
a named constant. See above.
2. What is the difference between a TLink and a DLink?
Your names are not very descriptive.

struct NodeD
{
int stringNode;
int isFinalState;
int max_links;
DLink Link[5];
} DFA[5];
1. What is with the number '5'? Magic number again. Convert to
a named constant. See above.
1. The member "isFinalState" implies a boolean (true / false) type.
You should name it that way:
bool isFinalState;

int max_states;
int maxNode;

Do these variables _need_ to be global?

void NFA_input()
{
int i, j, k, f;
cout<<"\nHow MAny states does the NFA has =";
cin>>max_states;

1. Since the number of states is dynamic, you may want to
consider allocating them from dynamic memory (i.e. using
'new') and using a dynamic container, such as a vector
or list.

2. You don't check for invalid input. What happens if
the user enters "apple" or "3.14159"?
(I believe the input operation will set the stream's
fail bit or bad bit).
for (i=0; i<max_states; i++)
{
cout<<"\nIs State q["<<i<<"] final State ? (yes=1, No=0)";
cin>>NFA.isFinalState;


Or:
unsigned int yes_no;
NFA.isFinalState = yes_no == 1;

What happens when max_states is 10? You only have 5
elements allocated in your array.

cout<<"\nHow many transitions does this State have ?";

I suggest you flush the output buffer before requesting input:
cout.flush();
cin>>NFA.max_links;


What happens if the number of transitions is 30?
You only have 5 allocated.
What happens when the user enters a negative number, such
as -2? You did allow that by specifying max_links as an
int and not an unsigned int.

for (j=0; j<NFA.max_links; j++)
{
cout<<"\nThe "<<j+1<<" transition is linking state q["<<i<<"] with
state =";
cin>>NFA.Link[j].linkNode;
cout<<"\nHow many strings make this transition=";
cin>>NFA.Link[j].stringMax;
for (k = 0; k < NFA.Link[j].stringMax; k++)
{
cout<<"\nEnter those strings=\n";
cout<<"delta["<<k+1<<"]= ";
cin>>NFA.Link[j].string[k];


Possible array overflow: you only have 5 allocated.
What happens when there are 6, or zero?

[snip -- printing function]
int main()
{
clrscr();

This is not a standard C++ function. Do you really need the
screen cleared? The program will be more portable with out it.
For example, in some operating systems, you could redirect the
output of your program into a file. How does clearing the
screen work with redirecting the output?
char line[80]="-------------------------------------------------";
NFA_input();
cout<<"\nTranitions of the NFA are: \n";
cout<<line;
print_NFA();
cout<<"\n"<<line;
cin.get(); cin.ignore();
return 0;
}

Summary
-------
I believe you don't have an efficient data structure. Your
implied requirements allow a dynamic amount of states and
transitions. Fixed sized arrays are very bad for dynamic
quantities of elements. Your I/O is not checked for
boundary conditions or stream failures. Your naming
conventions could use improvement for better readability.

You need to use pointer when dealing with dynamic structures.
If you insist on arrays, place a pointer in your structure
and allocate the array at run-time. You will need to
remember the size of the array because the C++ language
does not provide a sizeof() operation for dynamic arrays.
A std::vector is much safer, and also handles dynamic
expansion.

Your nodes have a common set of members (maybe methods
too), you should factor out the commonalities into
a base class:
struct BaseState
{
bool is_final_state;
unsigned int max_states;
};

struct Node
: public BaseState
{
TLink * links;
};

struct DNode
: public BaseState
{
int stringNode;
DLink * links;
};


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
V

Victor Bazarov

angelayoub said:
Dear sir,

What if I'm a madam?
I am so pleased to write you,and i want on this opportunity to thank you
about your help,i was wondering if you would mind helping me to write a C
program that convert a NFA to an equivalent DFA,i found this program in C++
program but i haven't studied it yet at the university.
I am looking forward to getting you answer.

Here is my answer. Read carefully. First, this is a C++ newsgroup.
If you need help with a C program, you're in a wrong place. Please
consider posting to comp.lang.c. Second, if you need some program
written, you're better off contacting your fellow students from the
university. We here don't write programs to strangers. If you want
to hire somebody, consider posting to misc.jobs.offered. Third, if
this is your first time here, consider reading the Welcome message
posted here weekly by Shiva, and the FAQ list. You can find the FAQ
here: http://www.parashift.com/c++-faq-lite/ and the Welcome message
is duplicated at http://www.slack.net/~shiva/welcome.txt. Fourth,
please don't post FIVE TIMES. Be patient, it takes a few minutes
for the people around the globe to see your posting and reply.

There is probably more that you could correct about the way you
posted. I'll leave it to others.

Good luck with your studies!
 
J

Jonathan Turkanis

Victor Bazarov said:
What if I'm a madam?
thank you
about your help,i was wondering if you would mind helping me to write a C
program that convert a NFA to an equivalent DFA,i found this program in C++
program but i haven't studied it yet at the university.

Here is my answer. Read carefully. <snip>

Yes. And please don't send unsolicited email.

Jonathan
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a Non deterministic Finite Automat to an equivalent Deterministic Finite Automata,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
A

angelayoub

Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub
 
P

Phlip

angelayoub said:
I am so pleased to write you,and i want on this opportunity to thank you
about your help,i was wondering if you would mind helping me to write a C
program that convert a NFA to an equivalent DFA,i found this program in C++
program but i haven't studied it yet at the university.
I am looking forward to getting you answer.

Please read this: http://www.slack.net/~shiva/welcome.txt

You are posting to a USENET newsgroup that has different abilities, hence
different rules, from www.talkaboutprogramming.com .

You should expect 24~36 hours before getting an answer. Repeating the
question will annoy the people capable of answering. Further,
www.talkaboutprogramming.com might not be able to show you your own post in
this list for a while.

The only answer for your sparse question is more questions:

Have you used Google.com to search for a C version?

Have you used Google to search for a forum that discusses NFA or DFA?

Why do you think you need C, just because you have not learned to write C++?

Have you tried to compile the source you have?

Have you tried to contact the forum most closely related to the source you
have - such as it's author's favorite mailing list?

Could you read the source and look up the keywords you don't know in a C++
tutorial? (Relying only on a university for an education is very limiting.
You will not make it in the Real World without the ability to teach yourself
new languages.)
 
A

angelayoub

I am so pleased to write you,and i want on this opportunity to thank
you
about your help,i was wondering if you would mind helping me to write a
C
program that convert a NFA to an equivalent DFA,i found this program in
C++
program but i haven't studied it yet at the university.
 
T

Thomas Matthews

angelayoub said:
I am so pleased to write you,and i want on this opportunity to thank
you
about your help,i was wondering if you would mind helping me to write a
C
program that convert a NFA to an equivalent DFA,i found this program in
C++
program but i haven't studied it yet at the university.

By the number of posts in thes newsgroup, I'd say you are not.
You don't read the reply's by others (hmm, so what makes me
think the OP will read this one?).

Use your favorite search engine and search the following
newsgroups, using the terms "NFA DFA convert"
(your best bet)
(for questions about the C language)


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
J

Jerry Coffin

Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.

First of all, it looks a great deal as if your news program is mis-
configured, or else you're expecting Usenet to be somewhat different
than it really is -- I'm seeing about a half dozen copies of your post.

In any case, almost any decent book on compiler construction will cover
NFA to DFA conversion. The usual recommendation in this is area is
"Compilers: Principles, Techniques and Tools", but Aho, Sethi and
Ullman, generally known as The Dragon Book, due to the picture on the
cover (of a knight in armor slaying a dragon).
 
A

angelayoub

I was wondering if would someone mind giving a C program that minimizate the states of DFA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,795
Messages
2,569,644
Members
45,359
Latest member
1854578

Latest Threads

Top