nunojob:~ dscape/08$ echo The Black Sheep

Archive for May, 2008

Wouldn’t ANTLR be better if written in a dynamic language?

I think making a tool like ANTLR is a non-dynamic language is a shot in the foot!

It just makes sense to use dynamic languages to create meta-language tools. Would facilitate the work of the developer and of the ones writing grammars taking away all that java trash that helps in nothing to make out stuff work. ANTLR is great, but all the negative aspects (from end-user point of view) arise from the fact of having all that unnecessary information and needing to declare types and other stuff that ARE NOT NATURAL for a grammar to have. And the way it’s implemented in Java is just a way of copying the way (bad) dynamic languages work.

grammar Expr; 

options {
  output = AST;
  ASTLabelType = CommonTree;
} 

prog
     : ( stat
         { System.out.println( $stat.tree.toStringTree() ); }
       )+
     ;

stat
     : expr NEWLINE -> expr
     | ID '=' expr NEWLINE -> ^('=' ID expr)
     | NEWLINE ->
     ; 

expr
     : multExpr ( ( '+'^ | '-'^ ) multExpr )*
     ;

multExpr
     : atom ( '*'^ atom )*
     ;

atom
     : INT
     | ID
     | '('! expr ')'!
; 

ID
     : ( 'a'..'z' | 'A'..'Z' )+
     ;

INT
     : '0'..'9'+
     ; 

NEWLINE
     : '\r'? '\n'
     ; 

WS
     : ( ' ' | '\t' | '\n' | '\r' )+
       { $channel=HIDDEN; }
     ;
grammar Expr; 

options {
  output = AST;
} 

prog
     : ( stat
         { puts $stat.to_tree }
       )+
     ;

stat
     : expr NEWLINE
     | ID '=' expr NEWLINE -> ^ // mark the root somehow
     | NEWLINE
     ; 

expr
     : multExpr ( ( '+'^ | '-'^ ) multExpr )*
     ;

multExpr
     : atom ( '*'^ atom )*
     ;

atom
     : INT
     | ID
     | '('! expr ')'!
; 

ID
     : ( 'a'..'z' | 'A'..'Z' )+
     ;

INT
     : '0'..'9'+
     ; 

NEWLINE
     : '\r'? '\n'
     ; 

WS
     : ( ' ' | '\t' | '\n' | '\r' )+
       { skip }
     ;

Just wish I had the time to implement it in Ruby and prove my point! Maybe in the masters thesis..

By the way, the ANTLR Book is great. If you want to learn about grammars and creating DSL’s you will love it. But be advised, you’ll hate the java trash that comes with it.

By the way Google changed their icon.

But once again, who gives a fuck? I sure don’t.

Advertisements

Information Retrieval using the Boolean Model in Ruby on Rails

Simple Twist of Fate

Letra da música

Campanha humanitária do Post-crossing

Não consigo ficar indiferente as pessoas que nunca se resignam ao mundo em que vivemos. Os mentores do projecto post-crossing, antigos meus colegas de curso, decidiram “aceitar doações que serão enviadas à cruz vermelha chinesa, em benefício das vítimas do terramoto na província de sichuan”.

Como se isto não basta-se, aos “primeiros 100 doadores (que doarem mais de 10 euros) será enviado um conjunto de postais da fotógrafa chinesa phoebe jin”. Por isso estão à espera de que?

Mais informações aqui.

famfamfam flag iconset yaml representation on ruby

First download the flags from famfamfam into a folder called flags (pngs only,
no subfolders!).

Now in the bash:

cd flags
wget http://www.iso.org/iso/iso3166_en_code_lists.txt
ls > file.txt
irb

Now your on the interactive ruby shell (irb).

# If you want to use this as a script just copy
# the bash lines and put them as
# system ‘cd flags’
# system ‘wget …’ and so on

# We start treating the output from the ls
# open the ls output
f = File.new ‘file.txt’
# place the file in lines
lines = f.readlines
# map those who have 2 digits codes
lines = lines.select { |line| line.size == 7 }
# get the 2 digits
lines = lines.map { |line| line[0..1] }
f.close

# Then the iso file
# open the iso file
f = File.new ‘iso3166_en_code_lists.txt’
# get rid of the notes
f.readline
# place the file in iso
iso = f.readlines
# create a new hash
hashed_iso = {}
# select non empty lines
iso.select { |a| !a.rstrip.empty? }.map do |b|
# remove the whitespaces and split in ‘;’
aux = b.rstrip.split ‘;’
# place info in the hash
hashed_iso[aux[1].downcase] = aux[0].capitalize
end
f.close

# Now we cross information giving more
# importance to what’s in the iso.
iso_famfamfam = hashed_iso.select {
# select those who have flags in famfamfam
|k,v| lines.member? k
}.sort_by {
# sort them by the name the user will see
|pair| pair[1]
}

# Now we create the contents to store in the yaml file
# create the yaml first line
yaml_lines = “hash: \n”
iso_famfamfam.each do |pair|
# for each pair, create the yaml
# representation and put in yaml_lines
yaml_lines < < ' ' + pair[0] + ': ' + pair[1] + "\n" end yaml_lines << "array: ---\n" iso_famfamfam.each do |pair| yaml_lines << '- - ' + pair[0] + "\n - " + pair[1] + "\n" end # put it in a file f = File.new 'flags.yml', 'w' f.write yaml_lines f.close #sample for loading the yaml into ruby f = File.new 'flags.yml' fy = YAML.load f [/sourcecode] Now you have your yaml representation of the flags. Do what you please. Personally I'm going to use the file to load it to Ruby when my Ruby on Rails app starts and use it as part of the registration system in the

Windows Live Mess

Não estão todos incrédulos que esteja a postar sobre isto!? Eu estou. Acabei de ler este artigo genial. Para ler, rir, reler e rir outra vez.

Fica uma pequena citação e o artigo original:

How on earth does Microsoft continue to pour massive resources into building the same frigging synchronization platforms again and again? Damn, they just finished building something called Windows Live FolderShare and I haven’t exactly noticed a stampede to that. I’ll bet you’ve never even heard of it. The 3,398th web site that lets you upload and download files to a place on the Internet. I’m so excited I might just die.

Mas não se fica por aqui. Mais aqui:

Java 6 for Mac OS X Leopard is here!!

In the most impressive development of the week I have just discovered that Java 6 was finally released for Mac OS X. I’m in complete disbelief.

Now I almost believe that IBM DB2 Express-C for mac will be released in less that a month. :P

More on this here.