Paul Berry (stereotype441) wrote,
Paul Berry

Nerd post: meaningless python

Much of my spare time in the last week has gone to writing a parser for python (I like writing pasrers). I was inspired to work on this by this page about Top-Down Operator Precedence parsing, although I didn't wind up using that technique.

This is my most ambitious (and successful) parser yet. So far, it parses the complete grammar for Python expressions. 400 lines of Python code excluding the lexer.

I'm also using a cool technique to auto-generate the unit tests. The generated unit tests contain some cool Python expressions that are actually syntactically valid (albeit meaningless):

[ x for x in lambda * x : x ]
lambda x , x = x , : x
{ x : lambda : x }
x [ lambda : x : ]
( x for x , x in x )
x ( * x * x )
x [ x : x | x : x ]

I guess it goes to show, with sufficient determination, you can pervert any programming language.
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.