Coder Social home page Coder Social logo

pythoncompilerworkbench's Introduction

Python Compiler Workbench

screenshot

This is a live coding environment to help you develop intuitions about how Python source code compiles to ASTs and bytecodes. As you type in code, it gets compiled to AST and bytecode formats, and the visualization updates instantaneously.

Watch the 1.5-minute YouTube demo.

Installing

  1. Download GraphViz and install it.
  2. Install two Python packages: bottle and pydot.

One way to install is:

easy_install pip
pip install bottle
pip install pydot

Running

  1. Run python backend.py to start the server.
  2. Visit http://localhost:8080/index.html

(tested with Python 2.7 on Mac OS X so far)

Why did I create this project?

Because it was the fastest and most effective way for me to learn about Python ASTs.

The official docs aren't that helpful for gaining intuitions about what real ASTs look like. They are more of a reference guide, not a tutorial. So I figured that the best tutorial would be to create an environment where I could easily enter in any piece of Python code and see what it compiled into.

For instance, I wanted to see what a chain of if-elif-else blocks looked like in the AST, so I just typed in a simple example:

if-else-screenshot

Low and behold, it compiles into a series of nested if-else blocks!

On a meta level, the process of building this tool itself -- especially writing the code to transform ASTs into the GraphViz format for visualization -- gave me even better intuitions for how AST nodes are structured.

So all in all, it's been a very efficient and fun way for me to learn :) And if this project helps you learn as well, then even better!

pythoncompilerworkbench's People

Contributors

pgbovine avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.