2008-03-01から1ヶ月間の記事一覧

PDF::Writer:PDF::SimpleTable::Column::Heading.new

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.columns["col1"] = PDF::SimpleTable::Column.new("COL1") {|col| col.headin…

Java FAQ:オブジェクトを文字列化

Java FAQ:S007 Q-06 public class C2008032100 { public static void main(String[] args) { System.out.println(new Integer(1).toString()); System.out.println(new Double(1.2).toString()); System.out.println(new Object().toString()); } } で、 1 …

lex を試す。lex.lex(optimize=1)

#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'PLUS', ) t_A = r'a' t_PLUS = r'\+' def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex(optimize=1) lex.input("a+a") while 1: tok = lex.token() if …

PDF::Writer:PDF::SimpleTable::Column#justification, #justification=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center tab.columns = { "col1" => P…

Java FAQ:int をn進数の文字列に

Java FAQ:S007 Q-04 public class C2008032000 { public static void main(String[] args) { int i = 10; String s; s = Integer.toBinaryString(i); System.out.println(s); s = Integer.toOctalString(i); System.out.println(s); s = Integer.toString(i…

lex を試す。__doc__ を直接書き換え

#!/usr/bin/env python import ply.lex as lex digit = r'([0-9])' nondigit = r'([_A-Za-z])' identifier = r'(' + nondigit + r'(' + digit + r'|' + nondigit + r')*)' reserved = { 'if' : 'IF', 'then' : 'THEN', 'else' : 'ELSE', 'while' : 'WHILE', …

PDF::Writer:PDF::SimpleTable::Column#link_name, #link_name=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center tab.columns["col1"] = PDF::…

Java FAQ:double を int に変換

Java FAQ:S007 Q-03まんま public class C2008031900 { public static void main(String[] args) { double d = 2.5; int i = (int)d; System.out.println(d); System.out.println(i); } } で、 2.5 2

lex を試す。@TOKEN decorator

python 2.4 (以上)でないとダメ #!/usr/bin/env python import ply.lex as lex from ply.lex import TOKEN digit = r'([0-9])' nondigit = r'([_A-Za-z])' identifier = r'(' + nondigit + r'(' + digit + r'|' + nondigit + r')*)' reserved = { 'if' : 'IF…

PDF::Writer:PDF::SimpleTable::Column#width, #width=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center tab.columns["col1"] = PDF::…

Java FAQ:String を double に変換

Java FAQ:S007 Q-02 public class C2008031800 { public static void main(String[] args) { double d; String s = "1.2"; d = Double.parseDouble(s); System.out.println(d); Double d_o = Double.valueOf(s); d = d_o.doubleValue(); System.out.println…

lex を試す。エラー処理

「t.lexer.skip(1)」は一文字(トークン?)捨てるという意味のようだ lexer でエラーなんてあって良いのか分からないのだけど。

PDF::Writer:PDF::SimpleTable::Column#name

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center tab.columns["col1"] = PDF::…

Java FAQ:数値を String に変換

Java FAQ:S007 Q-01 public class C2008031700 { public static void main(String[] args) { String s; boolean b = true; s = String.valueOf(b); System.out.println(s); char c = 'a'; s = String.valueOf(c); System.out.println(s); byte B = 1; s = S…

lex を試す。literals

#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', ) literals = [ '+','-','*','/' ] t_A = r'a' def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() lex.input("a+a") while 1: tok = lex.token() if no…

PDF::Writer:PDF::SimpleTable::Column#heading, #heading=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center tab.columns["col1"] = PDF::…

Java FAQ:サイズ0の配列

Java FAQ:S006-Q18 public class C2008031600 { public static void main(String[] args) { int[] ary = new int[0]; System.out.println(ary.length); } } で、 0

lex を試す。column の計算

特別には用意されていないから、lexpos から計算しろとのこと。 まあ、たしかにエラー表示でも行番号だけで、column は使わないか

PDF::Writer:PDF::SimpleTable#columns, #columns=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.columns tab.show_lines = :all tab.show_headings = true tab.orientation = :center tab.position = :center p tab.columns…

Java FAQ:配列を返す関数の型の書き方

Java FAQ:S006-Q13 public class C2008031500 { static int [] foo() { int[] ary = {1, 2, 3}; return ary; } public static void main(String[] args) { System.out.println(foo()[0]); } } でも public class C2008031501 { static int foo()[] { int[] …

lex を試す。行情報の更新

#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'PLUS', ) t_A = r'a' t_PLUS = r'\+' def t_newline(t): r'\n+' t.lexer.lineno += len(t.value) #t.lexer.lexpos = 0 def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer…

PDF::Writer:PDF::SimpleTable#column_order, #column_order=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| p tab.column_order tab.column_order = %w(col1 col2 col3) p tab.column_order data = [ { "col1" => "foo", "col2" => "bar", "col3" => "baz" }, ] tab.data.replace da…

Java FAQ:配列宣言の書き方

Java FAQ:S006-Q13 public class C2008031400 { public static void main(String[] args) { int[] ary1 = new int[10]; int ary2[] = new int[10]; String[] ary3 = new String[10]; String ary4[] = new String[10]; System.out.println(ary1[0]); System.…

lex を試す。トークンを捨てる

「t_ignore_」という名前を使うと、自動的に捨てるらしい #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'PLUS', ) t_A = r'a' t_PLUS = r'\+' t_ignore_COMMENT = r'\#.*' def t_error(t): print "Illegal character '%s'" % t.value[0] t.…

PDF::Writer:PDF::SimpleTable#data, #data=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order.push(*%w(col1 col2 col3)) data = [ { "col1" => "foo", "col2" => "bar", "col3" => "baz" }, ] #tab.data.replace data p tab.data tab.data = data p …

Java FAQ:new と初期化は無関係

Java FAQ:S006-Q11 public class C2008031300 { public static void main(String[] args) { String[] ary = new String[10]; System.out.println(ary[0]); } } で、 null

lex を試す。トークンを捨てる

マニュアルでは #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'PLUS', 'COMMENT', ) t_A = r'a' t_PLUS = r'\+' def t_COMMENT(t): r'\#.*' pass def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() …

PDF::Writer:PDF::SimpleTable 最小限の記述

なくても良さそうなコードを削ってみて require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order.push(*%w(from1 to1 from2 to2)) data = [ { "from1" => "1 point", "to1" => "0.3528 mm", "from2" => "1 point",…

Java FAQ:配列の大きさ指定

Java FAQ、『Java の質問箱』 とはちょっと離れて そういえば、配列サイズの指定が実行時に決まる変数でも良いという項目がないようだ。 5.10 に配列のサイズは変更できないから Vector を使えというのはあるけど。 #include <stdio.h> void foo(int size) { int ary[</stdio.h>…

lex を試す。tokens を自動列挙?

わざわざ tokens に指定するのがバカくさいので。 #!/usr/bin/env python import re import ply.lex as lex _dir_org = dir() ### User Definition ### t_A = r'a' t_PLUS = r'\+' def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.ski…