ANN: LOLPython 1.0

Andrew Dalke andrewdalke at gmail.com
Mon Jun 4 19:21:20 CEST 2007


Following along with the current lolcat fad, and taking inspiration
from lolcode,
I've implemented LOLPython.  For details and downloads see

  http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html

Here's an example implementation of a Fibonacci number generator

SO IM LIKE FIBBING WIT N OK?
    LOL ITERATE FIBONACCI TERMS LESS THAN N /LOL
    SO GOOD N BIG LIKE EASTERBUNNY
    BTW, FIBONACCI LIKE BUNNIES! LOL
    U BORROW CHEEZBURGER
    U BORROW CHEEZBURGER
    I CAN HAZ CHEEZBURGER
    HE CAN HAZ CHEEZBURGER
    WHILE I CUTE?
        I AND HE CAN HAZ HE AND I ALONG WITH HE
        IZ HE BIG LIKE N?
            KTHXBYE
        U BORROW HE

The lolpython.py runtime converts LOLPython to Python.

def FIBBING ( N ) :
    'ITERATE FIBONACCI TERMS LESS THAN N'
    assert N >= 0
    # BTW, FIBONACCI LIKE BUNNIES! LOL
    yield 1
    yield 1
    I = 1
    HE = 1
    while 1:
        I , HE = HE , I + HE
        if HE >= N :
            break
        yield HE

and by default exec's the translated code.

You might also be interested looking at the code because I
use PLY for tokenization and translate the token stream into
Python code which is then exec'ed.  The neatest part was
making the exec'ed code act like it was in __main__ using

  module_name = "__main__"
  python_s = to_python(lolpython_s)
  m = types.ModuleType(module_name)
  sys.modules[module_name] = m
  exec python_s in m.__dict__

which is a trick others might use when implementing
interesting import hooks.

LOLPython, at
  http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html

Please note that LOLPython does not implement the lolcode standard
language.  While I was influenced by some of the language I wanted
something which was semantically equivalent to Python, including
support for classes, exceptions and the yield statement.

For an implementation of lolcode in Python (and also using PLY)
see sjlol at:
  http://lolcode.com/implementations/sjlol

and a full list of implementations at
  http://lolcode.com/implementations/implementations
including IDE support in Visual Studio.

                                Andrew Dalke
                                dalke at dalkescientific.com



More information about the Python-announce-list mailing list