| ▲ | A Python Interpreter Written in Python(aosabook.org) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 points by xk3 4 days ago | 12 comments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | blueybingo 5 minutes ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
the article glosses over something worth pausing on: the `getattr` trick for dispatching instructions (replacing the big if-elif chain) is actaully a really elegant pattern that shows up in a lot of real interpreters and command dispatchers, not just toy ones -- worth studying that bit specifically if you're building anything with extensible command sets. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | anitil 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
Oooh it's a bytecode interpreter! I was wondering how they'd fit a parser/tokenizer in 500 lines unless the first was `import tokenizer, parser`. And it looks like 1500ish lines according to tokei I think because python is a stack-based interpreter this is a really great way to get some exposure to how it works if you're not too familiar with C. A nice project! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | tekknolagi 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
See also https://github.com/nedbat/byterun and https://github.com/rocky/x-python | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | woadwarrior01 an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
aka A Metacircular Interpreter | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | hcfman 2 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
Just wondering why you stopped there? Why not a python interpreter for a python interpreter for python ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||