Skip to main content.
Febrero 6th, 2008  español 

My own compiler written in Python

Computer Science Programming

During these last months I’ve been developing, just for fun and in my *very* little spare time, my own compiler kit tool.
More than a compiler, it’s a tool for building up compilers (there are others over there, like Lex & Yacc, Flex & Bison in its GNU flavour). Mine is called Bparser.

I’ve put it in my wiki, just in case anybody want to give it a glance.

My tool is better than the LEX & YACC couple in the sense it can parse LR(n) grammars whilst LEX/Yacc only parses LALR ones. It uses a Lookahead and mangle-likes estructures to take some decisions when choosing which grammar rule to use for reduction.

If it eventually cannot decide which rule should be used, it will start to backtrack to find out the rule to apply.

This tool allows ambiguos grammars, so it is very similar to a GLR parser. BISON (GNU’s YACC) can also use the GLR algorithm, but it is less efficient and can take exponential space/time to parse some entries depending on the given grammar.

Read the rest of this entry »

Posted by Boriel as Compilers, Computer Science, Programming at 12.05 pm

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
No Ratings Yet
4 Comments »
Septiembre 22nd, 2007  español 

libgmail throught HTTP(S) proxy

Computer Science Programming

libgmail is, in words of its author, a pure python binding to provide access to your gmail account.

I’m using it and find it very useful. However, within my organization, I must connect to the internet via an HTTP/HTTPS proxy firewall. Direct internet connections are filtered, so I developed a hack to make it to work via an HTTP(S) proxied connection.

Basically I ripped the code from this ASPN snippet, and derived the urllib proxied transport to create a new one.

To use it behind a proxy, you can copy the libgmail example, and define the proxy this way:

import libgmail

libgmail.PROXY_URL = 'www.myproxy.org:3128'  # Define the proxy.

ga = libgmail.GmailAccount("google@gmail.com", "mymailismypass")
ga.login()
folder = ga.getMessagesByFolder('inbox')

for thread in folder:
    print thread.id, len(thread), thread.subject
    for msg in thread:
        print "  ", msg.id, msg.number, msg.subject
    print msg.source

I patched the libgmail.py file and write the proxied transport in another one: gmail_transport.py. You will need to copy both the file gmail_transport.py and the modified version of libgmail.py (overwrite it) into the same directory libgmail.py is installed.

There is also a diff file available, for libgmail-0.6.1.2.

Update (2007-10-06): It’s now possible to use proxy authentication. To do it so, you must use the proxy host address on the previous example this way: user:password@myproxy.org:3128 where user and password are your proxy user and password respectively. You’ll have to download again the file gmail_transport.py.

Now, the example to use it behind a proxy requiring with user/passwd authentication is like this:

import libgmail

# Connect from behind a proxy www.myproxy.org:3128 using
# proxy authentication user = 'john', password = 'proxy4321'
libgmail.PROXY_URL = 'john:proxy4321@www.myproxy.org:3128'  # Define the proxy 

ga = libgmail.GmailAccount("google@gmail.com", "mymailismypass")
ga.login()
folder = ga.getMessagesByFolder('inbox')

for thread in folder:
    print thread.id, len(thread), thread.subject
    for msg in thread:
        print "  ", msg.id, msg.number, msg.subject
    print msg.source

Posted by Boriel as Computer Science, Programming at 7.57 pm

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
2 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 5 (2 votes, average: 5 out of 5)
9 Comments »
Julio 16th, 2007  español 

General term of a serie

Mathematics Programming

Carlos Rodríguez, a friend of mine, mathematician and teacher, has given me a script (in javascript) which calculates the general term of a serie, using interpolation by finite differences.

I’ve hacked it a bit, to allow it to plot the result using a javascript canvas function plotter I found at Menno’s Blog. This way you can check the result. Menno’s told me his code is based upon the a script from Jeka911.

Since Microsoft Internet Explorer does not support :( canvas natively, I used the moocanvas Javascript library, which emulates it very well. This project is related to MooFx and MooTools (which I use in this blog for little javascript effects).

Keep reading to see a very interesting interactive graphic plot…

Read the rest of this entry »

Posted by Boriel as Mathematics, Programming at 8.49 am

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
No Ratings Yet
5 Comments »
Enero 21st, 2007  español 

Calling Perl functions from Python

Computer Science Programming

I’m currently working on a project and need to call old Perl functions from Python (until the perl code is refactorized and translated to python).

A friend of mine told me about PyPerl, but we found it’s currently unmaintained. :(

Suppose you have a perl module, named mylib.pl, which have a function like:

sub myfunc
{
my ($a, $b) = @_;
...
...

return result;
}

We wanted to be able to call myfunc function from python, without having to rewrite it.
So I managed to create a python module to wrap perl functions in python, using python decorators. With it, you can call perl functions this way:

import perlfunc

@perlfunc
@perlreq('mylib.pl')
def myfunc(a, b):
    pass

This would call the perl function myfunc (defined in library mylib.pl) using a and b as parameters. Lists (and arrays as list of lists) and dictionaries can be passed as parameters (they are conveniently converted to perl).

It seems to work very well. :)
It’s licensed GPL, and you can download it from here: perlfunc.py

Posted by Boriel as Computer Science, Programming at 10.44 pm

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
2 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 5 (2 votes, average: 4 out of 5)
5 Comments »
Abril 14th, 2006  español 

CodeHighlight Fix

Wordpress Programming

For those using the fantastic CodeHighlight plugin, I’ve fixed it up to work with Wordpress 2.x and PHP listings.

To install the fix, just install the plugin as usual and then overwrite the file CodeHighlight.php with this one (download file).

Update: Forgot to mention this version inserts the CSS (Style Sheet) needed to format the code. You needn’t to modify your theme CSS.

Posted by Boriel as Wordpress, Programming at 10.41 pm

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
2 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 52 Votes | Average: 5 out of 5 (2 votes, average: 5 out of 5)
1 Comment »
« Previous entries