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

PDF::Writer:PDF::SimpleTable#header_gap, #header_gap=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.header_gap tab.header_gap = 200 tab.show_lines = :all data = [] 80.times do |i| data << { "col1" => "#{i}", "col2" =>…

Java FAQ:オーバライドされたスーパークラスのメソッドを呼ぶ

Java FAQ:S011 Q-07 class C2008042001 { void foo() { System.out.println("foo in C2008042001"); } } class C2008042002 extends C2008042001 { C2008042002() { super.foo(); foo(); } void foo() { System.out.println("foo in C2008042002"); } } pub…

自前 Lexer の指定

「yacc.parse(s, lexer = Lexer())」 #!/usr/bin/env python tokens = ( 'A', 'B', 'C', ) class LexToken: def __init__(self, t, value, lineno, lexpos): self.type = t self.value = value self.lineno = lineno self.lexpos = lexpos class Lexer: def …

PDF::Writer:PDF::SimpleTable#split_rows, #split_rows=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.split_rows tab.split_rows = true tab.row_gap = 150 tab.show_lines = :all data = [ { "col1" => "foo", "col2" => "bar",…

Java FAQ:クラスメソッドのオーバライド?

Java FAQ:S011 Q-06まんま class C2008041901 { static int foo() { return 1; } static void bar() { System.out.println("foo() = " + foo()); } } public class C2008041900 extends C2008041901 { static int foo() { return 2; } public static void m…

LALR でなく SLR を使う

「yacc.yacc(method="SLR")」 #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', 'C', ) t_A = r'A' t_B = r'B' t_C = r'C' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() imp…

PDF::Writer:PDF::SimpleTable#protect_rows, #protect_rows=

何?

Java FAQ:コンストラクタ内のインスタンス変数参照でエラー

Java FAQ:S010 Q-10 class C2008041801 { int x; C2008041801(int x) { this.x = x; } } class C2008041802 extends C2008041801 { int y; C2008041802() { super(this.y); } } public class C2008041800 { public static void main(String[] args) { new C…

規則の途中のアクションで shift/reduce conflicts が発生してしまう

まんま #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', 'C', 'D', 'X', ) t_A = r'A' t_B = r'B' t_C = r'C' t_D = r'D' t_X = r'X' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) le…

PDF::Writer:PDF::SimpleTable#minimum_space, #minimum_space=

require 'pdf/simpletable' pdf = PDF::Writer.new def table(pdf) PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.minimum_space tab.minimum_space = 500 tab.row_gap = 50 tab.show_lines = :all data = [ { "col1" => "foo…

Java FAQ:インスタンス変数が初期化されていない例

Java FAQ:S010 Q-09ほぼ、まんま abstract class C2008041701 { C2008041701() { show(); } abstract public void show(); } class C2008041702 extends C2008041701 { String name; C2008041702(String name) { this.name = name; } public void show() { …

規則の途中のアクション

自分で書き下す必要があるようだほぼ、まんま #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', 'C', 'D', ) t_A = r'A' t_B = r'B' t_C = r'C' t_D = r'D' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0…

PDF::Writer:PDF::SimpleTable#row_gap, #row_gap=

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

Java FAQ:インスタンス変数の初期化子とコンストラクタの実行順序

Java FAQ:S010 Q-08ほぼ、まんま class C2008041601 { int a; C2008041601() { this.a = 1; } } class C2008041602 extends C2008041601 { int a = 10; C2008041602() { System.out.println(this.a); } } public class C2008041600 { public static void ma…

p.lineno(num), p.lexpos(num), p.linespan(num), p.lexspan(num)

#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', 'C', ) t_A = r'A' t_B = r'B' t_C = r'C' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc as yacc def p_i…

PDF::Writer:PDF::SimpleTable#maximum_width, #maximum_width=

require 'pdf/simpletable' pdf = PDF::Writer.new def table(pdf, maximum_width) PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.maximum_width tab.maximum_width = maximum_width if maximum_width tab.show_lines = :all …

Java FAQ:インスタンス生成を制限する方法

Java FAQ:S010 Q-04ほぼ、まんま class C2008041501 { private static C2008041501 instance = new C2008041501(); private C2008041501() { } public static C2008041501 getInstance() { return instance; } } public class C2008041500 { public static …

エラーまわり

良く分かっていない #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', ) t_A = r'A' t_B = r'B' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc as yacc def …

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

require 'pdf/simpletable' pdf = PDF::Writer.new def table(pdf, width) PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.width tab.width = width if width tab.show_lines = :all data = [ { "col1" => "foo foo foo foo fo…

Java FAQ:スーパークラスの引数なしコンストラクタがないとコンパイルエラーになる場合

Java FAQ:S010 Q-03話がちょっとややこしい? と、思ったのは、デフォルトコンストラクタを勘違いしていたからのようだ。「クラスの定義にコンストラクタを一つも記述しなかった場合、コンパイラによって自動的に引数なしのコンストラクタが生成されます。…

nonassoc

試したが、失敗…(原因不明) #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', ) t_A = r'A' t_ignore = " \t" literals = ['+', '<'] def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc…

PDF::Writer:PDF::SimpleTable#orientation, #orientation=

require 'pdf/simpletable' pdf = PDF::Writer.new def table(pdf, orientation) PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.orientation tab.orientation = orientation tab.show_lines = :all data = [ { "col1" => "foo…

Java FAQ:サブクラスでは必ずコンストラクタを記述しないとダメ

Java FAQ:S010 Q-02なんでそういう仕様なんだっけ?C++ も同じかな? class C2008041301 { C2008041301() { System.out.println("C2008041301"); } } class C2008041302 extends C2008041301 { C2008041302() { System.out.println("C2008041302"); } } pub…

エラーまわり

#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', ) t_A = r'A' t_B = r'B' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc as yacc def p_input(p): 'input …

PDF::Writer:PDF::SimpleTable#position, #position=

require 'pdf/simpletable' pdf = PDF::Writer.new def table(pdf, position) PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.position tab.position = position tab.show_lines = :all data = [ { "col1" => "foo", "col2" =>…

Java FAQ:デフォルトコンストラクタ

Java FAQ:S010 Q-01 public class C2008041200 { } をコンパイルした後、javap -c を実行 Compiled from C2008041200.java public class C2008041200 extends java.lang.Object { public C2008041200(); } Method C2008041200() 0 aload_0 1 invokespecial …

parser.out

example/calc/calc.py を実行すると、parser.out, parsetab.py というものが生成されるparser.out Unused terminals: Grammar Rule 1 statement -> NAME = expression Rule 2 statement -> expression Rule 3 expression -> expression + expression Rule 4 …

PDF::Writer:PDF::SimpleTable#title_gap, #title_gap=

require 'pdf/simpletable' pdf = PDF::Writer.new PDF::SimpleTable.new do |tab| tab.column_order = %w(col1 col2 col3) p tab.title_gap tab.title_gap = 50 tab.title = "TITLE" tab.show_lines = :all data = [ { "col1" => "foo", "col2" => "bar", "…

Java FAQ:String#intern()

Java FAQ:S008 Q-13 public class C2008041100 { public static void main(String[] args) { String s1 = "abc"; String s2 = new StringBuffer("abc").toString(); System.out.println(s1 == s2); System.out.println(s1.equals(s2)); System.out.println(…

開始記号の指定

start で指定 #!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', ) t_A = r'A' t_B = r'B' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc as yacc start = 'i…