-
December 24th, 2011, 11:12 PM
#1
How to write C++ program for a specific finite automata?
Hello there,
I want to write a program for a specific finite automata, e.g., for the RegExp = (a+b)*b. The program should ask for a string input and tell whether the string is VALID or INVALID.
Kindly provide me with the guidelines only, I want write the program myself. Thanks
-
December 25th, 2011, 05:40 PM
#2
Re: How to write C++ program for a specific finite automata?
do you know how to get user input? If not look at <iostream> header and examples with std::cin, std::cout.
You'll need a third party lib for the regex match, unless you have c++ 0x compiler (in which case you can use <regex> header).
program outline would be:
Get user string.
Compare to your regex.
Present result (match/no match)
Repeat or exit.
-
December 28th, 2011, 02:37 AM
#3
Re: How to write C++ program for a specific finite automata?
Thanks Amleto. Your reply is really helpful.
1. I am using Turbo C++, 3.0. How can I know if it contains the regexp header ? or where can I get it if not included with Turbo C++ 3.0 ?
2. Can someone gives me guidelines if I am interested in implementing it myself (without using regexp header) ?
Thanks.
-
December 28th, 2011, 02:50 AM
#4
Re: How to write C++ program for a specific finite automata?
Originally Posted by bringo
Thanks Amleto. Your reply is really helpful.
1. I am using Turbo C++, 3.0.
You must be joking.
That compiler is almost 20 years old. You should be using an ANSI compliant, modern C++ compiler. There are many free ones out there, one being Visual Studio Express, another being gcc.
C++ was standardized in 1998. That compiler you're using is a dinosaur that shouldn't be used if your creating a new C++ program. Legitimate C++ source will fail to compile with that compiler, and it doesn't take a lot to see this:
Code:
#include <iostream>
int main()
{
std::cout << "Hello World";
}
That code must compile with no issues. If it doesn't compile, then get another compiler, pronto.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; December 28th, 2011 at 02:53 AM.
-
December 28th, 2011, 12:05 PM
#5
Re: How to write C++ program for a specific finite automata?
Thanks a lot dear Paul McKenzie. Can you please name a few compilers more ? Can I use C++ (not Visual C++) code in Visual Studio 8 as well ? If yes please tell me initial steps for this. Thanks again.
Design tips for implementing a finite automaton are still awaited....
Thanks
-
December 28th, 2011, 12:25 PM
#6
Re: How to write C++ program for a specific finite automata?
Originally Posted by bringo
Thanks a lot dear Paul McKenzie. Can you please name a few compilers more ? Can I use C++ (not Visual C++) code in Visual Studio 8 as well ?
Visual C++ is not a language. It is just the name of Microsoft's compiler that compiles C++ code, just like "Turbo" was the name of Borland's C++ compiler.
So yes, you can (and must) be able to compile C++ programs in Visual C++, just like the "Hello World" program I posted.
Regard,
Paul McKenzie
-
December 28th, 2011, 12:29 PM
#7
Re: How to write C++ program for a specific finite automata?
Originally Posted by bringo
Design tips for implementing a finite automaton are still awaited....
Do you have the design of the FSA on paper? That is where you start.
Once you do that, then you can build a recursive descent parser to parse the expression using the "on paper" definition of the FSA. Just writing code without having the expression parser formally written on paper, whether it is an FSA, a set of production rules, etc. is not a good idea.
Regards,
Paul McKenzie
-
December 28th, 2011, 03:32 PM
#8
Re: How to write C++ program for a specific finite automata?
Turbo C was absolutely great for its day. I purchased a copy when it was still new and still have it. But the world moves on.
Do a google search for various C++ compilers. If necessary look for Microsoft's Visual C++ Express. For a free product, it is rather awsome. It does lead you into the Microsoft vein of compilers, but that is to be expected.
And do read Paul's note. Draw this out on paper with pencil (or preferably white board and marker) and see what you want to do for each state and how you want to transition between states. The importance of that advice cannot be overstated.
-
January 3rd, 2012, 12:42 AM
#9
Re: How to write C++ program for a specific finite automata?
Thanks a lot. I'm doing advised by paul and bkelly. I have installed Microsoft Visual Studio 8.
I'll soon share the proceedings.
Thanks a lot again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|