CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2011
    Posts
    7

    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

  2. #2
    Join Date
    Apr 2008
    Posts
    725

    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    7

    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to write C++ program for a specific finite automata?

    Quote Originally Posted by bringo View Post
    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.

  5. #5
    Join Date
    Dec 2011
    Posts
    7

    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

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to write C++ program for a specific finite automata?

    Quote Originally Posted by bringo View Post
    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

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to write C++ program for a specific finite automata?

    Quote Originally Posted by bringo View Post
    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

  8. #8
    Join Date
    Nov 2011
    Posts
    72

    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.

  9. #9
    Join Date
    Dec 2011
    Posts
    7

    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
  •  





Click Here to Expand Forum to Full Width

Featured