2008-03-01から1ヶ月間の記事一覧
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: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 …
#!/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 …
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: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…
#!/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', …
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: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
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…
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: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…
「t.lexer.skip(1)」は一文字(トークン?)捨てるという意味のようだ lexer でエラーなんてあって良いのか分からないのだけど。
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: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…
#!/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…
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:S006-Q18 public class C2008031600 { public static void main(String[] args) { int[] ary = new int[0]; System.out.println(ary.length); } } で、 0
特別には用意されていないから、lexpos から計算しろとのこと。 まあ、たしかにエラー表示でも行番号だけで、column は使わないか
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: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[] …
#!/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…
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: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.…
「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.…
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:S006-Q11 public class C2008031300 { public static void main(String[] args) { String[] ary = new String[10]; System.out.println(ary[0]); } } で、 null
マニュアルでは #!/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() …
なくても良さそうなコードを削ってみて 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 の質問箱』 とはちょっと離れて そういえば、配列サイズの指定が実行時に決まる変数でも良いという項目がないようだ。 5.10 に配列のサイズは変更できないから Vector を使えというのはあるけど。 #include <stdio.h> void foo(int size) { int ary[</stdio.h>…
わざわざ 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…