Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
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.
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.
https://gist.github.com/Arachnid/491973
http://swtch.com/~rsc/regexp/
https://code.google.com/p/re1/source/browse/
https://code.google.com/p/re2/source/browse/
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.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm aware regular expressions, as a concept, represent a single Regular Language, which can be processed via a DFA/NFA with O(n) ~O(2^m) complexity, being n the size of the string and m the size of the regex. Most stack-overflow discussions about the subject quote this awesome article that proves it.
However, regex implemented in modern languages deal with more than regular languages. For instance, it's possible to recognize palindromes with regex, a context-free grammar problem that, when solved via a push-down automata(PDA), is known to have a O(n³) complexity.
I would like to know were exactly in the Extended Chomsky Hierarchy modern (perl or python re, for example) regex implementations fit, or, at least, their worst possible complexity.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for suggestions of portable lightweight libraries written in C++, that support mathematical and business rule expression and evaluation. I understand C++ doesn't provide such functionality in the STL.
The basic requirement is as follows:
The expressions to be evaluated will be comprised of numbers and strings and variables either representing numbers or strings.
Some of the expressions are expected to be evaluated many times per second (1000-2000 times), hence there is a requirement for high performance evaluations of the expressions.
Originally the project at my company, we encode all the business rules as classes that derived from a base expression class. The problem is that this approach does not scale well as the number of expressions increases.
I've googled around, but most "libraries" I could find are pretty much simple examples of the shunting yard algorithm, most of the expression parsers, perform parsing and evaluation in the same step making them unsuitable for continuous reevaluations, and most only support numbers.
What I'm looking for:
Library written in C++ (C++03 or C++11)
Stable/production worthy
Fast evaluations
Portable (win32/linux)
Any suggestions for building high performance business rules engine.
Example business rule:
'rule_result = (remaining_items < min_items) and (item == "beach ball")'
See the C++ Mathematical Expression Library outlined in this answer.
But, if you really want speed, consider compiling the expressions as C/C++ directly, then load them dynamically (shared objects/DLLs).
Have you considered generating your own parser with Bison + Flex? It uses a FSM-based LALR parser implementation that is fast and is easy to write, and supports evaluation of expressions while you're parsing them, as well as AST generation for repeated evaluation.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need a library which will take in two regular expressions and determine whether they are isomorphic (i.e. match exactly the same set of strings or not)
For example a|b is isomorphic to [ab]
As I understand it, a regular expression can be converted to an NFA which in some cases can be efficiently converted to a DFA. The DFA can then be converted to a minimal DFA, which, if I understand it correctly, is unique and so these minimal DFA's can then be compared for equality. I realize that not all regular expression NFA's can be efficently transformed into DFA's (especially when they were generate from Perl Regexps which are not truly "regular") in which case ideally the library would just return an error or some other indication that the conversion is not possible.
I see tons of articles and academic papers on-line about doing this (and even some programming assignments for classes asking students to do this) but I can't seem to find a library which implements this functionality. I would prefer a Python and/or C/C++ library, but a library in any language will do. Does anyone know if such a library? If not, does someone know of a library that gets close that I can use as a starting point?
Haven't tried it, but Regexp:Compare for Perl looks promising: two regex's are equivalent if the language of the first is a subset of the second, and vice verse.
The brics automaton library for Java supports this.
It can be used to convert regular expressions to minimal Deterministic Finite State Automata, and check if these are equivalent:
public static void isIsomorphic(String regexA, String regexB) {
Automaton a = new RegExp(regexA).toAutomaton();
Automaton b = new RegExp(regexB).toAutomaton();
return a.equals(b);
}
Note that this library only works for regular expressions that describe a regular language: it does not support some more advanced features, such as backreferences.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have looked at the following software tools:
Ragel
ANTLR
BNF Converter
Boost::Spirit
Coco/R
YACC
ANTLR seems the most straight-forward, however its documentation is lacking.
Ragel looks possible, too, but I do not see an easy way to convert BNF into its syntax.
What other tools are available that can take BNF input and generate a corresponding, Unicode-friendly, cross-platform, standalone, C++ parser?
Many thanks for all suggestions.
Edit: Changed Objective-C requirement to C++.
Try boost.spirit 2.
The boost spirit user list is very active and answers are quick from the authors.
TDParseKit! (Most specifically, this page on Objective-C parser generation with BNF grammars)
Have you looked at QLALR? It is a creative Friday project from QtDF. I have not tried it personally, but the trolls seems to be pragmatic about their approach to problems, so I guess this is too.
You can try GOLD Parser! It's a great tool for parsing and generating. With a simple UI, all what you need to do is to provide a valid grammar file and select your favored programming languages for your output code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a regular expression tutorial that doesn't use a designer?
I learned the basics of RegEx with this tutorial
It talks about what happens behind the scenes and doesn't depend on a certain platform.
This is a great and quick getting started guide:
The absolute bare minimum every programmer should know about regular expressions
Check out Expresso I have used it in the past to build my RegEx. It is good to help learning too. Not really a tutorial but you can test out regex's with it.
RegEx Buddy, while also not a tutorial in itself, has been one of the best tools for me. The on the fly highlighting helps.
RegexBuddy is also nice, if I may add. There is a variety of similr tools available. A simple google search "regex tool" reveals most of them.
As far as for the tutorial, I can recommend the book "Mastering Regular Expressions" (I read the first, there is probably a newer edition by now)