76 For example, if you use in <A HREF="http://www.python.org">Python</A> or |
76 For example, if you use in <A HREF="http://www.python.org">Python</A> or |
77 in <A HREF="http://www.ruby-lang.org/en/">Ruby</A> (or also in a number of other mainstream programming languages) the |
77 in <A HREF="http://www.ruby-lang.org/en/">Ruby</A> (or also in a number of other mainstream programming languages) the |
78 innocently looking regular expression <code>a?{28}a{28}</code> and match it, say, against the string |
78 innocently looking regular expression <code>a?{28}a{28}</code> and match it, say, against the string |
79 <code>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</code> (that is 28 <code>a</code>s), you will soon notice that your CPU usage goes to 100%. In fact, |
79 <code>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</code> (that is 28 <code>a</code>s), you will soon notice that your CPU usage goes to 100%. In fact, |
80 Python and Ruby need approximately 30 seconds of hard work for matching this string. You can try it for yourself: |
80 Python and Ruby need approximately 30 seconds of hard work for matching this string. You can try it for yourself: |
81 <A HREF="http://www.dcs.kcl.ac.uk/staff/urbanc/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.py">catastrophic.py</A> (Python version) and |
81 <A HREF="http://talisker.inf.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.py">catastrophic.py</A> (Python version) and |
82 <A HREF="http://www.dcs.kcl.ac.uk/staff/urbanc/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.rb">catastrophic.rb</A> |
82 <A HREF="http://talisker.inf.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.rb">catastrophic.rb</A> |
83 (Ruby version). Here is a similar problem in Java: <A HREF="http://www.dcs.kcl.ac.uk/staff/urbanc/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.rb">catastrophic.java</A> |
83 (Ruby version). Here is a similar problem in Java: <A HREF="http://talisker.inf.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/catastrophic.rb">catastrophic.java</A> |
84 </p> |
84 </p> |
85 |
85 |
86 <p> |
86 <p> |
87 You can imagine an attacker |
87 You can imagine an attacker |
88 mounting a nice <A HREF="http://en.wikipedia.org/wiki/Denial-of-service_attack">DoS attack</A> against |
88 mounting a nice <A HREF="http://en.wikipedia.org/wiki/Denial-of-service_attack">DoS attack</A> against |
99 nearly all regular expression matchers using the POSIX rules are actually buggy. |
99 nearly all regular expression matchers using the POSIX rules are actually buggy. |
100 </p> |
100 </p> |
101 |
101 |
102 <p> |
102 <p> |
103 On a rainy afternoon, I implemented |
103 On a rainy afternoon, I implemented |
104 <A HREF="http://www.dcs.kcl.ac.uk/staff/urbanc/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/re3.scala">this</A> |
104 <A HREF="http://talisker.inf.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/progs/re3.scala">this</A> |
105 regular expression matcher in Scala. It is not as fast as the official one in Scala, but |
105 regular expression matcher in Scala. It is not as fast as the official one in Scala, but |
106 it can match up to 11,000 <code>a</code>s in less than 5 seconds without raising any exception |
106 it can match up to 11,000 <code>a</code>s in less than 5 seconds without raising any exception |
107 (remember Python and Ruby both need nearly 30 seconds to process 28(!) <code>a</code>s, and Scala's |
107 (remember Python and Ruby both need nearly 30 seconds to process 28(!) <code>a</code>s, and Scala's |
108 official matcher maxes out at 4,600 <code>a</code>s). My matcher is approximately |
108 official matcher maxes out at 4,600 <code>a</code>s). My matcher is approximately |
109 85 lines of code and based on the concept of |
109 85 lines of code and based on the concept of |
181 I recently implemented a very simple compiler for an even simpler functional |
181 I recently implemented a very simple compiler for an even simpler functional |
182 programming language following this |
182 programming language following this |
183 <A HREF="https://www.cs.princeton.edu/~dpw/papers/tal-toplas.pdf">paper</A> |
183 <A HREF="https://www.cs.princeton.edu/~dpw/papers/tal-toplas.pdf">paper</A> |
184 (also described <A HREF="https://www.cs.princeton.edu/~dpw/papers/tal-tr.pdf">here</A>). |
184 (also described <A HREF="https://www.cs.princeton.edu/~dpw/papers/tal-tr.pdf">here</A>). |
185 My code, written in <A HREF="http://www.scala-lang.org/">Scala</A>, of this compiler is |
185 My code, written in <A HREF="http://www.scala-lang.org/">Scala</A>, of this compiler is |
186 <A HREF="http://www.dcs.kcl.ac.uk/staff/urbanc/compiler.scala">here</A>. |
186 <A HREF="https://nms.kcl.ac.uk/christian.urban/compiler.scala">here</A>. |
187 The compiler can deal with simple programs involving natural numbers, such |
187 The compiler can deal with simple programs involving natural numbers, such |
188 as Fibonacci numbers or factorial (but it can be easily extended - that is not the point). |
188 as Fibonacci numbers or factorial (but it can be easily extended - that is not the point). |
189 </p> |
189 </p> |
190 |
190 |
191 <p> |
191 <p> |