3 ms·
Well said. I will include this in the article. Couldn't figure out how to say it well before because they are still not equivalent to context-free languages, th
by pkrumins 17y ago
Well said. I will include this in the article. Couldn't figure out how to say it well before because they are still not equivalent to context-free languages, they are just sometimes powerful enough to describe some of the context-free languages. Therefore I didn't include it. I think only the regex implementations with recursion are context-free. Others are not, therefore I wouldn't say "most" of them are.
You're right that I was surprised because I hadn't heard of recursive regular expressions in Perl before.
Update: I just remembered that extended regular expressions can even recognize recursive languages. Here is a regex that decides if the number is a prime:
perl -lne '(1x$_) !~ /^1?$|^(11+?)\1+$/ && print "$_ is prime"'
This goes beyond context-free, therefore I couldn't just say "context-free" carelessly in the article.
- baddox 17y agoTechnically, a CFG is the intersection of an n-balanced parentheses language and a regular language. Therefore, any regular language can be described by a CFG (but obviously not vice-versa). I am completely unfamiliar with Perl and its regular expressions, but from your article and this comment I get the impression that they are Turing-complete, which would mean they're capable of describing any formal language as well as doing any "doable" computation. Is that correct?
- pkrumins 17y agoJust found this comment. I am not exactly sure if they are Turing-complete. The code in (??{code}) can be anything, so I guess, they are.