2009-10-17から1日間の記事一覧

Schemeのブロックコメントにマッチする正規表現(2)

開き括弧と閉じ括弧から,正規表現を生成. def charsetq(c) case c when "[", "-", "]", "\\" "\\#{c}" else c end end def _rec_regexp(str) Array.new(str.length) {|i| [Regexp.quote(str[0, i]), charsetq(str[i, 1])] } end def rec_regexp(s1, s2) a1…

Schemeのブロックコメントにマッチする正規表現

自信はない. re = /(?<block>#\|(?:(?:[^#|]|#[^|]|\|[^#])++|\g<block>)*+\|#)/ str = <</block></block>

ruby1.9のrequire_relative

ところで,require_relativeっていいよね.1.9から入ったのかな. なんかhttp://svn.ruby-lang.org/repos/ruby/trunk/NEWSに書いてあるけど,1.9.1の途中から入ったのかな?

parser generator書いてみた(5)

実行速度測ってみた. CPUは,2 GHz Intel Core 2 Duo. $ ruby19 -v ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0] $ time ./sample/calc2.rb 19985 real 0m1.085s user 0m1.066s sys 0m0.014srequire_relative '../rdpg.rb' Lexer = Par…