regular-language

Why does Regexp have a timeout method, while in theory they shouldn't?

大兔子大兔子 提交于 2020-01-01 19:51:11
问题 This is a theoretical Computer Science question (Computation Theory). I know that RegExps can take a very long time to calculate. However, from Theory of Computation we know that matching with a Regular Expression can be done extremely fast in a few clock cycles. If RegExps are equivalent to Finite Automata, why RegExps have (or require) a timeout method? Using a DFA, the computation time for matching can be exteremely fast. By RegExps I mean the Regular Expressions pattern matching classes

Split String In JAVA by specific words

微笑、不失礼 提交于 2019-12-31 02:58:05
问题 String S= "multiply 3 add add 3 3 1" I want to get two string arrays The one is {"multiply", "add", "add"} Another out is {"3","3","3",1} How can I get it? I tried to use String operators[] = s.split("[0-9]+"); String operands[] =s.split("(?:add|multiply)"); But, it doesn't work. 回答1: You should use Matcher instead of split : import java.util.regex.Matcher; import java.util.regex.Pattern; ... List<String> operators = new ArrayList<String>(); Matcher m = Pattern.compile("add|multiply").matcher

Finiteness of Regular Language

和自甴很熟 提交于 2019-12-28 06:27:42
问题 We all know that (a + b)* is a regular language for containing only symbols a and b . But (a + b)* is a string of infinite length and it is regular as we can build a finite automata, so it should be finite. Can anyone please explain this? 回答1: Finite automaton can be constructed for any regular language, and regular language can be a finite or an infinite set. Of-course there are infinite sets those are not regular sets. Check the Venn diagram below: Notes : 1. every finite set is a regular

Does order not matter in regular expressions?

余生长醉 提交于 2019-12-23 16:11:59
问题 I was looking at the question posed in this stackoverflow link (Regular expression for odd number of a's) for which it is asked to find the regular expression for strings that have odd number of a over Σ = {a,b} . The answer given by the top comment which works is b*(ab*ab*)*ab* . I am quite confused - a was placed just before the last b* , does this ordering actually matter? Why can't it be b*a(ab*ab*)*b* instead (where a is placed after the first b* ), or any other permutation of it?

Why is the complement of a regular language still a regular language?

橙三吉。 提交于 2019-12-23 12:45:17
问题 According to my textbook, the complement of L1 = A* - L1 is a regular language as long as L1 is a regular language. Doesn't A* also include Context Free languages, Context Sensitive languages, and Recursively Enumerable languages? A*-L1 would include all of them too, wouldn't it? How can it be regular then? Under the representation of a Finite State Machine I understand why the complement is still a regular language. However, I can't understand the theory behind it. Also, A* - L1 = A*

Scheme, When to use Symbols instead of Strings?

主宰稳场 提交于 2019-12-21 18:59:13
问题 I apologize in advance for my primitive english; i will try my best to avoid grammatical errors and such. Two weeks ago i decided to freshen my knowledge of Scheme (and its enlightnings) whilst implementing some math material i got between hands, specifically, Regular Languages from a course on Automata theory and Computation in which i am enrolled. So far, i've been representing alphabets as lists of symbols instead of lists of chars because i want to have letters of variable size. lists of

Scheme, When to use Symbols instead of Strings?

耗尽温柔 提交于 2019-12-21 18:57:22
问题 I apologize in advance for my primitive english; i will try my best to avoid grammatical errors and such. Two weeks ago i decided to freshen my knowledge of Scheme (and its enlightnings) whilst implementing some math material i got between hands, specifically, Regular Languages from a course on Automata theory and Computation in which i am enrolled. So far, i've been representing alphabets as lists of symbols instead of lists of chars because i want to have letters of variable size. lists of

If we know a CFG only generates regular language, can we get the corresponding regular expression?

牧云@^-^@ 提交于 2019-12-21 09:24:46
问题 As we know, given a regular grammar, we have algorithm to get its regular expression. But if the given grammar is context-free grammar (but it only generates regular language), like S->aAb A->bB B->cB|d Is there any existing algorithm that can get the regular expression in general? Thanks! 回答1: In the most general sense, there is no solution. The problem of determining whether a CFG is regular is undecidable (Greibach Theorem, last 3 pages of http://www.cis.upenn.edu/~jean/gbooks/PCPh04.pdf )

RegExp result is not my expected

倾然丶 夕夏残阳落幕 提交于 2019-12-20 05:50:57
问题 My regExp do not get a correct result, I can not find where is mistake. let ori_str = "abcXabcYabcZ" // there are 3 Capital character let pattern = "[A-Z]" let regular = try!NSRegularExpression(pattern: pattern, options: .caseInsensitive) let results = regular.matches(in: ori_str, options: .reportProgress , range: NSMakeRange(0, ori_str.characters.count)) print("results have: \(results.count) count") // log 'result have: 12 count' why 12 without 3 ??? I want to get the Capital Character, then

Why is {a^n a^n | n >= 0} regular?

帅比萌擦擦* 提交于 2019-12-19 11:34:11
问题 I understand the reason and the proof why {a^n b^n | n >= 0} is NOT regular. Why is {a^nb^n | n >= 0} not regular? The solution of one of my exercises is: {a^n a^n | n >= 0} is regular. How can I prove this thesis? 回答1: Yes, Language {a n a n | n >= 0} is a regular language . To proof that certain language is regular, you can draw its dfa/regular expression. And you can drive do for this language as follows: Because " a n a n for n >= 0 " is same as " a 2n for n >=0", and that is "set of all