5

I have been looking out for some algorithm that has in input a regular expression or a string and that converts it into an NFA and then a DFA, and that would actually print out the transition table of the corresponding final DFA.

I'am thus wondering if there is already an algorithm or C or Python library that does that,or if you have suggestions of algorithms to use, that I could implement.

Thank you.

Anoracx
  • 438
  • 7
  • 24
  • 1
    As written, your question is a bit too broad/subjective to answer: you're asking whether you should code it yourself or whether there's an existing library. Questions of those forms aren't really appropriate here on Stack Overflow. Could you update your question to have something more concrete, such as "how do I use library X to solve this problem?" or "what algorithm would be most appropriate here?" – templatetypedef Oct 23 '13 at 20:08
  • Well now, I was asking, if there is an existing library, or if I should implement if from scratch, or (and that's why I mentioned the thomson) If someone knows an algorithm that I could Implement. But I modified a bit of the question, I hope it is more clear. – Anoracx Oct 24 '13 at 11:05
  • http://projectsgeek.com/2011/05/regular-expression-to-dfa-code-in-c-language.html – Grijesh Chauhan Oct 25 '13 at 12:40
  • http://www.sourcecodeonline.com/list?q=regular_expression_to_dfa_conversion_c_code – Grijesh Chauhan Oct 25 '13 at 12:41

1 Answers1

2

I'm not certain if either of these links might help you.

The first provide a very simple NFA/DFA implementation in Python, with conversion from NFA to DFA. It doesn't generate the NFA from a regex though, but it is not so difficult to do. The second site provides a long discussion on NFA vs DFA, including numerous code examples (mostly in C) and links to external libraries that I know little of. The third and fourth links provide the source code of two regex engines implementation developped by the second article's author, including parsing from regex to NFA, then conversion from NFA to DFA. Note however that I haven't had a look at either of these projects.

Otherwise, I would mention that most real world regex engines use NFA, not DFA, because of some extended features that simply can't be performed with a DFA. So if none of hte links above can help you, then you might have some luck looking at compiler-compilers, since they are the ones that actually use DFAs.

James
  • 4,211
  • 1
  • 18
  • 34
  • Thanks for the help, but unfortunately I looked the links up and couldn't find any of the algorithms printing out the state table of the corresponding final DFA. – Anoracx Oct 26 '13 at 15:50
  • They might not already _print_ the transition table, but extracting it from the final computed DFA is simple enough... All you need is to walk over each node, and assign them a unique, sequential identifier. Then walk over the graph once again, and output that node id, the list of possible transitions with the id of the successor node for each transition. Computing the DFA, in structures that you may inspect, really is the harder part. – James Oct 30 '13 at 16:31