nfa

How to implement regular expression NFA with character ranges?

自古美人都是妖i 提交于 2019-12-18 05:14:46
问题 When you read such posts as Regex: NFA and Thompson's algorithm everything looks rather straightforward until you realize in real life you need not only direct characters like "7" or "b", but also: [A-Z] [^_] . namely character classes (or ranges). And thus my question -- how to build NFA using character ranges? Using meta-characters like "not A", "anything else" and then computing overlapping ranges? This would lead to using tree-like structure when using final automaton, instead of just a

drawing minmal DFA for the given regular expression

房东的猫 提交于 2019-12-17 06:51:14
问题 What is the direct and easy approach to draw minimal DFA , that accepts the same language as of given Regular Expression(RE) . I know it can be done by: Regex ---to----► NFA ---to-----► DFA ---to-----► minimized DFA But is there any shortcut way? like for (a+b)*ab 回答1: Regular Expression to DFA Although there is NO algorithmic shortcut to draw DFA from a Regular Expression(RE) but a shortcut technique is possible by analysis not by derivation, it can save your time to draw a minimized dfa.

Show that the following set over {a,b} is regular

守給你的承諾、 提交于 2019-12-10 16:33:41
问题 Given the alphabet {a, b} we define N a (w) as the number of occurrences of a in the word w and similarly for N b (w) . Show that the following set over {a, b} is regular. A = {xy | N a (x) = N b (y)} I'm having a hard time figuring out where to start solving this problem. Any information would be greatly appreciated. 回答1: Yes it is regular language! Any string consists if a and b belongs the language A = {xy | N a (x) = N b (y)} . Example: Suppose string is: w = aaaab we can divide this

Find the regular expression for the language on E={a,b}

安稳与你 提交于 2019-12-08 13:11:36
问题 L = w : (na(w) - nb(w)) mod 3 /= 0 How can I go about finding the regular expression for this language? I understand that it means that the number of As minus the number of Bs cannot be a multiple of 3. So a - b cannot be 3,6,9,12, etc. But I am still having trouble putting it into a regular expression. I tried first making it a DFA or NFA but I couldn't do that either. Any help is appreciated! 回答1: I would go about it by dividing the list of words on {a,b} into three cases: L1 = w : (na(w) -

Efficient algorithm for converting a character set into a nfa/dfa

依然范特西╮ 提交于 2019-12-05 20:17:48
问题 I'm currently working on a scanner generator. The generator already works fine. But when using character classes the algorithm gets very slow. The scanner generator produces a scanner for UTF8 encoded files. The full range of characters (0x000000 to 0x10ffff) should be supported. If I use large character sets, like the any operator '.' or the unicode property {L}, the nfa (and also the dfa) contains a lot of states ( > 10000 ). So the convertation for nfa to dfa and create the minimal dfa

Convert a NFA to Regular Expression

南笙酒味 提交于 2019-12-05 16:06:05
I found a same question on this website, and the answer was a PDF describing how to convert an NFA to a regex . But this is not working because this method has some conditions: There are transitions going from the initial state to all other states, and there are no transitions into the initial state. There is a single accept state that has only transitions coming into it (and no outgoing transitions). The accept state is distinct from the initial state. Except for the initial and accepting states, all other states are connected to all other states via a transition. In particular, each state

Efficient algorithm for converting a character set into a nfa/dfa

☆樱花仙子☆ 提交于 2019-12-04 02:40:27
I'm currently working on a scanner generator. The generator already works fine. But when using character classes the algorithm gets very slow. The scanner generator produces a scanner for UTF8 encoded files. The full range of characters (0x000000 to 0x10ffff) should be supported. If I use large character sets, like the any operator '.' or the unicode property {L}, the nfa (and also the dfa) contains a lot of states ( > 10000 ). So the convertation for nfa to dfa and create the minimal dfa takes a long time (even if the output minimal dfa contains only a few states). Here's my current

How to find the intersection of two NFA

删除回忆录丶 提交于 2019-12-01 07:46:13
In DFA we can do the intersection of two automata by doing the cross product of the states of the two automata and accepting those states that are accepting in both the initial automata. Union is performed similarly. How ever although i can do union in NFA easily using epsilon transition how do i do their intersection? You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for each state (q i , r j ) in the cross-product automaton, you add an ε-transition from that state to each pair of states (q k , r j )

How to find the intersection of two NFA

和自甴很熟 提交于 2019-12-01 04:26:24
问题 In DFA we can do the intersection of two automata by doing the cross product of the states of the two automata and accepting those states that are accepting in both the initial automata. Union is performed similarly. How ever although i can do union in NFA easily using epsilon transition how do i do their intersection? 回答1: You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for each state (q i , r j )

How are finite automata implemented in code?

空扰寡人 提交于 2019-11-30 07:09:13
问题 How does one implement a dfa or an nfa for that matter in Python code? What are some good ways to do it in python? And are they ever used in real world projects? 回答1: A straightforward way to represent a DFA is as a dictionary of dictionaries. For each state create a dictionary which is keyed by the letters of the alphabet and then a global dictionary which is keyed by the states. For example, the following DFA from the Wikipedia article on DFAs can be represented by a dictionary like this: