[pypy-dev] Project suggestions

Michael Sparks Michaels at rd.bbc.co.uk
Tue Sep 27 12:41:48 CEST 2005


On Friday 23 Sep 2005 13:02, Boria Feigin wrote:
...
> I am an undergraduate student (at a top-5 CS university in the UK)
> looking for a fun final-year project to sink my teeth into.

As I understand pypy it can theoretically take a number of alternate front
ends as well as back ends. I don't know how much work has gone into that,
but a whimsical idea that sprang to mind just now as an alternate project idea 
(that I'm not convinced should ever be done >:-) is this:

Last summer, for fun, I wrote a generic language parser that can handle
almost anything you throw at it. The basic underlying idea was "what if in
lisp you removed all the brackets and used a python-like syntax instead".
(Or depending on the time of day "What if we removed all the keywords
from python, could we still parse something that looked close to python>")

The idea was that you would use :<newline><indent> stuff </dedent> where you 
would use nested brackets. I did leave in a small amount of infix support 
though, and did think about things like: 

I only worked on a parsing/AST building, but it might be an "interesting"
alternate front end. Unlike python I found that in order to support
control flows like if...elif...elif..else, and try...except...finally, and
similar that you needed an end tag (could be anything though) in
order to simplify the parser. (Hints to the lexer would have been an
alternate approach, but would've required 2 passes in the way I was
thinking)

In case that doesn't make any sense,

if result is None:
    print "Parse failed"
else:
    print "Success"
end

is a function call to an "if" function that among it's arguments takes 2
anonymous code blocks with an "else" tag inbetween and followed by
an "end" tag.

Similarly:

pen down
repeat 4:
   forward 10
   rotate 90
end

is two function calls - one to pen, and one to repeat. Repeat takes 3 
arguments here - 4, the code block and the "end" tag.

Anyway, the code is here: cerenity.org/SWP/ - that also includes a pdf of the 
lightning talk I gave at ACCU (though not the slightly nicer version I gave 
at europython I notice... Hmm... ) Slide 8 shows how nuts this can get with 
mixing of an L-System description language with an SML-esque syntax for a 
structural stack, with a logo type language, and started off with a 
python-esque bootstrap. At europython I also had an SQL-like statement in 
there for added silliness. (The point was that the example parsed cleanly, 
not whether it meant anything)

The entire parser was written test first, with the tests being sample
programs - which you can find here:
   * http://cerenity.org/SWP/progs/

The parser itself is quite short, the grammer is LL(1) compliant and consists
of 13 productions. 

Anyway, as an alternate front end this could be a mad (but fun) little 
project. I'm not convinced it would actually be a GOOD idea to do
though :)

Regards,


Michael.
-- 
Michael Sparks, Senior R&D Engineer, Digital Media Group
Michael.Sparks at rd.bbc.co.uk, http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This e-mail may contain personal views which are not the views of the BBC.



More information about the Pypy-dev mailing list